Show Posts
|
|
Pages: [1] 2 3 ... 5
|
|
1
|
Java Game APIs & Engines / Java 2D / Re: Picking Tile in staggered isometric map
|
on: 2012-12-19 05:58:03
|
I appreciate the help. It being the work week, I didn't get a chance to really put some time into any solution and I definitely am not going to post the embarassing hack I was attempting. I did get a plug and play solution involving some math equations that are quite a bit beyond me that I will post for anyone running into the same situation. It works great! dawsonk http://www.kirupa.com/forum/showthread.php?376083-Picking-Tile-in-staggered-isometric-mapMaybe try something like this... 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| var tileW = 64; var tileH = 32; var rows = 8; var cols = 4;
for (var i = 0; i < rows; ++i) { for (var j = 0; j < cols; ++j) { tTile = _root.attachMovie("Tile", "R" + i + "C" + j, _root.getNextHighestDepth()); tTile._x = (tileW * j) + ((i % 2 == 1) ? 32 : 0); tTile._y = (tileH / 2) * i; } } onMouseDown = function () { var ax, ay, bx, by; var cx = _xmouse; var cy = _ymouse; var posX = (_xmouse / 32) >> 0; var posY = (_ymouse / 16) >> 0; if ((posX % 2) == (posY % 2)) { ax = (posX) * 32; ay = (posY + 1) * 16; bx = (posX + 1) * 32; by = (posY) * 16; if (getPos(ax, ay, bx, by, cx, cy) < 0) { trace(((posY / 1 >> 0) - 1) + " : " + ((posX / 2 >>0) + ((((posY / 1 >> 0) - 1) % 2 == 0) ? 0 : -1))); } else { trace((posY / 1 >> 0) + " : " + (posX / 2 >> 0)); } } else { ax = (posX) * 32; ay = (posY) * 16; bx = (posX + 1) * 32; by = (posY + 1) * 16; if (getPos(ax, ay, bx, by, cx, cy) < 0) { trace(((posY / 1 >> 0) - 1) + " : " + (posX / 2 >>0)); } else { trace((posY / 1 >> 0) + " : " + ((posX / 2 >> 0) +((((posY / 1 >> 0) - 1) % 2 == 0) ? -1 : 0))); } } }; function getPos($ax, $ay, $bx, $by, $cx, $cy) { var slope = ($by - $ay) / ($bx - $ax); var yIntercept = $ay - $ax * slope; var cSolution = (slope * $cx) + yIntercept; if (slope != 0) { if ($cy > cSolution) { return $bx > $ax ? 1 : -1; } if ($cy < cSolution) { return $bx > $ax ? -1 : 1; } return 0; } return 0; } |
|
|
|
|
|
2
|
Java Game APIs & Engines / Java 2D / Re: Picking Tile in staggered isometric map
|
on: 2012-12-16 20:19:07
|
I create my tiles from a Tile object that has individual fields. I do store the x and y of the tile, but that just references the top left corner of the 64x32 tile, where it will be drawn. Plus I would have to iterate through all tiles until that tile is matched which would still be pointing to the tiles drawing origin. Of course this is in Flash, but the ideas are still the same. The formula for picking a tile in a diamond shape isometric map that was given by dishmoth in this post... http://www.java-gaming.org/topics/get-row-and-col-of-mouse-click-on-isometric-map/21914/msg/252507/view.html#msg252507 worked great for the diamond shape isometric map. But trying to chop that up to make it work for a staggered isometric map is proving to be quite a challenge. The issue I believe is in the staggering of the rows. I will keep staring at it until my eyes fall out in great goobs of goo 
|
|
|
|
|
3
|
Java Game APIs & Engines / Java 2D / Re: Picking Tile in staggered isometric map
|
on: 2012-12-16 18:17:24
|
Thanks for the input Dapy, I'm kind of confused on what tileX and tileY are returning in this formula... int tilex = (int)(screenx/TILE_WIDTH + screeny/TILE_HEIGHT); int tiley = (int)(screeny/TILE_HEIGHT - screenx/TILE_WIDTH); are those the coordinates for the tile that was clicked? I dont have any offsets, so I am starting my drawing at 0,0 on the screen I am using this for drawing my tiles... 1 2 3 4 5 6 7 8 9 10 11 12 13
| for (var i = 0; i < rows; ++i) { for (var j = 0; j < cols; ++j) { tTile._y = i*16; if (i % 2) { tTile._x = (j*64)+32; } else { tTile._x = j*64; } } } |
PS: should also explain that I'm not very good at abstract logic either, hehehe.
|
|
|
|
|
4
|
Java Game APIs & Engines / Java 2D / Re: Isometric item placement?
|
on: 2012-12-16 18:02:32
|
I use isometric tiles for everything in my game. I model the object in blender and render it using an isometric camera, then use Gile to give the tile a transparent background. Depending on the size of the object, it may be 64x32 or 64x64. (I use a sizing algorithm to draw the tile in the right spot when I draw the map) The object is placed on a layer with a higher zorder or depth than the table. My layers... 0 = ashpalt/concrete 1 = dirt 2 = grass/ floor 3 = objects (collidable, walls, trees, signs, furniture) 4 = decorations (paintings, candles, plates) 5 = collide layer (for detecting collisions) I haven't created any objects that are wider than 64, but using the same drawing algo based on size should work with those too. Heres a pic... 
|
|
|
|
|
5
|
Java Game APIs & Engines / Java 2D / Re: Isometric item placement?
|
on: 2012-12-16 13:16:15
|
I have used layers in my tile game in order to place certain things on top of other things. I used a layer called decorations in order to place paintings on walls, candles or plates on tables, etc. I also create the table using a 64x64 tile. I just put an algorithm in the tile drawing function that starts drawing that tile based on its height. Hope that helps a bit! 
|
|
|
|
|
6
|
Java Game APIs & Engines / Java 2D / Picking Tile in staggered isometric map
|
on: 2012-12-16 12:57:57
|
Hello! I have been looking and trying for quite a while now, but can't seem to work out an algorithm for figuring out which tile is selected on a staggered isometric map using 64x32 tiles with a diamond shape inside. Here is a pic of my map...  The first row is drawn, then the x is offset to the right by 32 and the next row is drawn. Anyone have any good math skills to throw some algorithms my way for this? Thanks for any help! PS: My math isn't exactly top notch, so please keep that in mind. 
|
|
|
|
|
7
|
Java Game APIs & Engines / Java 2D / Re: Get row and col of mouse click on Isometric map
|
on: 2012-11-30 05:53:33
|
I realize that this post is pretty old but I have to mention it again. Since this original post, I've been to Blitz, Torque, Flash, back to Java and all over. I recently went back to Flash and was needing to find the Map Row and Column on a Isometric map again. I spent another day looking all over the place...again and came upon this post. After I got to the bottom, I realized it was a post I started almost 3 years ago, lol! Hey, I'm old. Again, after all the searching and reading through articles/ Threads/ and tutorials, the information here is the best that I have come across. I was able to take it and plug it right into my project and it worked like a champ! Thanks again to all who contributed here! 
|
|
|
|
|
8
|
Java Game APIs & Engines / Java 2D / Re: Isometric 2D Tutorials?
|
on: 2010-04-09 07:23:18
|
Excellent List of information that I continually browse for information. Once I read the title of the post those links were the first thing I thought of posting. They all show a few different approaches and give a pretty good idea of what the Isometric view is. They should all at least give you a good stepping point as they did for me that will eventually lead you to understand what kingaschi and Alan_W are talking about. I've been working on my isotiler program for a few months now and I constantly keep changing the tile size, recreating my iso tiles in the new size and trying it out, just to start all over. The hardest part for me was figuring out how to detect what column and row the mouse was clicking in. Thanks from the help of Demonpants and Dishmoth, I finally got that working. SwampChicken, you may want to consider creating an Isometric Tutorial Link post in the Tutorial Section to help out the newbs like me. Thanks for all the info!
|
|
|
|
|
9
|
Games Center / Archived Projects / Re: Battlement - action/strategy multiplayer game of teamwork
|
on: 2010-03-20 04:51:14
|
I've gotta say, this was extremely impressive. Graphics were great, the interface was very good and the gameplay was creative. Its not very often you see multiplayer applets and you did a great job with this one. Well done!  1 thing you may look at adding is a score board. Maybe show the connected users a Kill/Death score and maybe a win/loss score. I had a great time and I definitely bookmarked the site. Thanks!
|
|
|
|
|
10
|
Game Development / Newbie & Debugging Questions / Re: A little hand to the absolute newby?
|
on: 2010-03-19 03:23:43
|
|
Personally I enjoy using the standard Java 2d. So far I haven't been able to max out its capabilities (yet). To me it doesn't require any user clicking agreement window thingys and its already setup, doesnt require any additional downloads, more apt to run on the end user machine or enviroment, plus there are a lot more tutorials and info on it.
I feel when my techniques and endeavors outgrow Java 2d, I will move to an accelerated api.
|
|
|
|
|
12
|
Java Game APIs & Engines / Java 2D / Re: Get row and col of mouse click on Isometric map
|
on: 2010-02-10 02:08:01
|
Wow, thanks for the input. I know using 3d can make life a bit easier in some aspects but will definitely make life harder in others. I spent over a year using Blitz3d and made a pretty cool (to me anyways  ) which I greatly enjoyed and had a lot of fun using, but I am looking for something more in the 2d area as far as look and feel. Dishmoth, what you provide was plugged in to my code and worked flawlessly. It will take me a bit to figure out what the formula is actually doing, If I can figure it out, lol, but it works! I found close versions of the math you provided on the net, but I think there were just a few differences, like the 0,0 origin, maybe. If I was giving out an award, you would definitely be the winner for the first out of tons and tons of web pages giving formulas, theories and ideas in every language, to provide a pluggable code. As far as I understood, Demonpants code was providing a point (mouse click), unrotating it and unscaling it. It matched what I was trying to achieve, but I easily got lost in the code and goal. I did work out my brute force, unorthodox version last night which I would show, but I think alot of people would point at me and laugh. It took me 118 lines of code to get the same results, not using a formula. I created a cell array which stores the origin x and origin y (top of each tile diamond) and the minimum, maximum x and y pixel values of each tile cell. When user clicks a tile, it would iterate through each cell and check ... if mouseX was larger than the minimum x and smaller then maximum x if mouse Y was larger than the minimum y and smaller then the maximum y This function would sometimes find 1 cell, sometimes 2 cells, in the case of finding 2 cells, it would iterate through the cells coordinates to find the matching coordinates. It did return the correct row and column even though it was a very inefficient way of doing it and I'm sure would prove to be way to slow when actually running a game. I really, really appreciate all the help and time people have put in on this and Demonpants I will still be eagerly awaiting the tutorial entry.
|
|
|
|
|
13
|
Java Game APIs & Engines / Java 2D / Re: Get row and col of mouse click on Isometric map
|
on: 2010-02-09 04:53:46
|
|
Thank you for the help. I did check that page out in my never ending scourge of the net to locate a solution. One of the problems with the solution he offers
"The fundamental realization is that you can just invert the map-to-screen transformation (used during rendering)."
I am not doing this, I am not transforming anything, just basically painting a rectangle in a staggered fashion.
I did look into actually using square 32x32 tiles , rotating, scaling then painting them, but the results were a bit beyond my limited capabilities. It was easier to create the iso tile in gimp, then just draw the alpha'd rectangle to the screen.
I will keep plowing though and I will re-re-re-re-read the article. Thanks!
|
|
|
|
|
14
|
Java Game APIs & Engines / Java 2D / Re: Get row and col of mouse click on Isometric map
|
on: 2010-02-09 00:51:24
|
|
Demonpants - Awesome! Cant wait to see it!
Dishmoth - I appreciate the info. KGP was one of the resources I referenced, even though it was a staggered map, which uses 1 gif file for the map and not indiviual tiles and uses keystrokes to move the player. In my multiple days of looking at this, I have read, re-read and made tons of attempts to apply other peoples formulas and ideas and I am not 1 bit closer to picking an iso tile on my map. I am thinking about using a brute force approach, even though they are always inefficient, I just need to get something to work.
Thanks for the input!
|
|
|
|
|
15
|
Java Game APIs & Engines / Java 2D / Re: Get row and col of mouse click on Isometric map
|
on: 2010-02-08 07:12:00
|
|
Ohhh man that would be truly outstanding!! Please, please put in mouse clicks to select tiles!!
I just spent about 14 hours today of trial and error, rereading this post and scouring the web for other ideas and still cannot get the tile pick corrected.
I realized that the reason you need some sort of map coordinates is to let you know what tile your choosing, duh! The problem is, there are different types of coordinate systems people use for this and trying to make one work for my map isnt getting it done.
Of course I have more than a few days, I've been going over this same problem now for about 4 days and I'm still no where closer than when I started.
Thank you very much for the time and effort!
|
|
|
|
|
16
|
Java Game APIs & Engines / Java 2D / Re: Get row and col of mouse click on Isometric map
|
on: 2010-02-08 01:53:43
|
Well, I've spent about 8 hours or so today on this. I tried mapping the coordinates in excel and found out that I couldnt map out the map coordinates the way I wanted to, which of course means Im thinking wrong about something here. I wanted a tile coordinates to read as 0,0 from the top of the diamond to 16,0 to the bottom right of the diamond and 0,0 from the top of the diamond to 0,16 to the bottom left of the diamond. When I tried mapping these coordinates out in an excel file. I couldnt do it...  Heres a pic of the real world coordinates...  I believe due to the staggering, it cant be represented the way I was wanting it to. I do understand the coordinates under the mouse are the real coordinates and the user clicks what he sees. I did rotate the point in the code you provided using the cosine and sine. I didnt get the results I was looking for so I was doing some trial and error, hehehe. Since then I went back to my original program which draws a standard grid. I rotated that and tried scaling down the y of the rendered image and that didnt turn out right. I then attempting to rotate and scale each tile then draw the image, which I couldnt get to render correctly. I did learn about the radians and degrees by making this attempt. In the end, I looked at it and asked myself, what is the exact reason for needing the Map Coordinates to be 0,0 at the top of the diamond, 16,0 at the bottom right? I'm not really going to be using those coordinates for anything so why am I spending so much time trying to figure them out? I will try out your code though just to see what it gives me. Again I really appreciate the time and effort your putting in here. Thank you. I will post any futher progress on this.
|
|
|
|
|
17
|
Java Game APIs & Engines / Java 2D / Re: Get row and col of mouse click on Isometric map
|
on: 2010-02-07 08:24:05
|
I still cant get this. I dont understand the math. In reality if you have a point or coordinates and you rotate them 45 degrees, then squish the y coord, you should get an accurate map coordinate in lieu of a real time screen coordinate. I have tried your code just to convert the mouse click coordinates to iso map coordinates and they are no where close to what they should be as well as every internet search code I have found, which tells me my brain is not accepting the data. Here is a pic of my map which is 10 rows x 10 cols in a simple array The map array draws the images based on the code above which reference iso tiles that are already rotated and scaled on the y axis. When a user clicks 160,0 in real world coordinates, the map should say the user clicked 0,0 in iso coordinates as displayed in the pic. My tiles or cells that contain the tiles are 32 pixels wide and 16 pixels tall. Here is the pic...  Demonpants, I tried your code that converts coords to iso coords, but they didnt give me the coorect values. I realize that in the end I will opt to use the (figure everything in a 2d grid, then just draw everything in an iso view) state, but right now I really need to find a solution to this part of my endeaver. Here is a the code I used to try and figure the iso coords of the mouse click... 1 2 3 4 5 6 7 8 9 10 11 12 13
| public Vector2 convertPointToIsometric(Vector2 point) { point.rotate(45,45); point.y *= 0.5; return point; } |
and here is the code i used to call the function... 1 2 3 4 5 6
| public void convert2Iso(int tX, int tY){ Vector2 tVect = new Vector2(tX,tY); Vector2 tVect2 = convertPointToIsometric(tVect); System.out.println("MapX: "+tVect2.x+",MapY: "+tVect2.y);
} |
This is using your Vector2 class of course. All I was trying to do was to convert a 2d mouse click coordinate to an iso coordinate where the iso map 0,0 starts at ortho map 144,0. Man this is tough. thanks for any and all help though!!
|
|
|
|
|
19
|
Java Game APIs & Engines / Java 2D / Re: Get row and col of mouse click on Isometric map
|
on: 2010-02-06 03:49:34
|
I definitely see your very well made point here and I can easily see the benefit of working with a standard ortho grid setup then just using the isometric functions to only display the map. I spent all day yesterday just figuring out how to paint the selected tile and it really threw me for a loop. I was making the iso tiles in gimp, basically just drawing in the rendered iso tile area which was 32x16, save it as a png and draw it on the map. I did draw on a normal 32x32, rotated it and scaled its height by .5, but it didnt look much different then just drawing on the tile that was already rotated. Just to make sure I am understanding you, you are saying to perform all the calculations, movements, placements, checks and game logic on a standard 10x10 grid, then convert the output to an isometric map and render it, right? I like this idea, this would really speed up things. I cant believe all the searching and checking suggestions from google, no one mentioned this. When I google "convert 2d mouse coordinates "Isometric"" all the return sites for the first 6 pages show visited links, lol. Thats a lot of reading. I will spend some time here to try to implement your suggestions and supplied code. I know I'm already upside down though because even constantly going back to your post yesterday, I couldn't really understand how your achieving this. So I will go ahead and throw the questions out there right off the bat (Again, I really, really appreciate the help!) 1 2 3
| point.add(isometricOffset); |
I dont know what this is for and what isometricOffset would be. I can see your adding this to a instantiated vector2 object. If the Vector2 just got instantiated, then the original x and y would be 0, 0. "This is the coordinate of the top-left usable space", which means that all your really doing is adding, in the case of a regular 2d grid, the origin which would be 0,0, the top left coordinate? Why are you calling it isometricOffset? so basically point.add(isoetricOffset) is setting the initial values of x, y of a newly instantiated Vector2 object, right? Please say correct! Then I can move on, hehehehe. :0
|
|
|
|
|
20
|
Java Game APIs & Engines / Java 2D / Re: Get row and col of mouse click on Isometric map
|
on: 2010-02-05 02:30:34
|
|
Thanks for the input. I appreciate the help.
SteveyO - I was thinking about something similiar to your idea. One I was looking at was to create a shape based on the mouse click coordinates, then rotate and squish the shape and return the new coordinates. Then check if those coords are inside a tile or something along those lines. I also thought of checking for collisions or going that route. I may still try one of these or your method.
DemonPants - The ideas and things your explaining there are a bit over my head. I have no idea about vector math and I cant remember anything about sin and cosine. I havent ever worked with vectors or points, so I would have to read up on them. Currently I am not doing any kind of transformation to create the ISO perspective. The tiles I use are already rotated and squished, then drawn to the screen based off an array. I will have to spend some time looking over your suggestion.
I will post back my findings. Thanks again for the suggestions
|
|
|
|
|
21
|
Java Game APIs & Engines / Java 2D / Get row and col of mouse click on Isometric map
|
on: 2010-02-04 07:22:48
|
I have been searching and trying for days and I cant seem to get anything going with this. I have a map thats 10 rows x 10 cols stored in an array and its gets drawn starting with 0,0 of the array at the top of the diamond then it draws from there going down and to the right. It then goes to the next row, which would be to the down and to the left of the previous tile and works its way down and to the right. It continues this until all the tiles are drawn. My tiles are 32 wide by 16 high. This is the function I use to draw the Isometric map... 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| x = 144; y = 2; if(tilesLoaded = true){ for(int i=0;i<rows;i++){ x = 144 - (i*(tileWidth/2)); y = 2 + (i*(tileHeight/2)); for(int j=0;j<cols;j++){ g.drawImage(tile[mapArray[i][j]].img,x,y,null); x = x + tileWidth/2; y = y + tileHeight/2; } } } |
I realize this question has been asked a few times but I cant understand the solutions I've found. I would really appreciate any help anyone can offer. Thanks!
|
|
|
|
|
23
|
Discussions / Suggestions / Re: Tutorials Section?
|
on: 2010-01-31 06:12:00
|
|
I am in strong favor of this. A dedicated Tutorial section would be awesome and I'm sure a very big hit. I wouldn't worry too much about good tutorials from bad ones. Even a bad tutorial can have some usuable information.
Please?
|
|
|
|
|
25
|
Discussions / General Discussions / Re: My Experience with Flash
|
on: 2010-01-26 03:13:21
|
|
I think another case in this discussion is the fact that Adobe Flash CS3 or CS4 cost over $700 unless your a student or along those lines whereas the JDK is free.
This will ultimately cause a pretty big problem for me due to the fact that I cant afford to purchase something like that for my meager little indie endeavors and adventures.
I didnt take a look at AS3, but from what I read and seen, it does look more to be quite a full scale library. Demonpants pretty much said what I failed to say in the first post. It takes quite a bit to manipulate the movie objects and keep track of layers and timelines to put everything together. Of course it was my first experience with it so I'm sure over time I would get used to it. I just feel more comfortable with using Java to build stuff from the ground up where with flash your forced to use the movieclips, layers and timelines.
It was still fun though.
|
|
|
|
|
26
|
Discussions / General Discussions / My Experience with Flash
|
on: 2010-01-24 08:25:23
|
|
I recently dived into flash after a Sun Forums incident and tried it out. I did like the GUI and the easy to use implementation of objects. The actionscript code was easy to understand and it was pretty easy to deploy a new game I made called Sky Falcon of WWII hosted on my YellzBellz site.
In conclusion though, I definitely favor Java and of course the applets. I found Flash to be somewhat a beginner setup and it being originally made just for animation made me understand that. Its more of a general tool that can be used to quickly make simple games as where Java can be used to make some really complex and intricate games that can be deployed in different enviroments or as stand alone games.
I think I will be sticking with Java and again would like to thank this community for all the help and support where the dudes at Sun.Java forums are a bit High on themselves, lol.
|
|
|
|
|
27
|
Game Development / Networking & Multiplayer / Re: Guidance question
|
on: 2010-01-16 06:14:23
|
|
I've read it quite a few times on these boards and others, and I have instituted a similar system in a few of my own trials of just sending a keypress update to other players. If player 1 moves, then send that 1 keystroke or move change to the other players and let the other players machines move that 1 updated player. If player 1 stops moving, send that 1 change to the other players. It was also recommended to send position updates every so often also.
Using this idea worked pretty good for me.
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|