0

So I had a quick question. I'm currently making a small game in java and I wanted to experiment with hiding the player behind fake 3D objects on the screen (Isometric drawing). Unfortunately I can't post a picture (Not enough rep). Basically it's a 3D block that is 32 by 48 that gives an illusion that it's 3D by having half of it a lighter color and the other half a darker one. The player is the same size as the block and can move freely around the map of these 'blocks'. If the player moves behind a block, it's bottom part is hidden behind it. The opposite when it moves in front, covering the non-player block. Now I made an example program in GameMaker Studio just to test it out. To make it work in GM, I made a script for each sprite that was one line of code:

depth = y * -1

This causes the bottom part of the player to 'hide' behind the blocks when it moves behind them. I looked into it a bit on GM's wiki and it's pretty much changing the 'depth' of the instances. Now my question is, how would I do something like this in Java?

P.S. This is not in a diamond. It is in a straight 2D world (looking 45 down towards objects from front).

EDIT: Here are some pictures of the GameMaker version:

Player Outside

Player Inside

moltom26
  • 3
  • 4

2 Answers2

0

Read about drawing isometric worlds. Read about Java and isometric development.

Community
  • 1
  • 1
Verhagen
  • 3,885
  • 26
  • 36
  • Not quite what I was looking for... That is for diamond isometric design. I was looking more for a rectangular design (See my images). – moltom26 Jun 16 '15 at 05:38
  • Ok, I see. The isometric keyword was little miss leading. – Verhagen Jun 16 '15 at 05:41
  • You would need to check in your Java code, that the location where the person is, has a block on the south side of him. If so, only the top should be shown, else the full person block should be shown. Or always draw all the block from top to bottom. That way, the lower row of blocks will hide the bottoms, of blocks drawn one row before. – Verhagen Jun 16 '15 at 05:43
  • 1
    @Verhagen Or rather just draw the blocks from top to bottom. – Kayaman Jun 16 '15 at 05:48
  • @Kayaman but how would that work when the player goes behind the blocks? The player would still be above the top of the block. That would only fix the issue with the blocks on the screen. – moltom26 Jun 16 '15 at 19:05
  • @Verhagen But how would I draw only part of it when he goes behind it? For instance, when the player is half way behind it. – moltom26 Jun 16 '15 at 19:06
  • I think what I have to do is draw the player as two separate images (top and bottom), and draw all bottom parts first on the map and then all tops. That way, when java displays them, the tops overlap the lowers. Resulting in the hidden bottoms. Just have to figure out how to draw the player at the same time as the world... – moltom26 Jun 16 '15 at 19:42
  • @moltom26 everything should be part of a map, so you just have to write the things, which are located on the map. – Verhagen Jun 16 '15 at 20:03
  • @Verhagen except my player is separate from the background. – moltom26 Jun 16 '15 at 20:17
  • @moltom26 If you draw your player first, then a wall on the block south of it, the top half of the wall will mask the bottom half of the player. So no, you don't need to draw halves separately. This means of course that you need to draw the player at the same time as the map, so you can't first draw the map and then the player. – Kayaman Jun 17 '15 at 05:07
0

Thanks to Kayaman for solving the problem:

If you draw your player first, then a wall on the block south of it, the top half of the wall will mask the bottom half of the player. So no, you don't need to draw halves separately. This means of course that you need to draw the player at the same time as the map, so you can't first draw the map and then the player.

Just for future use, layering images in java is determined by the order in which they are added. This was the exact answer I was looking for. The GM code was GameMaker's way of setting the order in which the images were added to the screen.

Thanks to everyone for the help!

moltom26
  • 3
  • 4