: i've made a tile based level with a top down view. I have a sprite of a tank which can move up, down, left and right. the only thing i can't figure out is how to rotate the tank easily. I'm also looking for some sprite flipping/rotating routines if anyone has some.
:
:
:
All you need is to rotate by 90 degree? That's simple.
But let's first clarify few things:
Don't try to rotate sprite while game is in progress.
Make sure that you create 4 versions of the sprite
while loading or initializing game. Everything else
is not efficient and will slow your game down.
Now let's go back to sprite rotation:
The sprites are normally stored in arrays of bytes.
If H and W are height and width of the sprite,
the array size is H*W. So all you have to do is
read one sprite horizontally and write to another
vertically. If the H and W are not the same, make sure
your target sprite can hold the data.
If H and W are the same, thins are even simpler:
var spr1,spr2,... :array[1..H*H] of byte; { H and W are same }
i,j,k,l:byte;
;
;
;
{ let's assume Spr1 is the sprite w want to rotate.
the rotated image will be stored into Spr2 }
for i:=1 to H do
for j:=1 to H do
begin
k:=i+j*H;
l:=j+i*H;
spr1[k]:=spr2[l];
end;
Iby