Isometric Tile Mouse Stuff
Hello,
I have been reading a few of the articles on isometric tile games and have been trtying a few things. One problem I had was finding out if the mouse was within a tile. The tile is obviously not square, it''s diamond shaped, so it wasn''t exactly easy.
One article suggested a huge array of values that represented the tile. Plugging in the X and Y of the mouse gave a value telling if the mouse was inside the tile, or if not, which neighbour it was inside. I didn''t really like this technique because it seems wasteful and hard to modify with different tiles. I haven''t tried it - and would rather not.
Other methods included using equations to determine whether the mouse was above or below each line. I tried this and it didn''t work for me. I''m sure it DOES work, but I couldn''t get the maths right.
So to get to the point... I remembered some API calls for dealing with regions. These are CreatePolygonRgn and PtInRegion. I created a diamond region and simply call PtInRegion to see if the mouse is in it. PtInRegion means "Point In Region" I believe. This method worked really well! However, is it inefficient? I don''t know if this is the sort of thing the functions were intended for, but it is working well - and it''s so easy!
Is there any reason not to use these functions? i.e. are they slow, resource hungry, unreliable?
Thanks in advance,
MrBo.
I''ve never used the region stuff in the WinAPI I just made an offscreen surface that was the size of the screen and used the x,y position to create a color that represented the tiles location and updated this screen every time I moved the screen. When a mouse moves around just read the color from the offscreen ''tile-mouse map'' and then de-code the x,y tile co-ord.
I''ve got some code posted on my website I think its at :
www.stevesprogpage.f2s.com/Files/Putra.zip
There is an asm procedure called SpecialBlit as part of DXMain that I wrote to blit a 16 bit tile to the back buffer and to my offscreen image as a solid color tile.
The asm proc is a re-write of a alpha blending asm proc found on gamedev.net''s articles.
One thing to note : with this method you are limited by screen res:
8bpp - 14 x 14
16bpp - 254 x 254
24bpp - 4095 x 4095
32bpp - 65535 x 65535
So before you start thinking of using a smaller bpp count because you not using too many colors, look at the above info.
All of my code in that .zip file is wrote for 16bpp, if it''s different then you will have to re-write the SpecialBlit() code.
Hope that helps you a bit
I''ve got some code posted on my website I think its at :
www.stevesprogpage.f2s.com/Files/Putra.zip
There is an asm procedure called SpecialBlit as part of DXMain that I wrote to blit a 16 bit tile to the back buffer and to my offscreen image as a solid color tile.
The asm proc is a re-write of a alpha blending asm proc found on gamedev.net''s articles.
One thing to note : with this method you are limited by screen res:
8bpp - 14 x 14
16bpp - 254 x 254
24bpp - 4095 x 4095
32bpp - 65535 x 65535
So before you start thinking of using a smaller bpp count because you not using too many colors, look at the above info.
All of my code in that .zip file is wrote for 16bpp, if it''s different then you will have to re-write the SpecialBlit() code.
Hope that helps you a bit
When I find my code in tons of trouble,Friends and colleages come to me,Speaking words of wisdom:"Write in C."My Web Site
November 10, 2000 02:19 PM
I can send you my code, I''ve done it for simple diamond shaped tiles using linear equations, it''s in fact quite easy (at least it was for me). But I have another question: what is if you include a tile height? I.E. each of the four vectors has a "height" value, which is then subtracted from the y-position on the screen when I am drawing to screen. But if I am determining the position of the mouse in iso-coordinates, the program does not know what tile it is in, so it does not know the vertex height value in this point, and so it can''t retrace it back. Do you know a solution?
Hey anon / asd_de as long as you are using 2d tiles the code link that I put up will do what you want, if you are using D3D then the same pricible can be used, look thought the threads in this forum (the isometric one) there is an article about the technice I used in that program
When I find my code in tons of trouble,Friends and colleages come to me,Speaking words of wisdom:"Write in C."My Web Site
Thanks Steven, but what if I still want to do it using maths? Or do I HAVE to use colors then? For Example, how is it done in games like AoE2?
:/ I thought I had left that file there, oh well I''ll re-upload it.
I have not found a good way to convert from screen to tile co-ords, execpt for what I''m doing now. I did have some code for Blitz Basic on the amiga but I no longer have it, it was part of a iso map editor that a magazine was writing as a tutorial for blitz basic. Unfortunattly I chucked the mag out (thanks to my parents complaining about the number of magazines I have on computers) and the magazine is no longer in print. I wish I could find my amiga programming disks as I may have it on one of them somewhere, but I have not been able to find it for the past 2 years.
AoE might have used the same technique that I implemented, or they could have done something different, I do not know what they could have done.
OK It''s back on-line and I''ve checked it, it''s a working zip files containing graphics and code. No executable. It was wrote for DX7
I have not found a good way to convert from screen to tile co-ords, execpt for what I''m doing now. I did have some code for Blitz Basic on the amiga but I no longer have it, it was part of a iso map editor that a magazine was writing as a tutorial for blitz basic. Unfortunattly I chucked the mag out (thanks to my parents complaining about the number of magazines I have on computers) and the magazine is no longer in print. I wish I could find my amiga programming disks as I may have it on one of them somewhere, but I have not been able to find it for the past 2 years.
AoE might have used the same technique that I implemented, or they could have done something different, I do not know what they could have done.
OK It''s back on-line and I''ve checked it, it''s a working zip files containing graphics and code. No executable. It was wrote for DX7
When I find my code in tons of trouble,Friends and colleages come to me,Speaking words of wisdom:"Write in C."My Web Site
Umm I did post once how it works... it was about a month ago (this forum) so you might want to try and search for it.
I strongly recommend NOT using colours with D3D - in new graphics cards you can switch on Anti-Aliasing and, umm, you know what that means I guess If not: it interpolates the colours at the border between two tiles - have a lot of fun
- JQ, PWC Software
"programming is all about wasting time" -me
I strongly recommend NOT using colours with D3D - in new graphics cards you can switch on Anti-Aliasing and, umm, you know what that means I guess If not: it interpolates the colours at the border between two tiles - have a lot of fun
- JQ, PWC Software
"programming is all about wasting time" -me
~phil
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement