Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

x and y in SDL

This topic is 6043 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! (I''ve got my own gdnet forum now, so you can ask questons there )

Anyway what do you mean "with your own coordinates?"

I''m working on the second tut right now. Maybe this piece of code will help you:

// <i>screen</i> must be a global global variable

void DrawIMG(SDL_Surface *img, int x, int y,
int w, int h, int x2, int y2)
SDL_Rect dest;
dest.x = x;
dest.y = y;
SDL_Rect dest2;
dest2.x = x2;
dest2.y = y2;
dest2.w = w;
dest2.h = h;
SDL_BlitSurface(img, &dest2, screen, &dest);

void DrawIMG(SDL_Surface *img, int x, int y)
SDL_Rect dest;
dest.x = x;
dest.y = y;
SDL_BlitSurface(img, NULL, screen, &dest);

// in main() or somewhere ...

SDL_Surface *image;

// Load a bitmap into image

image = SDL_LoadBMP("image.bmp");

// Now to draw the image onto the screen, use

DrawIMG(image, x, y);
// where x and y are screen coordinates.

// You can also use a more advanced function:

DrawIMG(image, x, y, w, h, x2, y2);

where x and y are the screen coords, w and h are the
width and height of the image to draw. If the w and h
are less than the image size, then the image is cropped
if they are more, then the image is not repeated.
x2 and y2 are the x and y of the image to display at
the point x and y. For example:

DrawIMG(image, 50, 60, 100, 100, 25, 55);

With this statement we would blit the SDL_Surface *image onto the screen starting at the point 50x60. We would blit 100 pixels right and down. We would start the blitting (at point 50x60) with the pixel of the image at the point (25x55). On point ((50+100)x60) we would then blit the point ((25+100)x55) from the image.

Hope this makes sence or cleared something up for you. If not, wait for the tut.

Multitasking - screwing up several things at once.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!