Jump to content

Phaser animation play -> "x of undefined"


Sam
 Share

Recommended Posts

my game.js code produced an error on animations.play - It can not find the x position of "undefined"
I don't know why because the Sprite which should be animated is created before.

 

~ Using Phaser 2.2

 

State where lvlObjX is created:

this.lvlObjX = game.add.sprite( game.width - 40 * pixelratio, game.height / 2 + 150 * pixelratio, 'lvlObjXSpriteData');this.lvlObjX.angle = 90;this.lvlObjX.anchor.setTo(1,0);this.game.physics.enable(this.lvlObjX, Phaser.Physics.ARCADE);this.lvlObjX.body.immovable = true;
State where the animation is added and played:
this.lvlObjX.animations.add( 'extend', [7,8,9] );this.lvlObjX.animations.play( 'extend', 8, false ); (error: game.js: 666, this line )
 
Result: Error :
Uncaught TypeError: Cannot read property 'x' of undefined phaser.js:36264b.Sprite.setFrame phaser.js:36264b.Animation.play phaser.js:50866b.AnimationManager.play phaser.js:50351(anonymous function) game.js:666b.SignalBinding.execute phaser.js:19112b.Signal.dispatch phaser.js:18978 dispatch phaser.js:18684b.Animation.complete phaser.js:51250b.Animation.update phaser.js:51070b.AnimationManager.update phaser.js:50415b.Sprite.preUpdate phaser.js:36113b.Group.preUpdate phaser.js:21324b.Group.preUpdate phaser.js:21324b.Stage.preUpdate phaser.js:19926b.Game.updateLogic phaser.js:25696b.Game.update phaser.js:25649b.RequestAnimationFrame.updateRAF phaser.js:44894window.requestAnimationFrame.forceSetTimeOut._onLo

Any suggestions on it? Maybe I simply missed something..

 

 

Link to comment
Share on other sites

yeah that's no problem. it first gets the multiplication - as of maths rules.
The Sprite is also rendered and fully functional (collision detection etc.)

I definitively can output the x and y values of the "lvlObjX". So this is done right.


only the animation themes to cause that error which I do not know how it is produced.

Link to comment
Share on other sites

I set it to false, cause it should not loop, it should only be one time.
But before the animation is started the error occurs. I do not think that there is something wrong with the loop.

even this isn't the first time that I use it this way, it has worked before in the same code. but not on this code (as posted above)

Link to comment
Share on other sites

I've got it.
Julia, you were right by mentioning:

 

 

Are you loading your spritesheet in the preload function?  :) Like so: 

this.game.load.spritesheet('lvlObjXSpriteData', 'yoursprite.png', yourframewidth, yourframeheight, yournumberofframes);


I simply forgot to raise the amount of frames > yournumberofframes, because I updated the graphic. Now the animation works - Noob failure on my side ;)

solved.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...