Skip to content

Commit

Permalink
Close [#585] Implement actor.on('kill') event (#597)
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim authored and kamranayub committed May 13, 2016
1 parent 0c1f221 commit 6bb16dc
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 3 deletions.
Binary file modified dist/Excalibur.0.6.0.nupkg
Binary file not shown.
7 changes: 7 additions & 0 deletions dist/Excalibur.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3743,6 +3743,13 @@ declare module ex {
*/
target: any;
}
/**
* The 'kill' event is emitted on actors when it is killed. The target is the actor that was killed.
*/
class KillEvent extends GameEvent {
target: any;
constructor(target: any);
}
/**
* The 'predraw' event is emitted on actors, scenes, and engine before drawing starts. Actors' predraw happens inside their graphics
* transform so that all drawing takes place with the actor as the origin.
Expand Down
13 changes: 13 additions & 0 deletions dist/Excalibur.js
Original file line number Diff line number Diff line change
Expand Up @@ -6378,6 +6378,7 @@ var ex;
*/
Actor.prototype.kill = function () {
if (this.scene) {
this.emit('kill', new ex.KillEvent(this));
this.scene.remove(this);
this._isKilled = true;
}
Expand Down Expand Up @@ -7353,6 +7354,18 @@ var ex;
return GameEvent;
})();
ex.GameEvent = GameEvent;
/**
* The 'kill' event is emitted on actors when it is killed. The target is the actor that was killed.
*/
var KillEvent = (function (_super) {
__extends(KillEvent, _super);
function KillEvent(target) {
_super.call(this);
this.target = target;
}
return KillEvent;
})(GameEvent);
ex.KillEvent = KillEvent;
/**
* The 'predraw' event is emitted on actors, scenes, and engine before drawing starts. Actors' predraw happens inside their graphics
* transform so that all drawing takes place with the actor as the origin.
Expand Down
2 changes: 1 addition & 1 deletion dist/Excalibur.min.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions dist/excalibur-0.6.0.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3743,6 +3743,13 @@ declare module ex {
*/
target: any;
}
/**
* The 'kill' event is emitted on actors when it is killed. The target is the actor that was killed.
*/
class KillEvent extends GameEvent {
target: any;
constructor(target: any);
}
/**
* The 'predraw' event is emitted on actors, scenes, and engine before drawing starts. Actors' predraw happens inside their graphics
* transform so that all drawing takes place with the actor as the origin.
Expand Down
13 changes: 13 additions & 0 deletions dist/excalibur-0.6.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -6378,6 +6378,7 @@ var ex;
*/
Actor.prototype.kill = function () {
if (this.scene) {
this.emit('kill', new ex.KillEvent(this));
this.scene.remove(this);
this._isKilled = true;
}
Expand Down Expand Up @@ -7353,6 +7354,18 @@ var ex;
return GameEvent;
})();
ex.GameEvent = GameEvent;
/**
* The 'kill' event is emitted on actors when it is killed. The target is the actor that was killed.
*/
var KillEvent = (function (_super) {
__extends(KillEvent, _super);
function KillEvent(target) {
_super.call(this);
this.target = target;
}
return KillEvent;
})(GameEvent);
ex.KillEvent = KillEvent;
/**
* The 'predraw' event is emitted on actors, scenes, and engine before drawing starts. Actors' predraw happens inside their graphics
* transform so that all drawing takes place with the actor as the origin.
Expand Down
2 changes: 1 addition & 1 deletion dist/excalibur-0.6.0.min.js

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions sandbox/web/Excalibur.js
Original file line number Diff line number Diff line change
Expand Up @@ -6378,6 +6378,7 @@ var ex;
*/
Actor.prototype.kill = function () {
if (this.scene) {
this.emit('kill', new ex.KillEvent(this));
this.scene.remove(this);
this._isKilled = true;
}
Expand Down Expand Up @@ -7353,6 +7354,18 @@ var ex;
return GameEvent;
})();
ex.GameEvent = GameEvent;
/**
* The 'kill' event is emitted on actors when it is killed. The target is the actor that was killed.
*/
var KillEvent = (function (_super) {
__extends(KillEvent, _super);
function KillEvent(target) {
_super.call(this);
this.target = target;
}
return KillEvent;
})(GameEvent);
ex.KillEvent = KillEvent;
/**
* The 'predraw' event is emitted on actors, scenes, and engine before drawing starts. Actors' predraw happens inside their graphics
* transform so that all drawing takes place with the actor as the origin.
Expand Down
1 change: 1 addition & 0 deletions src/engine/Actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ module ex {
*/
public kill() {
if (this.scene) {
this.emit('kill', new ex.KillEvent(this));
this.scene.remove(this);
this._isKilled = true;
} else {
Expand Down
9 changes: 9 additions & 0 deletions src/engine/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ module ex {
public target: any;
}

/**
* The 'kill' event is emitted on actors when it is killed. The target is the actor that was killed.
*/
export class KillEvent extends GameEvent {
constructor(public target) {
super();
}
}

/**
* The 'predraw' event is emitted on actors, scenes, and engine before drawing starts. Actors' predraw happens inside their graphics
* transform so that all drawing takes place with the actor as the origin.
Expand Down
14 changes: 13 additions & 1 deletion src/spec/ActorSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,4 +939,16 @@ describe('A game actor', () => {
expect(childActor.draw).not.toHaveBeenCalled();
});

});
it('fires a killed event when killed', () => {
var actor = new ex.Actor();
scene.add(actor);
var killed = false;
actor.on('kill', (evt: ex.KillEvent) => {
killed = true;
});
actor.kill();

expect(killed).toBe(true);
});

});

0 comments on commit 6bb16dc

Please sign in to comment.