Results 1 to 4 of 4

Thread: Image change on collision

  1. #1

    Image change on collision

    Hi there.

    I'm busy with a game using delphiX and would like to change the image to an explosion when my bullet/bomb hits my enemies...I had a look at the DelphiX Shoot sample and tried the code but it has no effect.

    Here's my Bullet.DoCollision:

    [pascal]
    procedure TBullet.DoCollision(Sprite: TSprite; var Done: Boolean);
    begin
    If (Sprite is TEnimy) then
    begin
    Sprite.Collisioned := False;
    Sprite.Dead;
    Enimies := Enimies -1;
    Form1.DXWaveList1.Items.Find('hit').Play(False);
    dead;
    // Image change
    Image := Form1.DXImageList1.Items.Find('Explode');
    Width := Image.Width;
    Height := Image.Height;

    Dead;
    Points := Points + 1000;
    Done := False;
    end;
    if (Sprite is TDisk) then
    begin
    Sprite.Collisioned := False;
    Sprite.Dead;
    Form1.Disk_No := Form1.Disk_No -1;
    Form1.DXWaveList1.Items.Find('hit').Play(False);
    // Image change
    Image := Form1.DXImageList1.Items.Find('Explode');
    Width := Image.Width;
    Height := Image.Height;

    dead;
    Points := Points + 2000;
    SpaceMines := SpaceMines + 1;
    if collisioned = true then
    Form1.NewDisk;
    Done := False;
    end;
    end;[/pascal]

    Any help/suggestions?
    Wake up from the dream and live your life to the full

  2. #2

    Image change on collision

    Hello,
    if you call "Dead;" just after switching images you won't have any
    effect because the sprite is destroyed immediately after.

    If you want to show an animation you have to switch images, get the
    pattern count and start animating the new image. When AnimPos reaches
    PatternCount of the explosion image you actually call Dead.

    Of course you have to disable collision detection when the sprite is
    exploding so a good way is to set a boolean like "isDying" where if true
    you won't check for collisions anymore, or something like that.

    Hope this make sense
    <center>
    <br />Federico &quot;FNX&quot; Nisoli
    <br />Lead Programmer - FNX Games
    <br />http://www.fnxgames.com
    <br /><img src="http://www.fnxgames.com/imgs/banners/fnxban.gif">
    <br /></center>

  3. #3

    Image change on collision

    Thanks :-) The call to dead was the problem. I took out dead and it works 100% :-)

    Well not 100%, now the bullet lives on and kills other enemies.....I have to think about the correct solution...

    Code:
    If &#40;Sprite is TEnimy&#41; then
      begin
        Sprite.Collisioned &#58;= False;
        Sprite.Dead;
        Enimies &#58;= Enimies -1;
        Form1.DXWaveList1.Items.Find&#40;'hit'&#41;.Play&#40;False&#41;;
        // Image change
        Image &#58;= Form1.DXImageList1.Items.Find&#40;'Explode'&#41;;
        Width &#58;= Image.Width;
        Height &#58;= Image.Height;
        AnimCount &#58;= Image.PatternCount;
        AnimLooped &#58;= true;
        AnimSpeed &#58;= 15/1000;
        AnimPos &#58;= 0;
        Points &#58;= Points + 1000;
        Done &#58;= False;
      end;
    Wake up from the dream and live your life to the full

  4. #4

    Image change on collision

    Normally what happens is, the bullet dies but before it does, it tells the engine to apply an effect at the location where the bullet hit.

    If you build in a generic effects system, you'll be able to make your bullets do all sorts of things when they die and the explosions can live on long after the bullet has died.

    I'd personally create an explosion sprite and a bullet sprite. They both have quite different tasks to do.

    You should generally make a class do *one thing* and do it well.

    If you wanted to make other things explode in the same way, if you put the animation and sound code in the bullet, you'd have to copy this code to other objects. This common code would be better placed in another class.

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
  •