phaser/wip/phaser tests/sprites/animation 1.js
2013-09-13 16:24:01 +01:00

32 lines
1.3 KiB
JavaScript

/// <reference path="../../Phaser/Game.ts" />
(function () {
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
function init() {
myGame.loader.addSpriteSheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);
//myGame.loader.addSpriteSheet('coin', 'assets/sprites/coin.png', 32, 32);
myGame.loader.addSpriteSheet('monster', 'assets/sprites/metalslug_monster39x40.png', 39, 40);
myGame.loader.load();
}
var car;
function create() {
car = myGame.add.sprite(200, 300, 'monster');
car.animations.add('spin', null, 30, true);
//car.animations.play('spin', 30, true);
car.animations.play('spin');
}
function update() {
car.renderDebugInfo(16, 16);
car.velocity.x = 0;
car.velocity.y = 0;
car.angularVelocity = 0;
car.angularAcceleration = 0;
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
car.angularVelocity = -200;
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
car.angularVelocity = 200;
}
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
car.velocity.copyFrom(myGame.motion.velocityFromAngle(car.angle, 200));
}
}
})();