Jump to content

[ask] How to Rotate point with image

Recommended Posts

i want to p1 using image not point, and have some images not just p1 maybe p3 and p4 , p2 be a central rotating, can you help me ?


var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'try-rotate', {create: create, update: update, render: render });

var p1;
var p2;
var d = 0;

function create() {

p1 = new Phaser.Point(200, 300);
p2 = new Phaser.Point(300, 300);


function update() {

p1.rotate(p2.x, p2.y, game.math.wrapAngle(d), true);



function render() {

game.context.fillStyle = 'rgb(255,255,0)';
game.context.fillRect(p1.x, p1.y, 4, 4);

game.context.fillStyle = 'rgb(255,0,0)';
game.context.fillRect(p2.x, p2.y, 4, 4);


Link to post
Share on other sites

Create the point objects in the update function, rotate them, and assign the x/y to the image afterwards:

function update(){    var p = new Phaser.Point(img.x, img.y);    p.rotate(p2.x, p2.y, game.math.wrapAngle(d), true);     img.x = p.x;    img.y = p.y;    d++;}
Link to post
Share on other sites

Im not going to answer this but just wanted to say....

Your getting into the realms of "code this for me"....I hate that crap.

If you want people to try and "fix" your code, not "write" it, then show us some code!!!!

Create a simple example in JsBin or CodeIo of woteva and then people like me would be perfectly happy to fix it.


@XekeDeath : Love the sig :P  Got a mate who created a career as a coder using that advice....being an Aussie I wonder if he taught you ;)

Link to post
Share on other sites

Positioning sprites is exactly how Xekedeath told you do it. If you want orbiting points and images to boot then do it like that. I done a small example a while ago when playing with point data. Have a look and that should help you.




The planets are all following a rotating point and all i did was pass the X/Y to the image to stick with the rotating point data.

Link to post
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.

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.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...