Sign in to follow this  
ukdeveloper

Representing SDL Bitmap as vector

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

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