Results 1 to 6 of 6

Thread: How to know when collisions are NOT taking place

  1. #1

    How to know when collisions are NOT taking place

    Simple in delphix to work out when a sprite is colliding:

    Simply> collision; in the domove and it will fire when a collision occurs.

    But what if I need to know when a collision is not taking place at any 1 time.

    See the problem I have, is I am collecting jewels. Now, one jewel in particular needs to be hit 3 times before it turns into diamond

    When I hit once, it increments the counter of times it has been hit. But, once it has been hit I need to set the boolean to false so it may not be hit again.

    I would like to then set back to true second it realises the collision is no longer occuring:

    For example: Approaching jewel>>>>collision detected>>docollision is used>>>1 is added to the counter>>>boolean is set to false to stop further collisions>>collision with jewel is over>>>boolean is set back to true awaiting next collision.

    Perhaps I am doing this a long way?

    Any ideas?

  2. #2

    How to know when collisions are NOT taking place

    There is a way to detect if the colision is ocurring outside the docollision ?
    From brazil (:

    Pascal pownz!

  3. #3

    How to know when collisions are NOT taking place

    well, since dephix fires only when it detects a collision, presumably it knows when one is not?

  4. #4

    How to know when collisions are NOT taking place

    Quote Originally Posted by seiferalmasy
    well, since dephix fires only when it detects a collision, presumably it knows when one is not?
    my idea :

    from the main loop keep checking the collisions
    if the bool is true then don't "docollision" if false "docollision" and set the bool to true
    From brazil (:

    Pascal pownz!

  5. #5

    How to know when collisions are NOT taking place

    You must do something like this:

    [pascal]

    //---------------
    // game loop code
    //----------------
    var
    PrevIsColliding, IsColliding: boolean;
    HitCount: integer;
    begin
    //save previous collision state
    PrevIsColliding := IsColliding;

    //somewhere in main game loop
    IsColliding := false;

    //check the collision for each sprite, so that IsColliding might change to true
    checkCollision;

    //compare old collision state with new one
    if PrevIsColliding <> IsColliding then
    if IsColliding then Inc(HitCount);
    end;

    procedure TMySprite.DoCollision( blablabla )
    begin
    isColliding := true;
    end;
    [/pascal]

    I hope you understand this code. If not, i will explain it now.

    You must keep track of the Collision state with the "IsCollision" variabele. You must also save the collision state from the last game loop execution. When "PrevIsCollision" and "IsCollision" are not equal, something has happened. e.g The collision has started, or the collision has stopped.

    You only have to check, which one of the two things happened. When IsCollision is true, PrevIsCollision should be false, which means that the collision has just begun, because during the last game loop, no collision was detected (PrevIsCollision = false).

    Hope you understand this.

    Good luck
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  6. #6

    How to know when collisions are NOT taking place

    I understand thanks!

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
  •