Craftyjs Sprite Animation issue

741 Views Asked by At

I'm currently trying to make a game with crafty js and I'm stuck with the sprite Animation. I don't really know what I'm doing wrong ..

Here is the working code : http://aaahdontpaintmeinred.me.pn/

Here is how I load the sprite in my loading scene :

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

And here is how I try to bind and Animate in my player component :

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

},

Hope someone could point out what is going wrong ! If you need more details or you have questions, don't hesistate ! Thanks

2

There are 2 best solutions below

0
On

Ok, so I solved the problem by using the 0.5.3 version.

Still don't know what's going on. But will try to give an answer here.

0
On

Use the non minified version.

I was using Crafty v0.5.4 minified and sprite animation was not working, no errors in console log.

Then after several hours of struggling I tried with the non minified version and the sprite animation started to work properly.