简体   繁体   English

Phaser 游戏 - 获取精灵的最后一帧

[英]Phaser game - get last frame of a sprite

I don't want to play animation,I want to chage sprite's frames by clicking right and left buttons.我不想播放动画,我想通过单击左右按钮来改变精灵的帧。

var sprite = game.add.sprite(200, 100, 'mySprite');
sprite.frame = 3;

Now, if a right button is pressed I want this sprite goes to next frame现在,如果按下右键,我希望这个精灵转到下一帧

sprite.frame += 1;

If left button is pressed, sprites goes to the previous frame.如果按下左键,精灵会转到上一帧。

sprite.frame -= 1;

If left is pressed and current frame is 0 the sprite does not change it's frame, it stops on frame 0. I want the sprite goes from 0 to the last frame when I click left button.如果按下左键且当前帧为 0,精灵不会改变它的帧,它会停在第 0 帧。我希望当我单击左键时精灵从 0 到最后一帧。

For example, in Actionscript 3, I can do this:例如,在 Actionscript 3 中,我可以这样做:

sprite.gotoAndStop(sprite.totalFrames); sprite.gotoAndStop(sprite.totalFrames);

Is there "totalFrames" in Phaser/JS? Phaser/JS 中有“totalFrames”吗?

I did not find any answer, I have created a custom variable 'totalFrames' for all objects.我没有找到任何答案,我为所有对象创建了一个自定义变量“totalFrames”。 The first frame is 0, then 1 and so on...第一帧是 0,然后是 1,依此类推...

if (rightClick)
{
   objects.frame += 1;
}
else if (leftClick)
{
   if (objects.frame > 0)
   {
      objects.frame -= 1;
   }
   else
   {
      objects.frame = objects.totalFrames;
   }
}

A bit late, buy you could try Phaser.GameObjects.Sprite.anims.getTotalFrames()有点晚了,你可以试试 Phaser.GameObjects.Sprite.anims.getTotalFrames()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM