• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
FalconDragoon

Isometric Tile Picking Solved!

8 posts in this topic

Alright, I'm at my wits end, maybe someone out here can lend some insight. I'm currently working on an Isometric Tile-Based project in XNA. I'm using the Java app Tiled for map editing and all that. Everything has been going swimmingly so far, however I've reached a bit of a road block. I can't figure out the math I need to do tile picking (screen coords to tile coords). a lot of the things I've seen have had the maps drawn to the screen starting at the top left tile as 0,0 and shifting accordingly. However the maps produced using Tiled are to be drawn with the top center tile as 0,0 with X going down-right and Y going down-left. (Screenshot to show what I mean) Screenie If anyone out there could point me in the right direction on this, I would much appreciate it, as I think I'm about to go insane. [Edited by - FalconDragoon on January 3, 2009 12:08:23 PM]
0

Share this post


Link to post
Share on other sites
Without being able to give specifics, because you haven't told us your tile sizes, all we can really tell you is that the math for translating from screen-space coordinates (the mouse click) to tile-space coordinates is such that both the x and y results are both dependent upon the x and y inputs due to the diagonal nature of the tile indexing -- as opposed to rectangular tile grids, in which x an y are completely independent.

The formula can be coded as a 3x2 matrix, accounting for the transformation and the x/y offset (viewport centering).

Now, this only covers the simple case where the isometric grid doesn't contain any tiles which have "height" or any objects which extend beyond the diamond of a single tile. If you have tiles with height or large objects, you'll need to do additional work.
0

Share this post


Link to post
Share on other sites
That does help some, I should have thought to add the tile dimensions.
Currently I'm using tiles that are effectively 64x32.
I understand the concept (To a degree) of how it's supposed to work, but I just can't wrap my head around how to implement it...

Thankfully I don't have any large objects or height to worry about.

Oh, and thanks for the response.

EDIT: would it be possible for you to elaborate a bit on the 3x2 matrix bit?

The first part of your reply is what I had deduced, the second part, I'm sure, could be the missing link with a little bit of detail.

[Edited by - FalconDragoon on December 3, 2008 4:35:08 PM]
0

Share this post


Link to post
Share on other sites
its simple really, I'll start from tile--> screen and then see how it goes from screen to tile. Of course you should replace the numbers 64 and 32 by constants for easy change.


tile --> screen
for every tile you go in the X direction you go 64 pixels right and 32 pixels down,
for every tile you go in the Y direction you go 64 pixels left and 32 pixels down,

on screen right=positive x, left=negative x, up=negative y, down = positive y

so we get:
pixel_x = X_LOCATION_OF_TOP_MIDDLE_TILE + 64*tile_x - 64*tile_y
pixel_y = Y_LOCATION_OF_TOP_MIDDLE_TILE + 32*tile_x + 32*tile_y


now to do the screen --> tile
for ease of writing, pixel_x = px, tile_x = tx, X_LOCA... = X0

equation1: px = X0 + 64*(tx-ty)
equation2: py = Y0 + 32*(tx+ty)
we want to find equations for tx and ty when given px and py, so we do some algebra:

eq1+2*eq2 = px+2py = X0+2Y0 + 128*tx
---> tx = (px+2*py -X0-2Y0)/128

eq1-2eq2 = px-2py = X0-2*Y0 -128ty
---> ty = (px-2py - X0+2*Y0) /(-128)

I hope that was clear, and maybe you learned some math from it :)


the matrices are just compressed way to do the algebra.

[Edited by - Iftah on December 5, 2008 6:08:28 AM]
1

Share this post


Link to post
Share on other sites
Nice, this could indeed be just what I needed. I plan on studying this quite a bit. I've been successfull in converting from tile->screen coords, but the other way has been weighing heavily on my algebra challenged mind.

Thanks a ton for the assist!

Admittedly I am still curious about the matrix solution.
0

Share this post


Link to post
Share on other sites
WooT! Awesome man that did the trick! well after a couple of tweaks.

Firstly, I couldn't figure out where the 128 was comming from (It was the one thing that had me confused) changing it to 64, though, got the whole thing right on.

Thanks a ton!

[Edited by - FalconDragoon on December 22, 2008 12:24:49 PM]
0

Share this post


Link to post
Share on other sites
So this doesn't have to do with mouse coords / tile picking, but I have a question about clipping.

I'm working on an Isometric (64x32) tile game in Java, and I'm having an issue with the placement of my graphics on the JFrame after clipping (it was pretty funny the first time i saw what it was doing)

So I won't include code unless anyone wants it, to keep the post shorter but here's what I have now:

A JFrame,
A Subclass of JPanel that I created

All of the drawing I do is in an overridden version of the JPanel's paint() method. I create an "offscreen" Graphics instance to draw to and at the end, draw it to the JPanel's Graphics object and paint. Well I have clipping set up to move the clip window as you move the player, to keep your view of yourself centered (with respect to what's displayed on your screen).

The specified rectangle is clipped as expected/desired, however on the JFrame it appears as if the whole map is drawn and you are just viewing the area that is clipped. The clipping window moves around the JFrame.. lol.

I'm using setBounds() on the JPanel because I plan to add other things to the JFrame, and this JPanel will only be the Viewable Map portion of the Game GUI. So I think modifying where I set the bounds could fix this problem but I just thought I'd ask here and see if anyone has experience with this before I start trying a bunch of different things :P
0

Share this post


Link to post
Share on other sites
Could just be me, but that's tough to picture. Screenshot?

EDIT: I think I see what your saying (After re-reading) I'm assuming that the window you have is as big as the entire map and your just moving around a square to view a small piece (Like a lense or fog of war type thing)?
0

Share this post


Link to post
Share on other sites
Heh sorry, I was able to solve my problem today.

Rather than moving my JPanel so that the clipped region -always- shows up at the same place on the JFrame, I just change the coordinates used to draw the graphics (current map) to the JPanel, and keep the clip region in the same place.. and that did it :)

[Edited by - pete2705 on December 23, 2008 9:35:54 AM]
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0