View Full Version : DelphiX Collision detection with animated sprites problem

17-02-2003, 03:14 PM

Nice to see Delphi(X) being discussed so often!

To contribute to this I've got a question.

We've been working on a space shooter called SpacePirates as our first game using Delphi 5 and DelphiX and we've stumbled on a problem... Collision detection.

I've checked the tutorials that come with DelphiX (especially Sprite Tutorial (the shooter)) and the collision works fine there.

But when I tried to create (in our game) a "coin" sprite that rotates the coin with 8 images the collision seems to work flawlessly only with the 1st image of the animation...

If the 1st image of the animation is drawn onto the screen the bullet that "collides" with the coin does its stuff (deals damage, destroys the Bullet sprite, etc.) but if the coin "has" any other image the bullet flies right "through" it...

I've been able to "cheat" my way through it so far by increasing the speed of the animation but we've decided to add some "squishers" (you know, the machine that slams itself closed and then opens again repeatedly and "squishes" anything in it's path) and now it's obvious that we won't be able to cheat our way out of this "mess".

So to describe the "Squisher" problem in detail...
The whole animation looks somthing like this:
----OO---- (1st pic)
--O....O-- (2nd pic)
-O.......O- (3rd pic)
O...........O (4th pic)
where - is "the metallic rod" that holds the O which is some sort of a "fist". The dot is empty space.

-> The problem is that when the player collides with the 1st picture it works fine, the player dies.

-> The 2nd picture "works" but not always. If the player collides with it, death is imminent, however, shooting it produces various results. The bullet may hit the rod/fist or it may not... which, of course, sux big time.

-> The 3rd and 4th picture don't work at all. The player may fly over them as if they didn't exist (but are drawn!). The Player dies if the "squisher" loops from the 4th to the 1st the picture.

The picture is 640*80 (= 640*20*4 Images).

There are no probs with proper image drawing. I check the transparent color by checking the pixel(0,0) color.

I used the same process to create an ImageSprite as in the tutorial.

Item creation procedure:

constructor TItems.Create(AParent: TSprite);
inherited Create(AParent);
PixelCheck := true;

with TItems.Create(Form1.DXSpriteEngine.Engine) do
Image := Form1.DXImageList.Items[Itemz[a].ImageNumber];
Width := Image.PatternWidth;
Height := Image.PatternHeight;

AnimCount := Image.PatternCount;
AnimPos := 0;
AnimStart := 0;
AnimSpeed := Pic[Itemz[a].PicNumber].AnimSpeed/1000;
AnimLooped := true;



Any ideas on fixing the problem efficiently (FPS now is about 70).

The game can be found at http://redpoint.no-ip.com/bojzgames but is still under development and can crash/not start. It should work on Win2k, though.


19-02-2003, 10:22 AM
I'm bumping this one. Come on people, someone must have used DelphiX's collision system :evil:

19-02-2003, 10:23 AM
Hello! :D

I've found a solution for the problem...

I fixed the collision detection by breaking the animation bitmap to several smaller pics and added them to the ImageList as separated Images.

The code needed some changes but it works fine without performance loss.

So instead of having
Image1 = bitmap 160 pixels wide 40 high
I made
Image1 = bitmap 40x40
Image2 = bitmap 40x40
Image3 = bitmap 40x40
and so on.

You need to add a "timer" variable so that you know when to change the Image property of the ImageSprite to the next Image.

Code Example:
If AnimationTimer > 0 then
if AnimationTimer = 0 then
if AnimationPosition = AnimationMaxPosition then AnimationPosition = 0 else inc(AnimationPosition);
Image := Form1.DXImageList.Items[PictureIndex+AnimationPosition].

This may not be the best way to solve the problem but it does work.

19-02-2003, 10:25 AM
Oh,.. and I seem to have posted the message in the wrong forum...

Someone please move it to DelphiX?...