phaser/examples/sprites/dynamic crop.js

43 lines
750 B
JavaScript
Raw Normal View History

2013-10-22 02:58:20 +00:00
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
2013-10-22 02:58:20 +00:00
function preload() {
game.load.image('trsi', 'assets/pics/trsipic1_lazur.jpg');
}
var pic;
2014-02-28 18:40:06 +00:00
var cropRect;
2013-10-22 02:58:20 +00:00
function create() {
pic = game.add.sprite(0, 0, 'trsi');
2014-02-28 18:40:06 +00:00
cropRect = {x : 0, y : 0 , width : 128, height : 128};
}
2014-02-28 18:40:06 +00:00
function update() {
2014-02-28 18:40:06 +00:00
if(game.input.x < pic.width && game.input.y < pic.height){
2013-10-22 02:58:20 +00:00
2014-02-28 18:40:06 +00:00
pic.x = game.input.x;
pic.y = game.input.y;
2013-10-22 02:58:20 +00:00
2014-02-28 18:40:06 +00:00
cropRect.x = game.input.x;
cropRect.y = game.input.y;
pic.crop(cropRect);
2013-10-22 02:58:20 +00:00
2014-02-28 18:40:06 +00:00
}
2013-10-22 02:58:20 +00:00
2014-02-28 18:40:06 +00:00
}
function render() {
game.debug.text('x: ' + game.input.x + ' y: ' + game.input.y, 32, 32);
2013-10-22 02:58:20 +00:00
}