mirror of
https://github.com/wassname/phaser.git
synced 2026-08-12 12:20:38 +08:00
Sprites that are fixedToCamera can now be input dragged regardless of world position.
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.stage.backgroundColor = '#007236';
|
||||
|
||||
game.load.image('ball', 'assets/sprites/shinyball.png');
|
||||
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
|
||||
game.load.image('phaser', 'assets/sprites/sonic_havok_sanity.png');
|
||||
|
||||
}
|
||||
|
||||
var sprite;
|
||||
var cursors;
|
||||
|
||||
function create() {
|
||||
|
||||
game.world.setBounds(0, 0, 1000, 1000);
|
||||
|
||||
for (var i = 0; i < 100; i++)
|
||||
{
|
||||
game.add.sprite(game.world.randomX, game.world.randomY, 'mushroom');
|
||||
}
|
||||
|
||||
sprite = game.add.sprite(200, 200, 'ball');
|
||||
|
||||
sprite.fixedToCamera = true;
|
||||
// sprite.cameraOffset.setTo(200, 200);
|
||||
|
||||
|
||||
sprite.inputEnabled = true;
|
||||
sprite.input.enableDrag();
|
||||
sprite.events.onInputOver.add(wibble, this);
|
||||
|
||||
cursors = game.input.keyboard.createCursorKeys();
|
||||
|
||||
}
|
||||
|
||||
function wibble() {
|
||||
console.log('over');
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
if (cursors.up.isDown)
|
||||
{
|
||||
game.camera.y -= 4;
|
||||
}
|
||||
else if (cursors.down.isDown)
|
||||
{
|
||||
game.camera.y += 4;
|
||||
}
|
||||
|
||||
if (cursors.left.isDown)
|
||||
{
|
||||
game.camera.x -= 4;
|
||||
}
|
||||
else if (cursors.right.isDown)
|
||||
{
|
||||
game.camera.x += 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderText(sprite.cameraOffset.x, 32, 32);
|
||||
game.debug.renderText(sprite.cameraOffset.y, 32, 64);
|
||||
game.debug.renderPointer(game.input.activePointer);
|
||||
|
||||
}
|
||||
+1
-1
@@ -28,7 +28,7 @@ var module;
|
||||
function create() {
|
||||
|
||||
module = new Protracker();
|
||||
module.buffer = game.cache.getBinary('elysium');
|
||||
module.buffer = game.cache.getBinary('impulse');
|
||||
module.parse();
|
||||
module.play();
|
||||
|
||||
|
||||
@@ -50,13 +50,14 @@ function create() {
|
||||
// map.setCollisionByIndexRange(20, 25);
|
||||
// map.setCollisionByIndexRange(27, 29);
|
||||
|
||||
layer3 = map.createLayer('Tile Layer 3');
|
||||
layer3.scrollFactorX = 0.5;
|
||||
// layer3 = map.createLayer('Tile Layer 3');
|
||||
// layer3.scrollFactorX = 0.5;
|
||||
|
||||
layer2 = map.createLayer('Tile Layer 2');
|
||||
layer2.alpha = 0.5;
|
||||
// layer2 = map.createLayer('Tile Layer 2');
|
||||
// layer2.alpha = 0.5;
|
||||
|
||||
layer = map.createLayer('Tile Layer 1');
|
||||
layer.scrollFactorX = 0.5;
|
||||
|
||||
// layer.debug = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user