Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

10 years 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:


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;
	}
    }
        
    });
});

10 years ago by LazerFriends

OK I figured it out. I put the update to the animation inside the check() function instead of update() because the switch is a trigger.

    check: function( other ) {
        
	// Iterate over all targets
        for( var t in this.target ) {
            var ent = ig.game.getEntityByName( this.target[t] );
            // Check if we got a "door" entity with the given name
            if( ent && ent instanceof EntityDoor ) {
		ent.currentAnim = ent.anims.opening;
		ent.collides = ig.Entity.COLLIDES.NONE
		this.currentAnim = this.anims.active;
            } 
        }
	
    }

10 years ago by LazerFriends

Also, I put the idle (inactive) state in the update() function:


update: function(){
	
	this.currentAnim = this.anims.inactive;

},

Page 1 of 1
« first « previous next › last »