Jump to content

get corners of sprite after rotation


babycarlitos
 Share

Recommended Posts

Hello everyone,

I have 2 questions and I think they both deal with math.

1. How do i get the x,y,  x+ width and y+ height of a sprite after setting a rotation (corners of sprite)

image 1 (white background image)

2. how do i make a sprite look at the position of the mouse ( rotate to where the mouse is)

I tried various version and this seems to give me the closes one

 var angle = Math.atan2(mouseX - (boxIMG.position.x), -(mouseY - boxIMG.position.y));

then set the rotation to that

boxIMG.rotation = angle; but is not working correctly (black background image)

rotation example.jpg

mousee.jpg

Link to comment
Share on other sites

thans ivan,  that would be easier than me doing the math, just have to update to version 4. i will try that for the first question. For the future, should i do 2 posts separating the questions? I didn't do it since I figure they were somewhat related ( both deal with rotation)

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...