Results 1 to 5 of 5

Thread: vb; Get screen x/y by isometric tile x/y

  1. #1

    Thread Starter
    Banned nareth's Avatar
    Join Date
    Jun 2004
    Posts
    1,206

    vb; Get screen x/y by isometric tile x/y

    can anyone help me in the right direction of this math

  2. #2
    Addicted Member
    Join Date
    Jun 2004
    Location
    USA
    Posts
    172

    Re: vb; Get screen x/y by isometric tile x/y

    You want to know which TILE your mouse is on by the coordinates on the screen? Or do you want to know, say, coordinates to draw a tile, by the x and y position of the tile?

  3. #3
    Addicted Member
    Join Date
    Jun 2004
    Location
    USA
    Posts
    172

    Re: vb; Get screen x/y by isometric tile x/y

    Heres how to get a tile x/y by where the mouse is:

    VB Code:
    1. Public Sub PointToTile(ByRef FlatX As Integer, ByRef FlatY As Integer, ByRef IsoX As Integer, ByRef IsoY As Integer)
    2.         Dim Z As Integer
    3.         Dim TileFlatWidth As Integer = TILEW / 2
    4.         Dim TileFlatHeight As Integer = TILEH
    5.  
    6.         Dim TileHalfHeight As Single = TILEH / 2
    7.         Dim TileHalfWidth As Integer = TILEW / 2
    8.         Dim TileHeight As Integer = TILEH
    9.         Dim TileWidth As Integer = TILEW
    10.  
    11.         Z = (TileCountX) * TileHalfWidth
    12.  
    13.         IsoX = (FlatX - Z) \ 2
    14.         IsoY = FlatY - IsoX
    15.         IsoX = IsoX + FlatY
    16.  
    17.         IsoX = Int(IsoX / TileFlatWidth)
    18.         IsoY = Int(IsoY / TileFlatHeight)
    19.  
    20.     End Sub

    Call it like this:

    VB Code:
    1. Dim TileX,TileY, MouseX,MouseY as Integer
    2. MouseX=Cursor.Position.X
    3. MouseY=Cursor.Position.Y
    4. TileX=MouseX
    5. TileY=MouseY
    6.  
    7. PointToTile(MouseX,MouseY,TileX,TileY)
    8.  
    9. 'Now tileX and tileY are the x and y of which tile your mouse is over.

    EDIT: P.S., I didn't make this function up. Someone from these forums gave me it, and I kind of changed it a little.

  4. #4
    Addicted Member
    Join Date
    Jun 2004
    Location
    USA
    Posts
    172

    Re: vb; Get screen x/y by isometric tile x/y

    And if you want to get the coordinates of where to draw an ISO tile onto the screen by the X and Y of the ISO tile, heres how to do that:


    Code:
    This will give you the coordinates of this point where the X is:
    
    X#########################################
    #                   0                    #
    #             0           0              #
    #      0                         0       #
    # 0                                    0 #
    #      0                         0       #
    #             0           0              #
    #                   0                    #
    ##########################################
    
    The #'s make up the box around the iso tile, and the 0's make up the iso tile.
    The X is where the coordinates to draw are.
    VB Code:
    1. 'TileX and TileY is the iso tile coords,
    2. 'for example, 0,0, 0,1, 3,3, etc.
    3. 'Usually goes to about 16,16.
    4.  
    5. 'NewX and NewY are the X and Y coords
    6. 'On the screen, of the top left of an iso
    7. 'tile, which is where you would draw the tile
    8.  
    9.  
    10. 'Set the new X to the middle of the screen
    11. NewX = SCREENW / 2
    12. 'Move the new X to the left, by half the width of a tile
    13. NewX -= TILEW / 2
    14. 'Set the new Y to 0 (top of the screen)
    15. NewY = 0
    16.  
    17. 'Increase the newX by half the tile width multiplied by the ISO tile X
    18. NewX += TileX * (TILEW/2)
    19. 'Increase the newY by half the tile height multiplied by the ISO tile X
    20. NewY += TileX * (TILEH/2)
    21. 'Increase the newX by half the tile width multiplied by the ISO tile y
    22. NewX -= TileY * (TILEW/2)
    23. 'Increase the newY by the tile height multiplied by the ISO tile y
    24. NewY += TileY * TileH
    25.  
    26.  
    27. 'Optional: If your sprites vary in Height:
    28. 'Decrease the newY by any height past the regular tile height
    29. NewY -= Sprites(SpriteID).SurfaceDescription.Height - TILEH
    Last edited by xjake88x; Jan 16th, 2005 at 11:48 PM.

  5. #5

    Thread Starter
    Banned nareth's Avatar
    Join Date
    Jun 2004
    Posts
    1,206

    Re: vb; Get screen x/y by isometric tile x/y

    your last post tha is what i ment and BTW to convert mouse x/y to isox/y i made that function with help from electroman

Posting Permissions

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



Click Here to Expand Forum to Full Width