Jump to content
  • Advertisement
Sign in to follow this  
ukdeveloper

Representing SDL Bitmap as vector

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

Hi, Supposing I've got a struct for a ball in a game of Pong...

struct pong_ball
{
       SDL_Rect b_rect;
       
       vector2f *position;
       
       vector2f *direction;
       
       float speed;
       
       pong_ball()
       {
                  position=new vector2f(25,50);
                  direction=new vector2f(1.0,1.0);
                  speed=0.5f;
       }
       
};

pong_ball g_ball;



I know how to blit images onto the screen using SDL, but how would I go about representing it in this form? Would I just call the usual Draw routine, but set the rectangle upper left x and y co-ords to be the same as the position variables in the vector? Then the ball would be drawn in a different place on each frame, presumably, representing the ball movement. I'm a little confused, ukdeveloper.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by ukdeveloper
Would I just call the usual Draw routine, but set the rectangle upper left x and y co-ords to be the same as the position variables in the vector? Then the ball would be drawn in a different place on each frame, presumably, representing the ball movement.


Yeap, sounds like you have it down [smile] Rather than:

SDL_Rect DestRect;
DestRect.x = 25;
DestRect.y = 25;
SDL_BlitSurface( image, 0, screen, &DestRect );


You will have something like this in your draw function:

SDL_Rect DestRect;
DestRect.x = position.x;
DestRect.y = position.y;
SDL_BlitSurface( image, 0, screen, &DestRect );

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!