1 decade ago
by Kxen
Hi,
I want to make so that the player only can shoot when it's not overlapping a certain entity and I just can't figure out how to do it. The other way around is easy (by just putting the action in the check function) so hopefully there is an easy solution to this as well.
Any idea?
Thanks.
1 decade ago
by dominic
Since all checks are executed after
update()
, you can
reset a flag at the end of your update function. It will be overwritten by
check()
if the player is overlapping this certain other entity:
EntityPlayer = ig.Entity.extend({
canShoot: true,
update: function() {
this.parent();
if( this.canShoot && ig.input.pressed('shoot') ) {
// shoot!
}
this.canShoot = true;
},
check: function( other ) {
if( other instanceof EntityCertainOtherType ) {
this.canShoot = false;
}
}
});
This works for any number of entities. If you just have
one other entity to check for overlapping, it's even simpler:
EntityPlayer = ig.Entity.extend({
update: function() {
this.parent();
var certainOtherEntity = ig.game.getEntityByName('foo');
if(
!this.touches(certainOtherEntity) &&
ig.input.pressed('shoot')
) {
// shoot!
}
}
});
1 decade ago
by Kxen
Thanks! Works perfectly. :) Great support as always.
Page 1 of 1
« first
« previous
next ›
last »