phaser/Tests/sprites/scale sprite 5.ts

61 lines
1.6 KiB
TypeScript
Raw Normal View History

2013-05-29 01:58:56 +00:00
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, preload, create);
2013-05-29 01:58:56 +00:00
function preload() {
2013-05-29 01:58:56 +00:00
// Using Phasers asset loader we load up a PNG from the assets folder
game.load.image('fuji', 'assets/pics/atari_fujilogo.png');
2013-05-29 01:58:56 +00:00
}
var fuji: Phaser.Sprite;
var tween: Phaser.Tween;
function create() {
game.stage.backgroundColor = 'rgb(0,0,100)';
// Here we'll assign the new sprite to the local fuji variable
2013-05-29 11:24:25 +00:00
fuji = game.add.sprite(game.stage.centerX, game.stage.centerY, 'fuji');
2013-05-29 01:58:56 +00:00
// sets origin to the center of the sprite (half the width and half the height)
2013-08-02 17:32:26 +00:00
fuji.transform.origin.setTo(0.5, 0.5);
2013-05-29 01:58:56 +00:00
// We'll tween the scale down to zero (which will make the sprite invisible) and then flip it
// The end result should look like turning over a card
// Create our tween
tween = game.add.tween(fuji.transform.scale);
2013-05-29 01:58:56 +00:00
// Start it going
2013-05-29 11:24:25 +00:00
scaleLeft();
2013-05-29 01:58:56 +00:00
}
function scaleLeft() {
tween.clear();
tween.to({ x: 0 }, 1000);
tween.onComplete.add(scaleRight, this);
tween.start();
}
function scaleRight() {
tween.clear();
tween.to({ x: 1 }, 1000);
tween.onComplete.add(scaleLeft, this);
tween.start();
// This line says "if the texture is flippedX then unflip it (set flippedX to false), otherwise set flippedX to true
(fuji.texture.flippedX) ? fuji.texture.flippedX = false: fuji.texture.flippedX = true;
}
})();