需要使用phaser.js帮助精灵从屏幕右侧进入

Need help getting sprites to come in from right hand side of the screen using phaser.js

本文关键字:屏幕 精灵 帮助 phaser js      更新时间:2023-09-26

我现在正在学习游戏的相位器框架:http://phaser.io

这个例子展示了多个精灵从屏幕左侧进入。我只是想弄清楚如何让它们从右边进来。我错过了一些东西。

工作示例可以在这里看到:http://examples.phaser.io/_site/view_full.html?d=sprites&f=add+several+sprites.js&t=add%20several%20sprites

代码:

var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload:preload, create: create, update: update });
var timer = 0;
var total = 0;
function preload() {
//  37x45 is the size of each frame
//  There are 18 frames in the PNG - you can leave this value blank if the frames     fill up the entire PNG, but in this case there are some
//  blank frames at the end, so we tell the loader how many to load
game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);
}
function create() {
releaseMummy();
}
function releaseMummy() {
var mummy = game.add.sprite(-(Math.random() * 800), game.world.randomY, 'mummy');
mummy.scale.setTo(2, 2);
//  If you prefer to work in degrees rather than radians then you can use Phaser.Sprite.angle
//  otherwise use Phaser.Sprite.rotation
mummy.angle = game.rnd.angle();
mummy.animations.add('walk');
mummy.animations.play('walk', 20, true);
game.add.tween(mummy).to({ x: game.width + (1600 + mummy.x) }, 20000, Phaser.Easing.Linear.None, true);
total++;
timer = game.time.now + 100;
}
function update() {
if (total < 200 && game.time.now > timer)
{
    releaseMummy();
}
} 

你可以将精灵的位置设置在游戏边界后的最右边。

var mummy = game.add.sprite(800 + (Math.random() * 800), game.world.randomY, 'mummy');

和补间在游戏边界的左边。

game.add.tween(mummy).to({ x: -(1600 + mummy.x) }, 20000, Phaser.Easing.Linear.None, true);

小提琴演示