mirror of
https://github.com/wassname/phaser.git
synced 2026-07-10 00:30:50 +08:00
Input Handler working. Dragging, sliding, click detection, multi-touch. Appears to be an issue with bringToTop but it's most likely a problem with the swapChild function rather than Input.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>phaser.js - a new beginning</title>
|
||||
<?php
|
||||
require('js.php');
|
||||
?>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
(function () {
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('atari1', 'assets/sprites/atari130xe.png');
|
||||
game.load.image('atari2', 'assets/sprites/atari800xl.png');
|
||||
game.load.image('atari4', 'assets/sprites/atari800.png');
|
||||
game.load.image('sonic', 'assets/sprites/sonic_havok_sanity.png');
|
||||
game.load.image('duck', 'assets/sprites/darkwing_crazy.png');
|
||||
game.load.image('firstaid', 'assets/sprites/firstaid.png');
|
||||
game.load.image('diamond', 'assets/sprites/diamond.png');
|
||||
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
|
||||
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
// This returns an array of all the image keys in the cache
|
||||
var images = game.cache.getImageKeys()
|
||||
|
||||
// Now let's create some random sprites and enable them all for drag and 'bring to top'
|
||||
for (var i = 0; i < 20; i++)
|
||||
{
|
||||
var tempSprite = game.add.sprite(game.world.randomX, game.world.randomY, game.rnd.pick(images));
|
||||
tempSprite.inputEnabled = true;
|
||||
// tempSprite.input.start(i, false, true);
|
||||
tempSprite.input.enableDrag(false, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
game.debug.renderInputInfo(32, 32);
|
||||
}
|
||||
|
||||
})();
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -91,6 +91,17 @@ Phaser.World.prototype = {
|
||||
|
||||
},
|
||||
|
||||
bringToTop: function (child) {
|
||||
|
||||
if (child !== this._stage.last)
|
||||
{
|
||||
this.swapChildren(child, this._stage.last);
|
||||
}
|
||||
|
||||
return child;
|
||||
|
||||
},
|
||||
|
||||
swapChildren: function (child1, child2) {
|
||||
|
||||
if (child1 === child2 || !child1.parent || !child2.parent)
|
||||
|
||||
@@ -319,6 +319,19 @@ Phaser.Sprite.prototype.getLocalUnmodifiedPosition = function(p, x, y) {
|
||||
|
||||
}
|
||||
|
||||
Phaser.Sprite.prototype.bringToTop = function() {
|
||||
|
||||
if (this.group)
|
||||
{
|
||||
this.group.bringToTop(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.game.world.bringToTop(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Phaser.Sprite.prototype.getBounds = function(rect) {
|
||||
|
||||
rect = rect || new Phaser.Rectangle;
|
||||
|
||||
@@ -672,7 +672,7 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
if (this.dragFromCenter)
|
||||
{
|
||||
this.sprite.transform.centerOn(pointer.worldX, pointer.worldY);
|
||||
// this.sprite.transform.centerOn(pointer.worldX, pointer.worldY);
|
||||
this._dragPoint.setTo(this.sprite.x - pointer.x, this.sprite.y - pointer.y);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user