Why does my sprite not animate?

137 views
Skip to first unread message

cbm...@gmail.com

unread,
Oct 21, 2013, 9:13:31 PM10/21/13
to mel...@googlegroups.com
I'm new to MelonJS and I must say it's been pretty awesome so far but for the life of me, I can't figure out why my sprite isn't animating frames.


When I control the main character, it only shows the first frame of each animation set.  In other words, for "run_left" I have 6 frames but it only shows frame 6.  Same for the other directions.

What am I doing wrong?

Thanks.

rene matias riveros salinas

unread,
Oct 21, 2013, 9:30:54 PM10/21/13
to mel...@googlegroups.com, cbm...@gmail.com
Hi,
Well, what I can see is that you are updating your frames only if the x velocity or the y velocity is different than 0. I see to that you have a animation cycle even if your player is not moving(animation with name 'still'), so if you gonna have animation frames running all the time I think is not necessary the piece of code:

// Update animation
if (this.vel.x != 0 || this.vel.y != 0) {
this.parent();
return true;
}
 
// Otherwise, tell the engine nothing to update
return false;

just replace it for :
// Update animation
this.parent(this);
return true;

is good for game performance not update if is not necessary, but if you will animating your player all time is necessary do it, either I imagine that your player is called samus aran for the metroid games and the still animation is when samus is stand breathing. Cheers!.

cbm...@gmail.com

unread,
Oct 21, 2013, 9:44:24 PM10/21/13
to mel...@googlegroups.com, cbm...@gmail.com
Thanks.  But that still doesn't work.

I have updated the gist as follows:


Thanks for any help.

rene matias riveros salinas

unread,
Oct 21, 2013, 9:54:17 PM10/21/13
to mel...@googlegroups.com, cbm...@gmail.com
you forget the 'this' inside this.parent, should be like this way:

// Update Samus' movement
this.updateMovement();
 
this.parent(this); // <----
return true;
instead of :

// Update Samus' movement
this.updateMovement();
 
this.parent();
return true;


Aaron McLeod

unread,
Oct 21, 2013, 9:55:53 PM10/21/13
to mel...@googlegroups.com
You're calling setCurrentAnimation every frame when the player holds down the left action. You'll want to this instead:

if(!this.isCurrentAnimation('run_left')) { this.setCurrentAnimation('run_left'); }


--
You received this message because you are subscribed to the Google Groups "melonJS - A lightweight HTML5 game engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to melonjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Aaron McLeod
http://agmprojects.com

Aaron McLeod

unread,
Oct 21, 2013, 9:57:51 PM10/21/13
to mel...@googlegroups.com
Sorry, just to add, when you call the setCurrentAnimation, it basically starts you at frame zero (or the first fame you specified), so that's why you're not seeing anything. And unless i am mistaken, there is no reason to pass (this) to the parent update call. It doesnt use parameters: https://github.com/melonjs/melonJS/blob/0.9.9/src/entity/entity.js#L1160

cbm...@gmail.com

unread,
Oct 21, 2013, 10:01:04 PM10/21/13
to mel...@googlegroups.com, cbm...@gmail.com
Thanks to both of you!!!  Both were the issue.  Works great now!

Is there not a better tutorial (or more advanced than the step-by-step) out there?  Not that I'm complaining.  I'm amazed at how much I've done in so little time!


Thanks again.


On Monday, October 21, 2013 9:13:31 PM UTC-4, cbm...@gmail.com wrote:

rene matias riveros salinas

unread,
Oct 21, 2013, 10:07:06 PM10/21/13
to mel...@googlegroups.com
pufff sorry for the mistake, I was taken a look at the old code platformer example my drop box x.x.

Aaron McLeod

unread,
Oct 21, 2013, 11:01:34 PM10/21/13
to mel...@googlegroups.com
Might not be updated, but can always check out the source code of games, provided its not minified: http://melonjs.org/gallery.html.

I have some projects up on github you're welcome to look at as well. 


I know jay has some good examples as well. https://bitbucket.org/parasyte/neverwell-moor here's a top down rpg he built. I have to admit, I dont follow how he did any of the collision stuff with tiled. Drew objects to make invisible walls, much more complex compared to whats in the tutorial.

Jay Oster

unread,
Oct 22, 2013, 1:22:24 AM10/22/13
to mel...@googlegroups.com, cbm...@gmail.com
I just want to comment that `this` is not necessary to pass as an argument to the me.ObjectEntity.update() superclass, because it takes no arguments: http://melonjs.github.io/docs/me.Renderable.html#update ... So, it was right the first time. ;)
Reply all
Reply to author
Forward
0 new messages