Jump to content

Uncaught TypeError: Cannot read property 'x' of undefined


KinoftheFlames
 Share

Recommended Posts

I realized I had an older version of Phaser so I updated to v2.4.4 and started seeing this issue:

Uncaught TypeError: Cannot read property 'x' of undefinedPhaser.Physics.Arcade.Body.preUpdate @ phaser.js:82607Phaser.Component.PhysicsBody.preUpdate @ phaser.js:45311Phaser.Graphics.preUpdate @ phaser.js:52569Phaser.Component.Core.preUpdate @ phaser.js:43691Phaser.Sprite.preUpdate @ phaser.js:46816Phaser.Group.preUpdate @ phaser.js:32470Phaser.Stage.preUpdate @ phaser.js:30840Phaser.Game.updateLogic @ phaser.js:34677Phaser.Game.update @ phaser.js:34619Phaser.RequestAnimationFrame.updateRAF @ phaser.js:58258_onLoop @ phaser.js:58242

originating from this section of code in preUpload for the physics body:

// 82607 phaser.js v2.4.4this.position.x = (this.sprite.world.x - (this.sprite.anchor.x * this.width)) + this.offset.x;this.position.y = (this.sprite.world.y - (this.sprite.anchor.y * this.height)) + this.offset.y;

This is related to me adding a graphics body as a child to a physics body of a sprite:

gfxBall = game.add.graphics(0, 0);gfxBall.beginFill(0xFFFFFF, 1);gfxBall.drawRect(0, 0, infoBall.size, infoBall.size);...var newBall = game.add.sprite(game.world.width/2 - infoBall.size/2, game.world.height/2 - infoBall.size/2);newBall.addChild(gfxBall);game.physics.arcade.enable(newBall);newBall.body.width = infoBall.size;newBall.body.height = infoBall.size;newBall.body.collideWorldBounds = true;

I changed phaser.js to bypass the issue, I just wanted to report it:

this.position.x = (this.sprite.world.x - (this.sprite.anchor ? this.sprite.anchor.x : 0 * this.width)) + this.offset.x;this.position.y = (this.sprite.world.y - (this.sprite.anchor ? this.sprite.anchor.y : 0 * this.height)) + this.offset.y;
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...