Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (542)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (605)
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 2356 times)
0 Members and 1 Guest are viewing this topic.
Offline marcuiulian13

Senior Devvie


Medals: 5
Exp: 3 years



« Posted 2012-08-27 15: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?

Getting a project done is by far the most hard thing in game development.
Offline Gjallar

JGO Coder


Medals: 13
Projects: 1


Follower of Nurgle


« Reply #1 - Posted 2012-08-27 15: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: 17



« Reply #2 - Posted 2012-08-27 16: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 Devvie


Medals: 5
Exp: 3 years



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

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

Getting a project done is by far the most hard thing in game development.
Offline loom_weaver

JGO Coder


Medals: 17



« Reply #4 - Posted 2012-08-27 16: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 Devvie


Medals: 5
Exp: 3 years



« Reply #5 - Posted 2012-08-28 07: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.

Getting a project done is by far the most hard thing in game development.
Offline loom_weaver

JGO Coder


Medals: 17



« Reply #6 - Posted 2012-08-28 12: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 Devvie





« Reply #7 - Posted 2012-08-29 04: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.

 

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

The first screenshot will be displayed as a thumbnail.

Elsealabs (16 views)
2014-12-28 10:39:27

CopyableCougar4 (19 views)
2014-12-28 02:10:29

BurntPizza (24 views)
2014-12-27 22:38:51

Mr.CodeIt (15 views)
2014-12-27 04:03:04

TheDudeFromCI (20 views)
2014-12-27 02:14:49

Mr.CodeIt (26 views)
2014-12-23 03:34:11

rwatson462 (58 views)
2014-12-15 09:26:44

Mr.CodeIt (47 views)
2014-12-14 19:50:38

BurntPizza (96 views)
2014-12-09 22:41:13

BurntPizza (115 views)
2014-12-08 04:46:31
How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50
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!