首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Craftyjs Sprite动画问题

Craftyjs Sprite动画问题
EN

Stack Overflow用户
提问于 2013-08-31 17:16:18
回答 2查看 722关注 0票数 1

我目前正在尝试用巧妙的js制作一个游戏,但我被精灵动画卡住了。我真的不知道我做错了什么。

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

下面是我如何在我的加载场景中加载sprite:

代码语言:javascript
复制
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');
  })
})

下面是我如何在我的播放器组件中绑定和动画:

代码语言:javascript
复制
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
  })
  ;

},

希望有人能指出哪里出了问题!如果你需要更多细节或者你有问题,不要固执己见!谢谢

EN

回答 2

Stack Overflow用户

发布于 2013-09-03 16:24:21

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

还是不知道发生了什么。但我会试着在这里给出答案。

票数 0
EN

Stack Overflow用户

发布于 2013-11-05 05:05:20

使用非最小化版本。

我使用的是Crafty v0.5.4,并且精灵动画不工作,控制台日志中没有错误。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18546497

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档