## Pascal

Moderators: None (Apply to moderate this forum)
Number of posts: 14016

This Forum Only

sprite roatation Posted by beardtrix on 23 Nov 2001 at 7:54 AM
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.

Re: sprite roatation Posted by iby on 25 Nov 2001 at 8:42 PM
: 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
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

Re: sprite roatation Posted by iby on 25 Nov 2001 at 8:44 PM
```
Eh... typo...

:
: { let's assume Spr2 is the sprite w want to rotate.
:   the rotated image will be stored into Spr1 }
:
```

Iby

Re: sprite roatation Posted by beardtrix on 26 Nov 2001 at 7:01 AM
ok, how do i use this to put the rotated tile on the screen (i'm using puttile(x,y,name,where) ) would i just use the new array with the rotated tile in it as name?

Re: sprite roatation Posted by iby on 26 Nov 2001 at 6:40 PM
: ok, how do i use this to put the rotated tile on the screen (i'm using puttile(x,y,name,where) ) would i just use the new array with the rotated tile in it as name?
:
:

You got it...

Iby

Re: sprite roatation Posted by beardtrix on 27 Nov 2001 at 8:04 AM
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?

Re: sprite roatation Posted by iby on 27 Nov 2001 at 10:33 AM
: 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?
:
:

```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.
```

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

Iby

Re: sprite roatation Posted by beardtrix on 28 Nov 2001 at 6:02 AM
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?
Re: sprite roatation Posted by iby on 28 Nov 2001 at 10:33 AM
: 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 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
Re: sprite roatation Posted by Jeff P. on 6 Dec 2001 at 1:43 AM
Hello!
I was just surfing around at sourceforge and ran across something that might help...

http://sourceforge.net/projects/burn/

## Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic