#### Archived

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

# x and y in SDL

## Recommended Posts

(also in cone3d''s talkbox) Ack! Can someone tell me how to blit bitmaps and stuff with my own coordinates in SDL, cus this''s driving me nuts.

##### Share on other sites
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:

  // screen must be a global global variablevoid 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 imageimage = SDL_LoadBMP("image.bmp");// Now to draw the image onto the screen, useDrawIMG(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.

---
cone3d
http://cone3d.gamedev.net
Multitasking - screwing up several things at once.

• ### Forum Statistics

• Total Topics
628301
• Total Posts
2981906

• 9
• 11
• 11
• 10
• 10