Sign in to follow this  

Sprite center

This topic is 4200 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello! I've finished by centering my global coordinate system on the bottom-left corner of the window but I'm still wondering where I should center my sprites. AFAIK, only two choices are preferable : Centered on sprite's center : - pro: Easy rotation - con: All maths require adding half width and half height to x and y components Centered on sprite's lower-left corner : - pro: easy to find sprite's left, top, right and bottom bounds (x,y,x+w,y+h) - con: no idea how to manage rotation I'm currently centering my sprites on their center but this makes all math very confusing and sometimes unreadable. As I see it, using bottom-left centered sprite would make unrotated sprite manipulation much more enjoyable but rotated sprite manipulation confusing as hell. -> Which solution is the best? -> Will it be easy to handle rotation with bottom-left centered sprites? -> What do you suggest me to do?

Share this post


Link to post
Share on other sites
- con: All maths require adding half width and half height to x and y components

You could always simplify this by adding functions with return values. IE... drawat(CX(),CY());
And then have said functions do the math for you. Would clean up syntax, I s'pose and also allow for easy rotation. Just a suggestion, though.


-Etyrn

Share this post


Link to post
Share on other sites
Agreed. Pick one set, and provide member functions (assuming an OOP approach) which calculate and return the other. It honestly is pretty arbitrary, at least until you find there's a bottleneck.

Actually, provide member functions to yield either set, so that one pair of functions (or single function, if you have an XY coordinate object) is a plain accessor and the other does some arithmetic. Then you are insulated from external code changes if you decide later to change which values you want to store in the sprite object.

However, you should also consider making those functions all private, and in turn called upon by public member functions that *do real work*. Accessors smell.

Share this post


Link to post
Share on other sites
Quote:
Original post by Trillian
Centered on sprite's lower-left corner :
- pro: easy to find sprite's left, top, right and bottom bounds (x,y,x+w,y+h)
- con: no idea how to manage rotation
...
-> Which solution is the best?
-> Will it be easy to handle rotation with bottom-left centered sprites?
-> What do you suggest me to do?


You can just use the bottom-left coordinate version. Rotation can be done by calculating the new coordinates of the 4 vertices like it was a centered sprite standing at (0,0), then add half width and height to the results before adding them to the bottom-left coordinates. This way you can position by the bottom-left of the unrotated sprite but rotate around the center.

Viktor

Share this post


Link to post
Share on other sites

This topic is 4200 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this