PDA

View Full Version : Image change on collision --- Need help please



Wizard
15-12-2006, 08:29 AM
Hi all...I got the code to work up to the point where my enemy image is changed to an explosion image. Problem is that the explosion image now stays on the screen and it should be dead and the bullet lives on when it's supposed to be dead. When I call dead the image change is ignored.

What am I doing wrong here? Your help is appreciated :-)

BTW: My game works on 85 fps and has a resolution of 1024*768, I read someones post that DelphiX can't handle that resolution. I'm using Delphi 6 and DelphiX :)


procedure TBullet.Hit;
begin
Collisioned := False;
Image := Form1.DXImageList1.Items.Find('Explode');
Width := Image.Width;
Height := Image.Height;
AnimCount := Image.PatternCount;
AnimLooped := True;
AnimSpeed := 15/1000;
AnimPos := 0;
Form1.DXWaveList1.Items.Find('hit').Play(False);
end;

procedure TBullet.DoCollision(Sprite: TSprite; var Done: Boolean);
begin
If (Sprite is TEnimy) then
begin
TBullet(Sprite).Hit;
Enimies := Enimies -1;
Points := Points + 1000;
Done := False;
end;
end;

Traveler
15-12-2006, 09:21 AM
One thing I do see is that your explosion animation shouldn't be looped.
I believe a call to the dead procedure upon the last frame of the animation, and in the bullet. hit procedure, should do the trick, for both problems.

Btw, where did you read that delphix can't handle such a resolution? Because I don't think that is correct. (Your game is proof of that).

(On other small thingy: its TEnemy, not TEnimy. )

Wizard
15-12-2006, 10:04 AM
Thanks for your reply. When Dead is called in the TBullet.DoCollision the image of the enemy does change and the bullet is killed but the new image (explosion) is not killed. When dead is called in the HIT procedure no image change and bullet not killed. When Dead is called in both the HIT and DoCollision the bullet is killed but the image does not change. I have disabled the call to looped as suggested.

How do I get the last frame of the animation?

BTW It was one of your posts in this forum :-)

Traveler
PGD Staff


Joined: 05 Nov 2002
Posts: 1171
Location: Netherlands
Posted: Tue Apr 13, 2004 1:08 pm Post subject:

--------------------------------------------------------------------------------

Seems to me that a turn based game doesn't need a high fps.

In any case, here's a few general things you might want to look at:
- using 256 colored graphics will help some.
- using 8bit color mode will help even more
- limit the drawing to the visible parts of your game.
- don't use alpha blending
- don't use canvas.fill(0) if your screen is already filled with tiles
- don't use standaard texts (ie. canvas.textout)
(- decrease the resolution, 1024x768 is too much for DelphiX)

Perhaps you can post a few screenshots. It might help a little to see where the problem areas are.
_________________
"Not all those who wander are lost."


Back to top

Wizard
15-12-2006, 11:47 AM
I think I got it !!!

I placed the following line in the enemy.doMove procedure :


if image = Form1.DXImageList1.Items.Find('Explode') then
dead;


It now works as I want it, I don't know if it's the right way but it seems fine :-)

Chesso
03-01-2007, 12:25 PM
I'm curious to know, how you got it to show the full explosion animation before making it dead in the sprite engine?

I figured a call to Dead; anytime after you change the image would just kill it before the animation had time to show properly?

jasonf
03-01-2007, 01:20 PM
the best way is to create a special explosion sprite, create it at the point where the explosion happens. it can then spawn additional particles for debris, smoke.. etc.

Chesso
03-01-2007, 01:33 PM
While I'm not sure what setup he has, one thing that gets to me, is how the animation plays it's full cycle perfectly, and then just dies.

How does one time something like that without some complex code, or am I missing something lol.

jasonf
03-01-2007, 01:53 PM
Not complex code at all really.

You keep a count of the number of frames the explosion has existed for. Then at a predefined point, you kill it.

So, you'd have an explosion class.

It's got a life count, say your animation is 10 frames long.
In your DoMove for the explosion, you increment this count and if the count > 10, then self.die;

You'd have an initializer method on the explosion called Explode(X,Y); which you'd call to set it up.. or you could do this in the constructor. So this would position the explosion in the correct place and set the counter to 0, it also sets up the animation, animpos:=0 animcount:=10 animstart := 0

You could also use the animpos property I think. but then you'd never see the last frame.. if animpos = animcount then die;

Chesso
03-01-2007, 02:05 PM
Then one could easily make the last frame blank and transparent :P. Cheap but it would work lol.