Sam Posted November 12, 2014 Share Posted November 12, 2014 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._onLoAny suggestions on it? Maybe I simply missed something.. Link to comment Share on other sites More sharing options...
Julia Posted November 12, 2014 Share Posted November 12, 2014 *Newbie here*Are you loading your spritesheet in the preload function? Like so: this.game.load.spritesheet('lvlObjXSpriteData', 'yoursprite.png', yourframewidth, yourframeheight, yournumberofframes); Link to comment Share on other sites More sharing options...
Sam Posted November 12, 2014 Author Share Posted November 12, 2014 Hi and welcome, yes it is loaded in the preload function Link to comment Share on other sites More sharing options...
Julia Posted November 12, 2014 Share Posted November 12, 2014 Hmm okay. Sorry, I really wouldn't know then Are you sure it's possible to write (game.width - 40 * pixelratio, game.height / 2 + 150 * pixelratio, ...);instead of ((game.width - 40) * pixelratio, (game.height / 2) + (150 * pixelratio), ...)); ? Link to comment Share on other sites More sharing options...
Sam Posted November 12, 2014 Author Share Posted November 12, 2014 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 More sharing options...
Julia Posted November 12, 2014 Share Posted November 12, 2014 The loop of the animation is set to false by default, right? What if you remove that? Link to comment Share on other sites More sharing options...
Sam Posted November 12, 2014 Author Share Posted November 12, 2014 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 More sharing options...
Sam Posted November 12, 2014 Author Share Posted November 12, 2014 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 More sharing options...
Julia Posted November 12, 2014 Share Posted November 12, 2014 Haha wow. Wouldn't guess I would be able to help someone with my noob-ness hahaha Link to comment Share on other sites More sharing options...
Recommended Posts