【问题标题】:Craftyjs Sprite Animation issueCraftyjs Sprite 动画问题
【发布时间】:2013-09-03 23:39:03
【问题描述】:

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

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

这是我在加载场景中加载精灵的方式:

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');
  })
})

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

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
  })
  ;

},

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

【问题讨论】:

    标签: javascript animation craftyjs


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      使用非缩小版。

      我使用的是 Crafty v0.5.4 缩小版,精灵动画无法正常工作,控制台日志中没有错误。

      经过几个小时的努力,我尝试了非缩小版本,精灵动画开始正常工作。

      【讨论】:

        猜你喜欢
        • 2014-05-12
        • 1970-01-01
        • 1970-01-01
        • 2013-12-24
        • 1970-01-01
        • 1970-01-01
        • 2016-07-29
        • 1970-01-01
        • 2014-10-03
        相关资源
        最近更新 更多