|
-
Jan 16th, 2005, 10:53 AM
#1
Thread Starter
Banned
vb; Get screen x/y by isometric tile x/y
can anyone help me in the right direction of this math
-
Jan 16th, 2005, 11:31 PM
#2
Addicted Member
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?
-
Jan 16th, 2005, 11:34 PM
#3
Addicted Member
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:
Public Sub PointToTile(ByRef FlatX As Integer, ByRef FlatY As Integer, ByRef IsoX As Integer, ByRef IsoY As Integer)
Dim Z As Integer
Dim TileFlatWidth As Integer = TILEW / 2
Dim TileFlatHeight As Integer = TILEH
Dim TileHalfHeight As Single = TILEH / 2
Dim TileHalfWidth As Integer = TILEW / 2
Dim TileHeight As Integer = TILEH
Dim TileWidth As Integer = TILEW
Z = (TileCountX) * TileHalfWidth
IsoX = (FlatX - Z) \ 2
IsoY = FlatY - IsoX
IsoX = IsoX + FlatY
IsoX = Int(IsoX / TileFlatWidth)
IsoY = Int(IsoY / TileFlatHeight)
End Sub
Call it like this:
VB Code:
Dim TileX,TileY, MouseX,MouseY as Integer
MouseX=Cursor.Position.X
MouseY=Cursor.Position.Y
TileX=MouseX
TileY=MouseY
PointToTile(MouseX,MouseY,TileX,TileY)
'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.
-
Jan 16th, 2005, 11:42 PM
#4
Addicted Member
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:
'TileX and TileY is the iso tile coords,
'for example, 0,0, 0,1, 3,3, etc.
'Usually goes to about 16,16.
'NewX and NewY are the X and Y coords
'On the screen, of the top left of an iso
'tile, which is where you would draw the tile
'Set the new X to the middle of the screen
NewX = SCREENW / 2
'Move the new X to the left, by half the width of a tile
NewX -= TILEW / 2
'Set the new Y to 0 (top of the screen)
NewY = 0
'Increase the newX by half the tile width multiplied by the ISO tile X
NewX += TileX * (TILEW/2)
'Increase the newY by half the tile height multiplied by the ISO tile X
NewY += TileX * (TILEH/2)
'Increase the newX by half the tile width multiplied by the ISO tile y
NewX -= TileY * (TILEW/2)
'Increase the newY by the tile height multiplied by the ISO tile y
NewY += TileY * TileH
'Optional: If your sprites vary in Height:
'Decrease the newY by any height past the regular tile height
NewY -= Sprites(SpriteID).SurfaceDescription.Height - TILEH
Last edited by xjake88x; Jan 16th, 2005 at 11:48 PM.
-
Jan 17th, 2005, 01:58 AM
#5
Thread Starter
Banned
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|