Slick Forums

Discuss the Slick 2D Library
 It is currently Fri Mar 22, 2019 10:25 pm

 All times are UTC

 Page 1 of 1 [ 1 post ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Trouble rotating and scaling images at the same timePosted: Sat Jun 25, 2016 4:29 am

Joined: Sat Jun 25, 2016 3:58 am
Posts: 3
I'm having trouble drawing images with scales other than 1 and angles of rotation other than 0 degrees. Whenever I do, they appear with strange offsets that seem to have something to do with their centers of rotation, but don't actually center it there.

Here's my code. The image's center of rotation is (centerX, centerY); right and bottom are the image's width minus centerX and its height minus centerY, not adjusted to match the scale; xFlip and yFlip are both false; and angle is in degrees.

Code:
int index = 0;
float xOffset, yOffset;
if (xFlip) {
index += 1;
xOffset = Math.round(-right*scale);
} else {
xOffset = Math.round(-centerX*scale);
}
if (yFlip) {
index += 2;
yOffset = Math.round(-bottom*scale);
} else {
yOffset = Math.round(-centerY*scale);
}
images[index].setRotation((float)angle);
if (flashColor == null) {
images[index].draw(x + xOffset, y + yOffset, (float)scale);
} else {
images[index].draw(x + xOffset, y + yOffset, (float)scale, flashColor);
}

I've been testing this code using a 24x24 Mega Man sprite with centerX = 12 and centerY = 24 (in other words, centered between Mega Man's feet).

The first image is the result when I draw two sprites at the same x and y coordinates, one at angle = 0 and the other at angle = 180, with scale = 1, and it looks like I want it to. The second is the same thing when scale = 2, and the third is when scale = 0.5. The center of the red cross is the intended location of the center of rotation.

Does anyone know what's wrong here? I've tried setting xOffset and yOffset to 0, by the way, but the images with scales other than 1 and angles other than 0 still appear in odd places, just different odd places than they do here. Changing the center of rotation also changes the effect, but it only works as expected when the center is at (0,0).

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 1 post ]

 All times are UTC

Who is online

Users browsing this forum: No registered users and 4 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ General    Games / Demos    Help / Discussion    Community Projects    Game Ideas/Design    Slick Competition 2011    Android Slick - LWJGL 2D Game Library    Announcements    Bug Reports / RFE    Extensions    Contribution depot Related Libraries and Tools    Phys2D    Tiled    TWL    Fizzy    Artemis Archive    Resolved Bugs/RFE    Useful Posts