Results 1 to 5 of 5

Thread: Ideas needed to 2d sprite z-ordering sort

  1. #1

    Ideas needed to 2d sprite z-ordering sort

    I'm developing a 2d game that requires the sprites to be z-order sorted but am not sure how to go about doing this. Basically the sprites move around a rectangular space at angles of 45 degrees. The sprite that the user controls can move in the normal four directions and also diagonally. As they overlap each other the sprites higher up the screen need to be drawn first. Should I base the sort on the Y-axis or have a separate variable ? I also don't want to sort the sprites every frame so how should I be checking to know when to resort the list ?

    I have put together a short video that shows the game running so you can see the sprite movement. I don't expect there to be more than 6 moving sprites on screen at anyone time.

    http://uk.youtube.com/watch?v=tl9ls02onj0

  2. #2

    Ideas needed to 2d sprite z-ordering sort

    I think the best way is to develop a 3D axis system and then map the coordinates. May be something like this:[pascal](* iX - "Width" input.
    * iY - "Height" input.
    * iZ - "Depth" input.
    * oX - "Width" output.
    * oY - "Height" output. *)
    PROCEDURE Map3D_2D (iX, iY, iZ: INTEGER; VAR oX, oY: INTEGER);
    BEGIN
    oY := iZ + iY;
    oX := iX + iZ;
    END;[/pascal]
    Didn't test this but I think you get the idea, didn't you? This way you can order the objects by its Z axis easy.
    No signature provided yet.

  3. #3

    Ideas needed to 2d sprite z-ordering sort

    I assume you have a x and y value for the sprites. If that's the case then just use a quicksort algorithm to sort on the y value of the sprite.
    I use this method as well for my game and so far its working pretty well.

  4. #4
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    Ideas needed to 2d sprite z-ordering sort

    I keep a list of all my sprites ordered by z-Order (usually based on Y position of feet). Before a sprite moves I take it out of the list, and after it moves I put it back in the right drawing order position.

    This is the same system as DelphiX uses.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  5. #5

    Ideas needed to 2d sprite z-ordering sort

    Thanks for all your input. I'm now sorting my sprites based on the y value plus the height of the sprite to get the feet position. I now need to implement some collision detection and that should complete the sprite movement code.

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
  •