如何在到达帧末尾时将其位置重置回原点
How to reset its position back to the origin when it reach the end of frame?
这是移相器示例之一,我试图做的是在图像到达帧末尾时再次加载图像。有人可以解释如何做到这一点吗
var game = new Phaser.Game(1500, 200, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });
function preload() {
// You can fill the preloader with as many assets as your game requires
// Here we are loading an image. The first parameter is the unique
// string by which we'll identify the image later in our code.
// The second parameter is the URL of the image (relative)
game.load.image('Car', 'car.jpg');
}
function create() {
// This creates a simple sprite that is using our loaded image and
// displays it on-screen
// and assign it to a variable
var image = game.add.sprite(0, 0, 'Car');
game.physics.enable(image, Phaser.Physics.ARCADE);
image.body.velocity.x=750;
if (image>game.width)
{
game.load.image('Car', 'car.jpg');
var image = game.add.sprite(0, 0, 'Car');
}
}
我认为上面只是伪代码,因为有很多小错误。但是这种方法存在许多问题。
如果您事先知道新图像需要什么,请预先预加载它,然后使用 loadTexture 应用它:
function preload() {
game.load.image('Car', 'car.jpg');
game.load.image('Pumpkin', 'pumpkin.png');
}
...
function update() {
if (car.x > game.width) {
car.loadTexture('Pumpkin');
}
}
还有一些其他需要注意的事情:
1)仅在尚未设置纹理时才更改纹理(在上面的例子中,它将一遍又一遍地运行loadTexture,除非您重置car.x坐标)
2)如果您无法预先预加载图像,则可以在播放过程中加载它。有关详细信息,请查看"加载程序事件"示例代码。
3)你需要检查update
而不是create
的精灵位置(因为到那时它根本不会移动)。
相关文章:
- jquery试图按名称获取按钮位置
- 我可以获得相对于被点击元素的确切点击位置吗
- 谷歌地图固定位置覆盖
- 在单击任何位置时隐藏元素,而不检查每次DOM单击
- 循环比赛位置算法
- es6 相当于下划线查找位置
- jQuery循环在特定位置暂停
- 引导程序:在导航栏中,显示悬停在单个位置的基于Li Link的不同内容
- 自定义函数中的光标位置
- 安卓平台上的QWebView HTML5地理位置
- DIV并排,位置不正确
- 使用jQuery更改元素的顶部位置
- 在谷歌地图上绘制位置数据库
- 如何在 html Web 应用中检测滑动原点位置
- 三.js - 如何获取相机相对于原点的位置
- 如何在到达帧末尾时将其位置重置回原点
- 在 SVG 动画中围绕舞台原点以外的其他位置旋转路径
- 用原点、角度和半径找到一个点的位置
- 为什么我的代码在布朗运动下旋转针图像移动针的位置?为什么原点的图像是分散的?
- 量角器测试-如何将鼠标位置重置为默认原点