Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  2D Isometric-Diamond: Several question into one thread  (Read 3227 times)
0 Members and 1 Guest are viewing this topic.
Offline SgtAhri

Junior Newbie





« Posted 2012-05-07 19:01:42 »

Hello everyone, I'm new here Smiley


So I am currently working on a 2D Isometric-diamond Zombie survival game.

I have followed this guide for having a solid base: http://www.java-gaming.org/topics/basic-game/21919/view.html



My first problem is when I move my character my game renders white lines between the tiles like small render lags.

First problem kinda solved: I tried to increase increase the mapXOffset by deltaTime * 0.2 in each update and it removed all the white lines.
Though somehow I still think I'm doing it wrong by moving the mapXOffset instead of the player and now I have to somehow when I press the arrows keys they have to go to the update method hmm.


My plan is to keep the player in the center of the screen all the time, currently the player is the small black rectangle



The tiles graphic is both within a tilesheet.png

My tilemap array
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  
   //Tile map
  int[][] tileMap_array = new int[][] {
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},      
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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1,1,0,1,1,0,0,1,1},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1},      
      {0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,1,1}      
   };



Rendering the map and player
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
      for (int i=0; i<tileMap_array.length; i++)
      {
         for (int j=(tileMap_array[i].length-1); j>=0; j--)
         {
            if (tileMap_array[i][j] == 1)
            {
               //Getting subimage of tilesheet              
              g.drawImage(tileMap_img.getSubimage(0, 32, 62, 32), ((j*tileMap_img.getSubimage(0, 32, 62, 32).getWidth()) / 2)+((i*tileMap_img.getSubimage(0, 32, 62, 32).getWidth()) / 2) - mapXOffset, ((i*tileMap_img.getSubimage(0, 32, 62, 32).getHeight()) / 2)-((j*tileMap_img.getSubimage(0, 32, 62, 32).getHeight()) / 2) + mapYOffset, null);
            }
            else
            {
               g.drawImage(tileMap_img.getSubimage(0, 0, 62, 32), ((j*tileMap_img.getSubimage(0, 32, 62, 32).getWidth()) / 2)+((i*tileMap_img.getSubimage(0, 32, 62, 32).getWidth())/2) - mapXOffset, ((i*tileMap_img.getSubimage(0, 32, 62, 32).getHeight()) / 2)-((j*tileMap_img.getSubimage(0, 32, 62, 32).getHeight()) / 2) + mapYOffset, null);
            }              
         }
      }
     
      g.setColor(Color.black);
      g.fillRect(player.x, player.y, 10, 10);



When the player clicks an arrow key its not the player moving but the world around him.
1  
2  
   int mapXOffset;
   int mapYOffset;



So when the player clicks an arrow key I change the value of one of the map offsets
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
         @Override
         public void keyPressed(KeyEvent e) {
            // TODO Auto-generated method stub
           if (e.getKeyCode() == 37)
            {
               //Left arrow
              mapXOffset -= 5;
            }            
            else if (e.getKeyCode() == 38)
            {
               //Up arrow
              mapYOffset += 5;
            }
            else if (e.getKeyCode() == 39)
            {
               //Right arrow
              mapXOffset += 5;
            }
            else if (e.getKeyCode() == 40)
            {
               //Down arrow
              mapYOffset -= 5;
            }            
         }


I have two guesses, either its doing the small white lines because I has to re-render the whole world each time or its because I'm doing the variable changing within the code above and not using the the deltatime within my update method
1  
2  
3  
   protected void update(int deltaTime)
   {
   }





My second question is: How could I go about making collisions? I plan to put in objects, even interactive objects like doors and so on.

My third question is: When the player is close to a staircase how could I simulate he is walking up on the staircase to the next floor inside a building?


And ofcourse if there is any tip/advice where I could do something better, please say so.



Thanks in advance.
Offline jonjava
« Reply #1 - Posted 2012-05-07 19:37:08 »

This Thread might be of interest to you: http://www.java-gaming.org/topics/drawing-isometric-tiles-inside-a-screen/24922/msg/212780/view.html

Offline SgtAhri

Junior Newbie





« Reply #2 - Posted 2012-05-07 21:25:17 »


Thanks there is alot of good information Smiley

Could you tell me, is moving the offset of the map right or should I move the player instead?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Ciaran54

Junior Member


Medals: 4



« Reply #3 - Posted 2012-05-07 21:35:06 »

Could you tell me, is moving the offset of the map right or should I move the player instead?

There is not right or wrong in game programming Wink

Either is possible, I usually prefer to move the player and then offset the map based on the player. Although it sounds like more work, It makes moving the camera slightly for cutscenes or the like much easier, I feel.

Whichever seems easier and most suitable to your game is the one you should use, I know that both techniques are used.
Offline Rorkien
« Reply #4 - Posted 2012-05-07 22:09:19 »

Could you tell me, is moving the offset of the map right or should I move the player instead?

It only depends on what effect you want to achieve.

If you move only the map, the player will always be on the center. So if you move to the edges of the map there will be a big empty space (its not attractive and makes you lose part of the map vision)
If you move both the player and the map, you can make that the map no longer moves when you get on the edge, just the player
Offline ra4king

JGO Kernel


Medals: 336
Projects: 2
Exp: 5 years


I'm the King!


« Reply #5 - Posted 2012-05-08 00:13:28 »

It's best to move the player and then set mapX/YOffset to center the player again.

Offline jonjava
« Reply #6 - Posted 2012-05-08 00:44:02 »

It's best to move the player and then set mapX/YOffset to center the player again.

Offline SgtAhri

Junior Newbie





« Reply #7 - Posted 2012-05-08 13:46:40 »

It's best to move the player and then set mapX/YOffset to center the player again.


The player X and Y is the X and Y of the screen so if I change those the player would not be centered anymore, and the mapX and Y offset is just so the map is centeret on the screen.
Offline jonjava
« Reply #8 - Posted 2012-05-08 14:56:54 »

Then simply have the screen center around the player Smiley
1  
2  
screen.x = player.x - screen.width/2;
screen.y = player.y - screen.height/2;

Offline ra4king

JGO Kernel


Medals: 336
Projects: 2
Exp: 5 years


I'm the King!


« Reply #9 - Posted 2012-05-08 23:15:10 »

It's best to move the player and then set mapX/YOffset to center the player again.


The player X and Y is the X and Y of the screen so if I change those the player would not be centered anymore, and the mapX and Y offset is just so the map is centeret on the screen.
Then don't make the player's location as the screen location. Separate logic and render. All your data should be in world coordinates. When rendering, you convert to screen coordinates.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 336
Projects: 2
Exp: 5 years


I'm the King!


« Reply #10 - Posted 2012-05-08 23:16:40 »

Then simply have the screen center around the player Smiley
1  
2  
screen.x = player.x - screen.width/2;
screen.y = player.y - screen.height/2;

No, to find the offsets, you do:
1  
2  
offsetX = -(player.getX()+player.getWidth()/2) + screen.getWidth()/2;
offsetY = -(player.getY()+player.getHeight()/2) + screen.getHeight()/2;

Offline jonjava
« Reply #11 - Posted 2012-05-09 00:08:58 »

Depends how you implement it.. A screen object is much more intuitive and flexible imo. Ie instead of centering the map around the player, center the screen around the player and the map around the screen.

Offline SgtAhri

Junior Newbie





« Reply #12 - Posted 2012-05-10 15:06:57 »

Thanks for the great answers.

We've made a choice to move to jMonkeyEngine 3 where I am currently studying theire SDK and documentation and my friend is learning how to use Blender.


Against, thanks for the help.
Offline Damocles
« Reply #13 - Posted 2012-05-10 15:59:50 »

Move the player on the map, then scroll the map to center the player.
(so you can use the player like other NPCs)
If you notice jerky movement, cheat by not rendering the player based on the calculated position, but the fixed position
in the screens center. The playerchar is the most important object in the game, and should keep as steady as possible.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (4 views)
2014-07-24 01:59:36

Riven (7 views)
2014-07-23 21:16:32

Riven (8 views)
2014-07-23 21:07:15

Riven (9 views)
2014-07-23 20:56:16

ctomni231 (41 views)
2014-07-18 06:55:21

Zero Volt (37 views)
2014-07-17 23:47:54

danieldean (31 views)
2014-07-17 23:41:23

MustardPeter (33 views)
2014-07-16 23:30:00

Cero (48 views)
2014-07-16 00:42:17

Riven (49 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!