Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (748)
Games in Android Showcase (226)
games submitted by our members
Games in WIP (834)
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 4304 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  
 
 

 
xxMrPHDxx (345 views)
2017-12-31 17:17:51

xxMrPHDxx (111 views)
2017-12-31 17:15:51

xxMrPHDxx (160 views)
2017-12-28 18:11:33

Ecumene (362 views)
2017-09-30 02:57:34

theagentd (505 views)
2017-09-26 18:23:31

cybrmynd (557 views)
2017-08-02 12:28:51

cybrmynd (488 views)
2017-08-02 12:19:43

cybrmynd (462 views)
2017-08-02 12:18:09

Sralse (425 views)
2017-07-25 17:13:48

Archive (1347 views)
2017-04-27 17:45:51
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
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!