1 decade ago by LazerFriends
This one is a little tough to explain. I have a switch entity that sits on the ground and triggers a door to open. When another entity touches it ( the player or a crate) the switch triggers, and the switch animation changes to look like it was pressed in.
The problem is, when placing a crate on it and then picking it up, the switch stays pressed in even though the crate isn't on it anymore. Its only when you set the crate down, no matter how far away, does the switch pop back up again.
Important note: when a crate is picked up, both the player and the crate entity are killed and a new entity (the player holding the crate) is spawned. When putting the crate down, that entity is killed and separate player and crate entities are spawned.
Here is the link: (press X to pick up a crate) http://bsmallbeck.com/impact/
And here is the switch code:
The problem is, when placing a crate on it and then picking it up, the switch stays pressed in even though the crate isn't on it anymore. Its only when you set the crate down, no matter how far away, does the switch pop back up again.
Important note: when a crate is picked up, both the player and the crate entity are killed and a new entity (the player holding the crate) is spawned. When putting the crate down, that entity is killed and separate player and crate entities are spawned.
Here is the link: (press X to pick up a crate) http://bsmallbeck.com/impact/
And here is the switch code:
ig.module( 'game.entities.switch' ) .requires( 'impact.entity' ) .defines(function(){ EntitySwitch = ig.Entity.extend({ size: {x:28, y:10}, offset: {x: 0, y: 18}, animSheet: new ig.AnimationSheet( 'media/switch.png', 28, 36), zIndex:0, type: ig.Entity.TYPE.NONE, checkAgainst: ig.Entity.TYPE.NONE, collides: ig.Entity.COLLIDES.PASSIVE, init: function( x, y, settings){ this.parent(x,y,settings); this.addAnim( 'inactive', 1, [0]); this.addAnim('active', 1, [1]); }, update: function(){ if(this.touches(ig.game.player) || this.touches(ig.game.box)){ this.currentAnim = this.anims.active; } else { this.currentAnim = this.anims.inactive; } } }); });