Results 1 to 9 of 9

Thread: Image change on collision --- Need help please

  1. #1

    Image change on collision --- Need help please

    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

    [pascal]
    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;[/pascal]
    Wake up from the dream and live your life to the full

  2. #2

    Image change on collision --- Need help please

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

    [size=9px](On other small thingy: its TEnemy, not TEnimy. )[/size]

  3. #3

    Image change on collision --- Need help please

    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
    Wake up from the dream and live your life to the full

  4. #4

    Image change on collision --- Need help please

    I think I got it !!!

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

    Code:
    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 :-)
    Wake up from the dream and live your life to the full

  5. #5

    Image change on collision --- Need help please

    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?

  6. #6

    Image change on collision --- Need help please

    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.

  7. #7

    Image change on collision --- Need help please

    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.

  8. #8

    Image change on collision --- Need help please

    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;

  9. #9

    Image change on collision --- Need help please

    Then one could easily make the last frame blank and transparent . Cheap but it would work lol.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •