sprite roatation

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.

Comments

: 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 spritewhile loading or initializing game. Everything elseis 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 isread one sprite horizontally and write to anothervertically. If the H and W are not the same, make sureyour target sprite can hold the data. If H and W are the same, thins are even simpler:

[code]

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;

: ok, i understand the code but i'm having some trouble. In the example you used : : var spr1,spr2 : array etc etc: : the thing is, i'm using something similar to this to handle my sprites:: : type spr1 = array [1..20*20] of byte : : and then doing this to draw the sprite:: : const floor : spr1 = (: 0,0,0,0,1,0,2,0,2,0,0,: 0,1,0,2,0,2,0,2,0,1,0, etc etc: : when i try and implement the code you suggested with this array, it wont let me. how do i get around this?: :

[code]type spr=array[1..9] of byte;

const flor:spr=(1,2,3, 4,5,6, 7,8,9);

var i,j,k,l:byte; flok:spr;

begin for i:=1 to 3 do for j:=1 to 3 do begin k:=(i-1)*3+j; l:=i+(j-1)*3; flok[k]:=flor[l]; end;end.[/code]

Use Watch to check the content of FLOR and FLOK variablesafter rotation...

ok, it's working - sort of - it puts some sort of image on the screen! it takes the original image and messes it up a bit

I understand the theory, i need to read my sprite array from left colom to right colom instead of top row to bottom row. i just can't implement it!!! could you take a look at my code for me and have a mess around please?

: ok, it's working - sort of - it puts some sort of image on the screen! it takes the original image and messes it up a bit :: I understand the theory, i need to read my sprite array from left colom to right colom instead of top row to bottom row. i just can't implement it!!! could you take a look at my code for me and have a mess around please?:

Hmmm.... If I understand it correctly you aretrying to modify your "put_sprite" routine...That's of course possible but not recommended.It's better to keep it as it is (keep it general)and just rotate image. Send me the full sourceand I will take a good look at it. I have somewherecode for my sprite editor with sample sprites.It is old and if I had to redo it, I would probablychange few things. But it works quite nice andI am sort of lazy :-). If you want I couldemail it to you.