Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (769)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (855)
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  
  Java2D Render Tiled Map  (Read 4659 times)
0 Members and 1 Guest are viewing this topic.
Offline printer

Junior Devvie


Medals: 1



« Posted 2016-06-16 18:02:19 »

Hello everyone,

I'm pretty new here and have basic knowlegde about java. I have a LUA background, but know basic Java.

I've started playing around with generate maps with two dimensional array and i fell in love with it. I saw this: http://www.cokeandcode.com/info/showsrc/showsrc.php?src=../../collision/tilemaps/src/org/newdawn/tilemap/Map.java

My setup look almost like this, but i added a camera: http://www.cokeandcode.com/main/tutorials/tile-maps/

My question: Is this a good way to render tiles? And also how can i only render tiles only inside my camera view.

Thanks everyone.

Offline steveyg90
« Reply #1 - Posted 2016-06-16 18:59:42 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
     int camX = CameraXPosition - SCREENWIDTH / 2;
     int camX /= TILEWIDTH;
     int endX = SCREENWIDTH / TILEHEIGHT + camX;
     int camY = CameraYPosition - SCREENHEIGHT / 2;
     int camY /= TILEHEIGHT;
     int endY = SCREENHEIGHT / TILEHEIGHT + camY;

     for(y=camY; y< endY; y++)
        for(x=camX; x<endX,x++)
           DrawTile(x, y);


Hope that helps.  The code you show for the tile map rendering isn't very good but it is a start, I would recommend the 2d array not be an int though, could easily be a simple byte.

Offline Opiop
« Reply #2 - Posted 2016-06-16 19:47:10 »

Be wary of ints vs byte if you are using each byte as an ID to reference a type of tile! Eventually you may run out of IDs to be passed out. Don't optimize until you know you need it Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline steveyg90
« Reply #3 - Posted 2016-06-16 20:45:26 »

8 bits in a byte  Grin
Offline Hydroque

JGO Coder


Medals: 25
Exp: 5 years


I'm always inspiring a good time.


« Reply #4 - Posted 2016-06-17 03:42:08 »

Lua and Java forever!

I loved putting Lua into my projects whenever I can. I even wrote a module which allows me to run Java to run Lua scripts which bounce off each other.

Anyways, store your tile information in many chunks. Render 6 chunks at a time, depending on their size and whether or not you want to do calculations to determine when the next chunks need to be wrote into memory and displayed... as well as the 3 that will be loaded out of memory.

You think I haven't been monitoring the chat? http://pastebin.java-gaming.org/c47d35366491fHere is a compilation <3
Offline printer

Junior Devvie


Medals: 1



« Reply #5 - Posted 2016-06-17 17:01:09 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
     int camX = CameraXPosition - SCREENWIDTH / 2;
     int camX /= TILEWIDTH;
     int endX = SCREENWIDTH / TILEHEIGHT + camX;
     int camY = CameraYPosition - SCREENHEIGHT / 2;
     int camY /= TILEHEIGHT;
     int endY = SCREENHEIGHT / TILEHEIGHT + camY;

     for(y=camY; y< endY; y++)
        for(x=camX; x<endX,x++)
           DrawTile(x, y);


Hope that helps.  The code you show for the tile map rendering isn't very good but it is a start, I would recommend the 2d array not be an int though, could easily be a simple byte.



It did not work Sad

I want todo something like this. fromPositionX, toPositionX and fromPositionY, toPositionY
Offline steveyg90
« Reply #6 - Posted 2016-06-17 18:32:09 »

I need to see your code, could you zip and send me your project?

Offline printer

Junior Devvie


Medals: 1



« Reply #7 - Posted 2016-06-20 11:35:31 »

I need to see your code, could you zip and send me your project?



Sorry for the late answer, but i've uploaded my code here:
http://www.java-gaming.org/topics/how-to-move-one-tile-grid-movement-like-pokemon-and-zelda/37528/view.html

Since that is a separate issue, you may can help me with the render certain radius in this thread.
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (1577 views)
2018-06-10 19:43:48

EgonOlsen (1661 views)
2018-06-10 19:43:44

EgonOlsen (1146 views)
2018-06-10 19:43:20

DesertCoockie (1574 views)
2018-05-13 18:23:11

nelsongames (1175 views)
2018-04-24 18:15:36

nelsongames (1666 views)
2018-04-24 18:14:32

ivj94 (2422 views)
2018-03-24 14:47:39

ivj94 (1632 views)
2018-03-24 14:46:31

ivj94 (2722 views)
2018-03-24 14:43:53

Solater (886 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!