Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove docs of removed components, simplify readd() example #849

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 14 additions & 36 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,51 +92,30 @@ export interface KaboomCtx {
* const label = make([
* text("oh hi"),
* ])

* add([
* rect(label.width, label.height),
* color(0, 0, 255),
* children(label),
* ])
*
* add(label);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part is to have an example text with background which is made possible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean? You want to change the example to be something like

const label = make([
    text("hi")
])

const background = add([
    rect(50, 50)
])

background.add(label)

Copy link
Contributor Author

@lajbel lajbel Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any update @slmjkdbtl ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah something like

const label = make([
    text("hi")
])

const background = add([
    rect(label.width, label.height)
])

background.add(label)

which might be a more practical example

* ```
*/
make<T>(comps?: CompList<T>): GameObj<T>,
/**
* Remove and re-add the game obj, without triggering add / destroy events.
* @example
* ```js
* // Common way to use this is to have one sprite overlap another sprite, and use readd() to have the bottom sprite on top of the other.
* // Useful to make an object on top of another object
*
* // Create two sprites.
* const greenBean = add([
* sprite("bean"),
* pos(200,140),
* color(255, 255, 255),
* area(),
* const bean = add([
* sprite("bean"),
* pos(20, 40),
* ])
*
* // This bean will overlap the green bean.
* const purpleBean = add([
* sprite("bean"),
* pos(230,140),
* color(255, 0, 255),
* area(),
* // Mark will overlap bean
* const mark = add([
* sprite("mark"),
* pos(20, 40),
* ])
*
* // Example 1: simply call readd() on the target you want on top.
* readd(greenBean)
*
* // Example 2: using onClick() or other functions with readd().
* // If you comment out the first example, and use this readd() with a function like onClick(), you
* can keep switching which sprite is above the other ( click on edge of face ).
*
* purpleBean.onClick(() => {
* readd(greenBean)
* })
*
* greenBean.onClick(() => {
* readd(purpleBean)
* })
* // Now bean overlap mark
* readd(bean)
* ```
*/
readd(obj: GameObj): void,
Expand Down Expand Up @@ -219,9 +198,9 @@ export interface KaboomCtx {
* sprite("bean"),
* scale(3, 1),
* ])
*
* // scale with vec2(x,y).
* bean.scale = vec2(2,4)
*
* ```
*/
scale(): ScaleComp,
Expand Down Expand Up @@ -2060,8 +2039,7 @@ export interface KaboomCtx {
* tiles: {
* "=": () => [
* sprite("floor"),
* area(),
* solid(),
* area({ isStatic: true }),
* ],
* "$": () => [
* sprite("coin"),
Expand Down
Loading