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
:
:
:
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:
[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;
[/code]
Iby
Eh... typo... ;-)
:
: { let's assume [b]Spr2[/b] is the sprite w want to rotate.
: the rotated image will be stored into Spr1 }
:
[/code]
Iby
:
:
You got it...
Iby
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?
:
: 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 variables
after rotation...
Iby
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?
:
: 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 are
trying 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 source
and I will take a good look at it. I have somewhere
code for my sprite editor with sample sprites.
It is old and if I had to redo it, I would probably
change few things. But it works quite nice and
I am sort of lazy :-). If you want I could
email it to you.
Iby
I was just surfing around at sourceforge and ran across something that might help...
http://sourceforge.net/projects/burn/