Techbot Posted November 10, 2014 Share Posted November 10, 2014 console.log (pointer.x) work fine butconsole.log (pointer.worldX) shows up undefined. I am trying to get my player sprite to move to the point clicked within the playable area. (think diablo) I can use scrollable viewport with cursor keys, but once I try mouse click I end up going around in circles. sprite.rotation = game.physics.arcade.moveToPointer(sprite, 600);is fine (it does not need world co-ordinates) but it is constantly in action , ie it does not wait for mouse click whereas sprite.rotation = game.physics.arcade.moveToXY(sprite,x,y); would be nice if paired with game.input.onDown.add(moveBall, this);/ / update destination with world co-ords function moveBall(pointer) { x = pointer.Worldx; y = pointer.WorldY; } Any help at all would be great. Link to comment Share on other sites More sharing options...
lewster32 Posted November 11, 2014 Share Posted November 11, 2014 If you've copied and pasted your code in above, then Worldx and WorldY are not the same as worldX and worldY (JS is case sensitive) - so this may explain why you're getting 'undefined'. To get the world coordinates when using a camera, all you need to do is add the camera coordinates to the pointer coordinates:var worldX = this.game.world.camera.x + this.game.input.activePointer.x;var worldY = this.game.world.camera.y + this.game.input.activePointer.y;This is in fact how worldX and worldY are calculated within the Pointer object: http://docs.phaser.io/Pointer.js.html#sunlight-1-line-738 WombatTurkey 1 Link to comment Share on other sites More sharing options...
Techbot Posted November 17, 2014 Author Share Posted November 17, 2014 thanks LewsterSlightly embarressed , yep it was a typo.Is there a 'closed' tag for topics? Link to comment Share on other sites More sharing options...
lewster32 Posted November 17, 2014 Share Posted November 17, 2014 Just mark the appropriate post as solved - in this case probably your own post Link to comment Share on other sites More sharing options...
Recommended Posts