1 decade ago by theSociableme
I have a body entity and a head entity. When you touch the body I want the head to react. i.e. to shoot - same as the key press.
What is the best way to do this?
main.js
farmerBody.js
farmerHead.js
How do I change this around to make touching the body spit/shoot?
Any help is appreciated.
What is the best way to do this?
main.js
ig.input.bind( ig.KEY.C, 'shoot' );
ig.input.bind(ig.KEY.MOUSE1, 'CanvasTouch');
farmerBody.js
update: function() {
if (ig.input.pressed('CanvasTouch') && this.inFocus()) {
// What Do I put here to
// trigger the head to shoot which
// is the same as pressing c on the keyboard
}
},
inFocus: function() {
return (
(this.pos.x <= (ig.input.mouse.x + ig.game.screen.x)) &&
((ig.input.mouse.x + ig.game.screen.x) <= this.pos.x + this.size.x) &&
(this.pos.y <= (ig.input.mouse.y + ig.game.screen.y)) &&
((ig.input.mouse.y + ig.game.screen.y) <= this.pos.y + this.size.y)
);
}
farmerHead.js
update: function() {
if(this.currentAnim == this.anims.spit){
if(this.spitTimer > 20){
this.currentAnim = this.anims.idle;
this.spitTimer = -1;
this.spiting = false;
}
this.spitTimer += 1;
}
if(ig.input.state('CanvasTouch')){
this.headRotation = ig.input.mouse.y - 310;
this.body.SetXForm(this.body.GetPosition(), this.headRotation/500);
}
if( ig.input.pressed('shoot') && (this.seedsAvailable > 0) && (this.spiting == false)) {
var x = this.pos.x + 12;
var y = this.pos.y + 4;
this.currentAnim = this.anims.spit;
var seed = ig.game.spawnEntity( EntitySeed, x, y, {flip:this.flip} );
seed.body.ApplyImpulse( new b2.Vec2(20 ,this.headRotation), this.body.GetPosition() );
this.seedsAvailable -= 1;
this.spiting = true;
}
this.parent();
},
How do I change this around to make touching the body spit/shoot?
Any help is appreciated.
