mirror of
https://github.com/wassname/phaser.git
synced 2026-08-17 11:23:42 +08:00
46 tests with assets and javascript code.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
(function() {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
|
||||
function init() {
|
||||
game.load.spritesheet('rect', 'assets/buttons/number-buttons-90x90.png', 90, 90);
|
||||
game.load.start();
|
||||
}
|
||||
function create() {
|
||||
var rect, factor;
|
||||
for (var i = 0; i < 16; i++) {
|
||||
rect = game.add.sprite(10 + Math.random() * 700, 10 + Math.random() * 300, 'rect', Math.round(Math.random() * 5));
|
||||
factor = 0.2 + Math.random() * 2;
|
||||
rect.transform.scale.setTo(factor, factor);
|
||||
factor = 2 + Math.random() * 6;
|
||||
rect.speed = factor;
|
||||
}
|
||||
console.log(game.world.group.length);
|
||||
}
|
||||
function update() {
|
||||
game.world.group.forEach(function(rect) {
|
||||
// Apply speed to each rect.
|
||||
rect.y += rect.speed;
|
||||
// Move the rect back to screen if it's not.
|
||||
if (!Phaser.SpriteUtils.onScreen(rect)) {
|
||||
rect.y = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,40 @@
|
||||
(function() {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
|
||||
var rotationSrv, angle = 0;
|
||||
|
||||
function init() {
|
||||
game.load.spritesheet('x', 'assets/sprites/x.png', 220, 160);
|
||||
game.load.start();
|
||||
}
|
||||
function create() {
|
||||
// Create 6 sprites rotating around the center at the beginning.
|
||||
for (var i = 0; i < 3; i++) {
|
||||
game.add.sprite(210 - ((i % 2) ? 140 : 0), 120 * (i + 1), 'x', i);
|
||||
game.add.sprite(370 + ((i % 2) ? 140 : 0), 120 * (i + 1), 'x', i + 3);
|
||||
}
|
||||
|
||||
// Set a default rotation server pointer.
|
||||
rotationSrv = new Phaser.Point(game.stage.centerX, game.stage.centerY);
|
||||
|
||||
// Rotate all the sprites around the touch point.
|
||||
game.input.onTap.add(function(pointer) {
|
||||
rotationSrv.x = pointer.position.x;
|
||||
rotationSrv.y = pointer.position.y;
|
||||
});
|
||||
}
|
||||
function update() {
|
||||
angle += 0.1;
|
||||
|
||||
game.world.group.forEach(function(obj) {
|
||||
var resPointer = new Phaser.Point(obj.x, obj.y);
|
||||
Phaser.PointUtils.rotateAroundPoint(resPointer, rotationSrv, angle);
|
||||
obj.x = resPointer.x;
|
||||
obj.y = resPointer.y;
|
||||
});
|
||||
}
|
||||
function render() {
|
||||
Phaser.DebugUtils.context.fillStyle = '#fff';
|
||||
Phaser.DebugUtils.context.fillText('Tap or click to set new rotation point.', 280, 100);
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user