Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion example-project/Giga/Giga.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ export default class Giga extends Sprite {

this.triggers = [
new Trigger(Trigger.CLICKED, this.whenthisspriteclicked),
new Trigger(Trigger.GREEN_FLAG, this.whenGreenFlagClicked)
new Trigger(Trigger.GREEN_FLAG, this.whenGreenFlagClicked),
new Trigger(
Trigger.BACKDROP_CHANGED,
{ backdrop: "giga" },
this.whenBackdropChanged
)
];

this.visible = false;
Expand All @@ -24,4 +29,8 @@ export default class Giga extends Sprite {
*whenGreenFlagClicked() {
this.costume = "giga-a";
}

*whenBackdropChanged() {
yield* this.sayAndWait("It's me!", 2);
}
}
11 changes: 10 additions & 1 deletion example-project/Gobo/Gobo.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ export default class Gobo extends Sprite {

this.triggers = [
new Trigger(Trigger.CLICKED, this.whenthisspriteclicked),
new Trigger(Trigger.GREEN_FLAG, this.whenGreenFlagClicked)
new Trigger(Trigger.GREEN_FLAG, this.whenGreenFlagClicked),
new Trigger(
Trigger.BACKDROP_CHANGED,
{ backdrop: "gobo" },
this.whenBackdropChanged
)
];

this.visible = false;
Expand All @@ -25,4 +30,8 @@ export default class Gobo extends Sprite {
*whenGreenFlagClicked() {
this.costume = "goboA";
}

*whenBackdropChanged() {
yield* this.sayAndWait("It's me!", 2);
}
}
7 changes: 7 additions & 0 deletions src/Sprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class SpriteBase {

set costumeNumber(number) {
this._costumeNumber = ((number - 1) % this.costumes.length) + 1;
if (this.fireBackdropChanged) this.fireBackdropChanged();
}

set costume(costume) {
Expand Down Expand Up @@ -646,4 +647,10 @@ export class Stage extends SpriteBase {
// For obsolete counter blocks.
this.__counter = 0;
}

fireBackdropChanged() {
return this._project.fireTrigger(Trigger.BACKDROP_CHANGED, {
backdrop: this.costume.name
});
}
}
4 changes: 4 additions & 0 deletions src/Trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const BROADCAST = Symbol("BROADCAST");
const CLICKED = Symbol("CLICKED");
const CLONE_START = Symbol("CLONE_START");
const TIMER_GREATER_THAN = Symbol("TIMER_GREATER_THAN");
const BACKDROP_CHANGED = Symbol("BACKDROP_CHANGED");

export default class Trigger {
constructor(trigger, options, script) {
Expand Down Expand Up @@ -85,4 +86,7 @@ export default class Trigger {
static get TIMER_GREATER_THAN() {
return TIMER_GREATER_THAN;
}
static get BACKDROP_CHANGED() {
return BACKDROP_CHANGED;
}
}