9 years ago by denkle
AnalogStick Plugin for Impact. With fix for scaled Canvas
https://gist.github.com/den-kle/55e0539eed9fa2368397463fb51f2c7d
Example:
https://gist.github.com/den-kle/55e0539eed9fa2368397463fb51f2c7d
Example:
// lib/game/main.js
init: function() {
// ...
this.stickLeft = new ig.AnalogStick( 40, ig.system.height-48);
this.stickRight = new ig.AnalogStick( ig.system.width-40, ig.system.height-48);
}
draw: function() {
// ...
this.stickLeft.draw();
this.stickRight.draw();
}
// lib/game/entities/player.js
update: function() {
// ...
// left stick
this.vel.x = ig.game.stickLeft.input.x * this.speed;
this.vel.y = ig.game.stickLeft.input.y * this.speed;
// right stick
if( ig.game.stickRight.amount > 0 ) {
this.angle = ig.game.stickRight.angle - Math.PI/2;
if( this.lastShootTimer.delta() > 0 ) {
this.shoot();
this.lastShootTimer.set(0.05);
}
}
}
