|
-
Nov 30th, 2004, 09:17 PM
#1
Thread Starter
Junior Member
isometric tiles -mouse positio[Resolved]
ok i have been searching for the last 2 days trying to find a way to get the tile the mouse is on. If some1 could post a little tutorial or could tell me a website that is pretty straight forwad i would really appreaciate it.
Thnx
Last edited by vbuser1338; Dec 4th, 2004 at 11:27 AM.
-
Nov 30th, 2004, 09:21 PM
#2
You can try on the bottom here:
http://www.gamedev.net/reference/art...article747.asp
and an other thread on this forum here:
http://vbforums.com/showthread.php?s...ight=isometric
See if that helps you enough...if not, ask again.
ØØ
-
Nov 30th, 2004, 09:54 PM
#3
Ex-Super Mod'rater
This is also a good thread, solution isn't till the second page though:
http://www.vbforums.com/showthread.p...hreadid=250523
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Nov 30th, 2004, 10:53 PM
#4
If you are using a "standard" 32 x 64 tile positioned as in the topic Electroman mentioned, this code might help out:
VB Code:
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim NewX As Long, NewY As Long
Const XPadding As Long = 192
NewX = (X - XPadding) \ 2
NewY = Y - NewX
NewX = NewX + Y
Caption = Int(NewX / 32) & " x " & Int(NewY / 32)
End Sub
See the last page of the topic above for more information on XPadding and other stuff.
To explain what the code does: it translates the position mouse pointer is at in to a normal non-isometric 2D map. This way it is possible to determine the tile you are at. It is also possible to find out the exact position. If you do this code inverted, you can have object positions in memory like if they were in normal 2D map, but then convert the positions to isometric when drawing them to the screen. This would keep things simple for you.
-
Dec 1st, 2004, 05:38 PM
#5
Thread Starter
Junior Member
isometric mouse
i tried the one with the mousemap and started looking at it. and i use this code i pieced together.
RegionX = Int(x / 24)
RegionY = Int(-x / 2 + y) \ 24
becuase using
RegionX=int(MouseX/MouseMapWidth)
RegionY=int(MouseY/MouseMapHeight)*2
like it said to do was calculating where it was on the screen if it was a 2d map not in isometric
it seems to work with very little error except the 0,0 turns to 1,1 but every other tile works ok. the only thing that isn't working is the offsets but i thinks that is just the way i am scrolling.
if any1 sees a problem with the code i am using now i would apreciate them pointing it out. and by the way i am using 24 by 24 tiles if are trying to figure out what 24 was
thnx guys
-
Dec 1st, 2004, 05:51 PM
#6
Thread Starter
Junior Member
scrolling the map
i can't figure out how to do the scrolling. i dunno this is the right way but in tile-based you add offsets i don't know if that how you do it with isometric but it scrolls it. but then the mouse doesn't work. and yes i am adding the offsets to the position if that was ur question. the code i am trying to use is below
Select Case KeyCode
Case vbKeyLeft
xoffset = xoffset + 1
yoffset = yoffset + 1
Case vbKeyRight
xoffset = xoffset - 1
yoffset = yoffset - 1
Case vbKeyUp
yoffset = yoffset + 1
xoffset = xoffset - 1
Case vbKeyDown
yoffset = yoffset - 1
xoffset = xoffset + 1
End Select
i dunno if thats how u are supposed to do it but could some1 point me in the direction of a good tutorial
thnx
-
Dec 1st, 2004, 06:24 PM
#7
You should notice with the offset that you shouldn't give tile offset, but a real X or Y coordinate offset (in pixels). I think, atleast that is what you must do with my code. What I understood from your code, you are moving the map from tile to tile instead of smooth pixel by pixel movement.
-
Dec 1st, 2004, 07:46 PM
#8
Thread Starter
Junior Member
mouse position
ok i have it working now but the mouse click is off by 1 sometimes but that is not a big concern with me.
i would use the mouse map but it goes regionx = x /tilewidth and then regiony = y/tileheight * 2. but that is finding out the cord if it was 2d map. the x works for the first line liek row 0 of x but when go to row 1 then it goes off. you kno what i mean?
well here is my code
Select Case KeyCode
Case vbKeyLeft
xoffset = xoffset + 10
Case vbKeyRight
xoffset = xoffset - 10
Case vbKeyUp
yoffset = yoffset + 10
Case vbKeyDown
yoffset = yoffset - 10
End Select
For MapY = 0 To 31
For MapX = 0 To 31
x = ((MapX - MapY) * 24) + xoffset
y = (MapX + MapY) * 24 * 0.5 + yoffset
Sec = StretchBlt(picScroll.hdc, x,y, lngTileWidth, lngTileHeight, picTile(Tile(MapX, MapY)).hdc, 0, 0, 48, 47, vbSrcAnd)
Sec = StretchBlt(picScroll.hdc, P.x, P.y, lngTileWidth, lngTileHeight, picMask(Tile(MapX, MapY)).hdc, 0, 0, 48, 47, vbSrcPaint)
Next
Next
RegionX = Int(((x - xoffset) + 2 * (y - yoffset)) / (2 * 24)) - 1
RegionY = Int(((-x + xoffset) / 2 + (y + yoffset)) / 24)
MsgBox RegionX & "," & RegionY
if ne1 thinks of a way that i could improve it i would appreciate it. I dunno if i could use a mouse map with this code to make it more exact. If it is posible and would work i would appreciate it.
thnx for all ur help
-
Dec 1st, 2004, 08:37 PM
#9
Are you able to post your code so I or someone else can see what the code is like? Probably would shorten the helping time as we could do "direct hit" fix suggestions
-
Dec 1st, 2004, 10:04 PM
#10
Thread Starter
Junior Member
mouse position
[CODE]
Option Explicit
Private xoffset As Integer
Private yoffset As Integer
Private Type MapPoint
X As Long
Y As Long
End Type
Dim Tile(31, 31) As Integer
Dim Map(31, 31) As Integer
Dim MapX As Long
Dim MapY As Long
Dim P As MapPoint
Private regionx As Integer
Private regiony As Integer
Private intmapxdest(31, 31) As Integer
Private intmapydest(31, 31) As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyLeft
xoffset = xoffset + 10
Case vbKeyRight
xoffset = xoffset - 10
Case vbKeyUp
yoffset = yoffset + 10
Case vbKeyDown
yoffset = yoffset - 10
End Select
picScroll.Cls
DrawTiles
End Sub
Private Sub Form_Load()
picScroll.Left = 0
picScroll.Top = 0
xoffset = 0
yoffset = 0
For MapX = 0 To 31
For MapY = 0 To 31
intmapxdest(MapX, MapY) = ((MapX - MapY) * 24) + xoffset
intmapydest(MapX, MapY) = (MapX + MapY) * 24 * 0.5 + yoffset
Next MapY
Next MapX
DrawTiles
End Sub
Public Sub DrawTiles()
Dim intXTile As Integer 'Pic position with mouse over
Dim intYtile As Integer 'Pic position with mouse over
Dim MapX As Long
Dim MapY As Long
Dim P As MapPoint
With picScroll
.Width = (24 * 31)
.Height = ((24 * 31) / 2) + 24
End With
Dim Sec As Long
For MapX = 0 To 10
For MapY = 0 To 10
P.X = intmapxdest(MapX, MapY) + xoffset
P.Y = intmapydest(MapX, MapY) + yoffset
Sec = BitBlt(picScroll.hDC, P.X, P.Y, 48, 48, picTile(Tile(MapX, MapY)).hDC, 0, 0, vbSrcAnd)
Sec = BitBlt(picScroll.hDC, P.X, P.Y, 48, 48, picMask(Tile(MapX, MapY)).hDC, 0, 0, vbSrcPaint)
Next
Next
intXTile = ((regionx - regiony) * 24)
intYtile = (regionx + regiony) * 24 * 0.5
Sec = BitBlt(picScroll.hDC, intXTile, intYtile, 48, 48, picTileSelectPic.hDC, 0, 0, vbSrcAnd)
Sec = BitBlt(picScroll.hDC, intXTile, intYtile, 48, 48, picTileSelectMask.hDC, 0, 0, vbSrcPaint)
End Sub
Private Sub picscroll_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
regionx = Int((((X - xoffset) + 2 * (Y - yoffset)) / (2 * 24)) - 1)
regiony = Int((-X + xoffset) / 2 + (Y + yoffset)) / 24
picScroll.Cls
DrawTiles
MsgBox regionx & "," & regiony
End Sub
Private Sub picScroll_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
regionx = Int((((X - xoffset) + 2 * (Y - yoffset)) / (2 * 24)) - 1)
regiony = Int((-X + xoffset) / 2 + (Y + yoffset)) / 24
picScroll.Cls
DrawTiles
End Sub
k that is my code it runs ok besides the mouse position is a little off i dunno if that would work better with a mousemap
-
Dec 2nd, 2004, 01:12 AM
#11
-
Dec 2nd, 2004, 05:18 PM
#12
Thread Starter
Junior Member
mouse position
the offsets seem to be working for me if you move the map it selects the right tile. i dunno if that is the problem you are talking about but thnx
-
Dec 2nd, 2004, 11:28 PM
#13
Re: isometric tiles -mouse position
Yup, that was the problem, but as you can see I've edited the message later on and have fixed the bug You'd might have use for some kind of lesson on isometric world, but I'm not too familiar with either, even though I can think of these things (in this case mostly because I once helped someone with the issue - my closest shot to isometric was hexa-shaped landscape).
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
|