How do I center a sprite and move it relative to the map and other objects?

I am making a space game with heavy use of bitmaps and primitives. I am having difficulty figuring out how I would center the user controlled spaceship and move it relative to asteroids, lasers and (*eventually if I could make multiplayer*) other spaceships that are centered and can scroll. :-/ One thing I tried which didn't work out so well was drawing everything on the bitmap and redrawing the bitmap to prevent smears. It had some artifacts that while looking kind of cool where not what I intended. :P I am a newbie and well aware that my code is quite the kludge. :-X

Edgar Reynaldo

To center an image, draw it at x = (screen_width - bitmap_width)/2 , y = (screen_height - bitmap_height)/2 .

Or to center the screen on a ship, set its coordinates to ship_x - (screen_width - ship_width)/2 , ship_y - (screen_height - ship_height)/2 .


Wow, I feel stupid for not using al_hold_bitmap_drawing(), it makes drawing the tile map a lot smoother and no artifacts when I draw ship, lasers and asteroids! :). I'll see if my naive approach of simply drawing everything to the bitmap and scrolling that works.

Thread #617044. Printed from