Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (408)
games submitted by our members
Games in WIP (293)
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  
  Infinite map illusion.  (Read 1536 times)
0 Members and 1 Guest are viewing this topic.
Offline marcuiulian13

Senior Member


Medals: 3



« Posted 2012-08-27 17:27:26 »

Hello everyone!

I create a map storing some tiles in an array. The effect i want to achive is that when the display edge achives any border of the map, the tiles from opposite side start rendering next to the border (some sort of infinity in a big map). The problem is that i don't know how to do this so that when the display passes the upper edge and the left edge in same time, the "corner" beween renders. Also, how should i iterate trough the array to have less CPU cost?


The zone marked with "Huh" is the "corner".

Can anyone point me any idea?

Check out my current project: http://cube3dev.blogspot.com/
Please comment/review/suggest.
Offline Gjallar

Senior Member


Medals: 7


Follower of Nurgle


« Reply #1 - Posted 2012-08-27 17:33:59 »

You couuuuuld seperate the map in chunks, so that lets say the yellow rectangle is a chunk, the red one is a chunk, etc. and then just render the chunks that should be on the screen. Easy as pie... at least in my current thought process
Offline loom_weaver

JGO Coder


Medals: 16



« Reply #2 - Posted 2012-08-27 18:04:08 »

1  
2  
xIndex = x % map.width
yIndex = y % map.height
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline marcuiulian13

Senior Member


Medals: 3



« Reply #3 - Posted 2012-08-27 18:36:39 »

You didn't understand. I want my map to REPEAT, it isn't infinite.

Check out my current project: http://cube3dev.blogspot.com/
Please comment/review/suggest.
Offline loom_weaver

JGO Coder


Medals: 16



« Reply #4 - Posted 2012-08-27 18:45:11 »

Determine your viewport.  Iterate over the visible x and y values in that viewport.  Then use the formulas I gave you.

It doesn't matter if it's repeat or infinite.  You'll be using the same equation either way.  Infinite or not is a separate function of allowing/prohibiting an entity to move from one side to the other.
Offline marcuiulian13

Senior Member


Medals: 3



« Reply #5 - Posted 2012-08-28 09:58:47 »

By viewport you mean the Rectangle of the screen (using xOffset, yOffset and Display.getWidth(), Display.getHeight()) ?

BTW, i'm using LWJGL. And the map is a tile-map.

Check out my current project: http://cube3dev.blogspot.com/
Please comment/review/suggest.
Offline loom_weaver

JGO Coder


Medals: 16



« Reply #6 - Posted 2012-08-28 14:54:46 »

Yes, but given your viewport you'll need to determine what tile indices are visible within it and then plug them into the equations to get your map indices.
Offline Best Username Ever

Junior Member





« Reply #7 - Posted 2012-08-29 06:08:34 »

Loom_weaver's first post was exactly what you wanted. Alternatively, consider the pseudocode:

1  
2  
3  
min = ..., max = ..., range = max - min;
while(value < min) value += range;
while(value > max) value -= range;


Which might prevent rounding errors for floating point numbers or overflow issues with integral numbers. This is not the fastest method, but it's the basic idea behind the modulus operator (remainder division.) You will need to "reset" the value within an acceptable range to prevent those types of bugs with large integers/floating points. You will have to split up the object, shift, and draw up to four separate "quadrants" (red, orange, yellow, and gray) to display the scene correctly. If you can't split every object then you may have to draw it four times for each screen boundary (drawing most of the object off screen.)
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Try the Free Demo of Revenge of the Titans

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (125 views)
2013-05-17 21:29:12

alaslipknot (133 views)
2013-05-16 21:24:48

gouessej (163 views)
2013-05-16 00:53:38

gouessej (155 views)
2013-05-16 00:17:58

theagentd (168 views)
2013-05-15 15:01:13

theagentd (153 views)
2013-05-15 15:00:54

StreetDoggy (197 views)
2013-05-14 15:56:26

kutucuk (221 views)
2013-05-12 17:10:36

kutucuk (220 views)
2013-05-12 15:36:09

UnluckyDevil (224 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.079 seconds with 21 queries.