Skip to content

Commit

Permalink
Fix #586 actors are no longer killed when added back to the game (#602)
Browse files Browse the repository at this point in the history
* Fix #586 actors are no longer killed when added back to the game

* Implement suggestions
  • Loading branch information
eonarheim committed May 26, 2016
1 parent d3022da commit a6aa4b2
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 11 deletions.
Binary file modified dist/Excalibur.0.6.0.nupkg
Binary file not shown.
4 changes: 4 additions & 0 deletions dist/Excalibur.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3206,6 +3206,10 @@ declare module ex {
* it from the scene graph. It will no longer be drawn or updated.
*/
kill(): void;
/**
* If the current actor is killed, it will now not be killed.
*/
unkill(): void;
/**
* Indicates wether the actor has been killed.
*/
Expand Down
11 changes: 10 additions & 1 deletion dist/Excalibur.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! excalibur - v0.6.0 - 2016-05-16
/*! excalibur - v0.6.0 - 2016-05-25
* https://github.com/excaliburjs/Excalibur
* Copyright (c) 2016 Excalibur.js <https://github.com/excaliburjs/Excalibur/graphs/contributors>; Licensed BSD-2-Clause*/
if (typeof window === 'undefined') {
Expand Down Expand Up @@ -5650,6 +5650,9 @@ var ex;
return this.children.indexOf(actor) > -1;
};
Scene.prototype.add = function (entity) {
if (entity instanceof ex.Actor) {
entity.unkill();
}
if (entity instanceof ex.UIActor) {
if (!ex.Util.contains(this.uiActors, entity)) {
this.addUIActor(entity);
Expand Down Expand Up @@ -6386,6 +6389,12 @@ var ex;
this.logger.warn('Cannot kill actor, it was never added to the Scene');
}
};
/**
* If the current actor is killed, it will now not be killed.
*/
Actor.prototype.unkill = function () {
this._isKilled = false;
};
/**
* Indicates wether the actor has been killed.
*/
Expand Down
8 changes: 4 additions & 4 deletions dist/Excalibur.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions dist/excalibur-0.6.0.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3206,6 +3206,10 @@ declare module ex {
* it from the scene graph. It will no longer be drawn or updated.
*/
kill(): void;
/**
* If the current actor is killed, it will now not be killed.
*/
unkill(): void;
/**
* Indicates wether the actor has been killed.
*/
Expand Down
11 changes: 10 additions & 1 deletion dist/excalibur-0.6.0.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! excalibur - v0.6.0 - 2016-05-16
/*! excalibur - v0.6.0 - 2016-05-25
* https://github.com/excaliburjs/Excalibur
* Copyright (c) 2016 Excalibur.js <https://github.com/excaliburjs/Excalibur/graphs/contributors>; Licensed BSD-2-Clause*/
if (typeof window === 'undefined') {
Expand Down Expand Up @@ -5650,6 +5650,9 @@ var ex;
return this.children.indexOf(actor) > -1;
};
Scene.prototype.add = function (entity) {
if (entity instanceof ex.Actor) {
entity.unkill();
}
if (entity instanceof ex.UIActor) {
if (!ex.Util.contains(this.uiActors, entity)) {
this.addUIActor(entity);
Expand Down Expand Up @@ -6386,6 +6389,12 @@ var ex;
this.logger.warn('Cannot kill actor, it was never added to the Scene');
}
};
/**
* If the current actor is killed, it will now not be killed.
*/
Actor.prototype.unkill = function () {
this._isKilled = false;
};
/**
* Indicates wether the actor has been killed.
*/
Expand Down
8 changes: 4 additions & 4 deletions dist/excalibur-0.6.0.min.js

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion sandbox/web/Excalibur.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! excalibur - v0.6.0 - 2016-05-16
/*! excalibur - v0.6.0 - 2016-05-25
* https://github.com/excaliburjs/Excalibur
* Copyright (c) 2016 Excalibur.js <https://github.com/excaliburjs/Excalibur/graphs/contributors>; Licensed BSD-2-Clause*/
if (typeof window === 'undefined') {
Expand Down Expand Up @@ -5650,6 +5650,9 @@ var ex;
return this.children.indexOf(actor) > -1;
};
Scene.prototype.add = function (entity) {
if (entity instanceof ex.Actor) {
entity.unkill();
}
if (entity instanceof ex.UIActor) {
if (!ex.Util.contains(this.uiActors, entity)) {
this.addUIActor(entity);
Expand Down Expand Up @@ -6386,6 +6389,12 @@ var ex;
this.logger.warn('Cannot kill actor, it was never added to the Scene');
}
};
/**
* If the current actor is killed, it will now not be killed.
*/
Actor.prototype.unkill = function () {
this._isKilled = false;
};
/**
* Indicates wether the actor has been killed.
*/
Expand Down
8 changes: 8 additions & 0 deletions src/engine/Actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,14 @@ module ex {
this.logger.warn('Cannot kill actor, it was never added to the Scene');
}
}

/**
* If the current actor is killed, it will now not be killed.
*/
public unkill() {
this._isKilled = false;
}

/**
* Indicates wether the actor has been killed.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/engine/Scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ module ex {
*/
public add(uiActor: UIActor): void;
public add(entity: any): void {
if(entity instanceof Actor) {
(<Actor>entity).unkill();
}
if (entity instanceof UIActor) {
if (!Util.contains(this.uiActors, entity)) {
this.addUIActor(entity);
Expand Down
11 changes: 11 additions & 0 deletions src/spec/ActorSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -951,4 +951,15 @@ describe('A game actor', () => {
expect(killed).toBe(true);
});

it('is no longer killed when re-added to the game', () => {
var actor = new ex.Actor();
scene.add(actor);
expect(actor.isKilled()).toBeFalsy();
actor.kill();
scene.update(engine, 100);
expect(actor.isKilled()).toBeTruthy();
scene.add(actor);
expect(actor.isKilled()).toBeFalsy();
});

});

0 comments on commit a6aa4b2

Please sign in to comment.