Jump to content
  • Advertisement
Sign in to follow this  

Question about sprites

This topic is 4705 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

Say if I have a sprite class and it has functions like draw(), mirror(bool x, bool y), rotate(int degres), scale(int x, int y) etc. How would you allow for the sprite to have multiple things done to it? e.g. Have it mirrored then rotated, then stretched? One way I thought was each sprite could have a original_surface and a current_surface variable. For example when you call rotate(20) it would take the original_surface, rotate it and put it in the current_surface. The problem would then be you would need a restore() function to set the current_surface back to the original and as you wouldn't know what had been done to the current_surface you would probably have to reset it every time? What do you think?

Share this post

Link to post
Share on other sites
your questions aren't very clear. first of all, what API are you using, OpenGL, or DirectX? and by mirror, do you mean something like a mirror image, or just another copy of that image? i do not know DirectX, but in OpenGL, you could rotate it by

float rotate = 30; //used to rotate the variable 30 degrees

void Render()
glRotatef(rotate,0,0,1); //rotate 30 degrees on z - axis
draw(); //draw your object

but that's openGL, you may be using DirectX, and for that matter, you might be using a different programming language altogether (this is c++)

for your current surface and orginal surface question
lets say your loading 2 bitmaps for your sprites

texture1 = LoadBitmapFile("bmpFile1.bmp");
texture2 = LoadBitmapFile("bmpFile2.bmp");

to switch between those two, all you would need to do is:

unsigned int switchBetweenTexture = texture1;

and then in your game loop just do:

int sprite = 0;
if(sprite < 10)
switchBetweenTexture = texture1;
switchBetweenTexture = texture2;
if(sprite > 20)
sprite = 0;

that would switch between the two textures, and that is a basic sprite algorithm. there are more advanced ways, and it's probably better to use time based changes, intsead of a loop counter change.

well that's all i have to say. hope i didn't overwhelm you with too much information.


Share this post

Link to post
Share on other sites
Well say for example if I have an entity mario. He has a walking sprite, a dying sprite and a standing sprite. If I press left I want to switch sprite to walking (no problems) but also mirror it on the y axis to make him face left. I was trying to see how to structure it rather than the actual code to mirror a surface.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!