javascript - Craftyjs Sprite 动画问题

标签 javascript animation craftyjs

我目前正在尝试使用狡猾的 js 制作游戏,但我被 Sprite 动画困住了。 我真的不知道我做错了什么..

这是工作代码: http://aaahdontpaintmeinred.me.pn/

以下是我在加载场景中加载 Sprite 的方法:

Crafty.scene('Loading', function(){
// Draw some text for the player to see in case the file
//  takes a noticeable amount of time to load
Crafty.e('2D, DOM, Text')
.text('Loading...')
.attr({ x: 0, y: Game.height()/2 - 24, w: Game.width() });

  // Load our sprite map image
  Crafty.load(['assets/mansprite.gif'], function(){
  // Once the image is loaded...

// Define the individual sprites in the image
// Each one (spr_tree, etc.) becomes a component
// These components' names are prefixed with "spr_"
//  to remind us that they simply cause the entity
//  to be drawn with a certain sprite
Crafty.sprite(133, 'assets/mansprite.gif', {
  mansprite:[0, 0]
});

  // Now that our sprites are ready to draw, start the game
  Crafty.scene('LevelEditor');
  })
})

这是我尝试在播放器组件中绑定(bind)和动画的方法:

Crafty.c('PlayerCharacter', {
init: function() {

this.requires('Actor, Collision,FPS,mansprite,SpriteAnimation,WiredHitBox')
  .attr({maxValues:1,boost:false,trailSpacing:100,currentFrame:0})
  .collision();

  this.animate('run',0, 0, 3);
  this.animate('idle',3, 0, 1);
  this.requires('FluidControls')
  //this.rotation+=90;
  .onHit("FinishLine",this.endLevel)
  .onHit("DeathWall",this.omagaDie)
  .onHit("Booster",this.booster)
  .bind("EnterFrame",function(fps){

    if(this.move.up)
    {
      this.animate('run', 4,-1);
      var spacing = this.trailSpacing; 
      if( this.currentFrame%((60*spacing)/1000) == 0)
        Crafty.e("montexte").spawn(this.x,this.y,this.boost,this.xspeed,this.yspeed,this.rotation%360,this.h,this.w);
    }else
    {
      if(!this.move.down)
      {
        this.animate('idle', 4,1);
      }
    }
    this.currentFrame++;

    if(this.currentFrame >=60)
      this.currentFrame=0
  })
  ;

},

希望有人能指出哪里出了问题! 如果您需要更多详细信息或有疑问,请不要犹豫! 谢谢

最佳答案

好的,所以我使用0.5.3版本解决了这个问题。

还是不知道怎么回事。但会尝试在这里给出答案。

关于javascript - Craftyjs Sprite 动画问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18546497/

相关文章:

android - Android ViewPager删除带动画的项目

javascript - Crafty.js 显示白屏

javascript - 如何为对话框窗口设置动画?

javascript - 带有返回语句的短路

javascript - 每张图像上都有特定文本的幻灯片

javascript - Kendo ListView - 从嵌套 JSON 中过滤字段

QuickDraw中的python3递归动画

javascript - 如何检查craftyjs实体是否掉出了crafty区域?

javascript - 无法使用 HTML5 Web 存储保存 bool 值的解决方法

javascript - 将数组转换为键值对