Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

docs(types.ts): add readd() examples #838

Merged
merged 4 commits into from
Apr 5, 2024
Merged
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
35 changes: 35 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,41 @@ export interface KaboomCtx {
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.
*
* // Create two sprites.
* const greenBean = add([
* sprite("bean"),
* pos(200,140),
* color(255, 255, 255),
* area(),
* ])
*
* // This bean will overlap the green bean.
* const purpleBean = add([
* sprite("bean"),
* pos(230,140),
* color(255, 0, 255),
* area(),
* ])
*
* // 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)
* })
* ```
*/
readd(obj: GameObj): void,
/**
Expand Down