Jump to content

[ask] How to Rotate point with image


nduhu
 Share

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);

d++;

}

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 comment
Share on other sites

If I'm right you mean you want images? Have you checked the examples? Tutorials?

You can add images and rotate that in your update. You can get images to follow points in the update by setting x/y values as the points values.

Still a very open and undescriptive question so I'm guessing what you 'might' mean.

Link to comment
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 comment
Share on other sites

Just create multiple images and apply the same code to each of them..

 

Store a reference to each image in an array and iterate over them, or put them in a Phaser.Group and use the forEach function to make it easier for yourself.

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

 

https://dl.dropboxusercontent.com/u/257829727/pointdata/index.html

 

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 comment
Share on other sites

 Share

  • Recently Browsing   0 members

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