phaser/examples/sprites/dynamic crop.js
2013-10-22 03:58:20 +01:00

29 lines
536 B
JavaScript

var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
function preload() {
game.load.image('trsi', 'assets/pics/trsipic1_lazur.jpg');
}
var r;
var pic;
function create() {
pic = game.add.sprite(0, 0, 'trsi');
r = new Phaser.Rectangle(0, 0, 200, 200);
}
function update() {
r.x = game.input.x;
r.y = game.input.y;
pic.x = game.input.x;
pic.y = game.input.y;
// Apply the new crop Rectangle to the sprite
pic.crop = r;
}