Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
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  
  Repeating infinite-like background  (Read 1262 times)
0 Members and 1 Guest are viewing this topic.
Offline Kronos

Junior Member


Medals: 1



« Posted 2013-10-24 16:22:09 »

Hello guys,

I need your help again. Imagine you're looking onto a road like a bird and you're flying it in eastern direction. I want the background to be always white stripes (the road middle marks) to move with. I already got a crappy solution ( I won't show it yet, because I want to see what you think) but as I said this is crap.

Or this way: How would you draw an infinite road from the birds-eye's view?

Thanks a lot.

cheers Kronos
Offline opiop65

JGO Kernel


Medals: 124
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #1 - Posted 2013-10-24 16:34:48 »

Tile it. Have one texture for a section of the road and just draw new instances of it as you love down the road. You can add overlays to it to add unique things such as cracks or holes in the road. But I think tiling is probably the most efficient and probably the easiest way.

Offline Zhon

Junior Member


Medals: 4



« Reply #2 - Posted 2013-10-24 18:18:56 »

If the road is a single image and it doesn't change, you can look up for parallax scrolling (not sure if that's the correct name for it)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline opiop65

JGO Kernel


Medals: 124
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #3 - Posted 2013-10-24 18:29:57 »

Parallax is images scrolling in opposite directions, giving a side scroller 'depth'. The concept probably could probably be the same though.

Offline Kronos

Junior Member


Medals: 1



« Reply #4 - Posted 2013-10-24 19:15:18 »

Thanks for the answers. Right now I have two ArrayLists. The First contains my street marks as rectangles. The second is the "garbage collector" for the rectangles, which aren't seen anymore.
I add them this way:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
         
if (player.x % 800 > last) {

float width = 160;
float height = 15;
for (int i = 0; i < 10; i++) {
streetMarks.add(new Entity(streetMarkcounter * width + streetMarkcounter * 60, Window.getHeight() / 2, width, height));
streetMarkcounter++;
}

last = (int) (player.x % 800);
}


So every 800 pixels there should come these marks. But sometimes, that doesn't work. I also use this way to add new enemies, every 800 pixels. But something is wrong.

Does anyone know whats up there? thanks
Offline Dxu1994
« Reply #5 - Posted 2013-10-24 20:54:06 »

This is the code I use in Renoria to render parallax, "infinite" repeating backgrounds:

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  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
private void renderBackground(RenderSpace g, int absolutex, int absolutey) {
      int hs = getHorizontalSpacing(), vs = getVerticalSpacing();
      if (this.horizontalRenderMode == RenderMode.STRETCH) {
         if (this.verticalRenderMode == RenderMode.STRETCH) {
            g.drawSprite(background, absolutex, absolutey, width, height, null);
         } else if (this.verticalRenderMode == RenderMode.TILE) {
            for (int i = ((absolutey) % vs) - vs; i < Core.view_RenderY + vs + Core.GameHeight; i += vs) {
               g.drawSprite(background, absolutex, i);
            }
         } else if (verticalRenderMode == RenderMode.NONE) {
            g.drawSprite(background, absolutex, absolutey, width, vs);
         } else {
            throw new Error();
         }
      } else if (this.verticalRenderMode == RenderMode.STRETCH) {
         if (this.horizontalRenderMode == RenderMode.TILE) {
            for (int i = ((absolutex) % hs) - hs; i < Core.view_RenderX + hs + Core.GameWidth; i += hs) {
               g.drawSprite(background, i, absolutey);
            }
         } else if (horizontalRenderMode == RenderMode.NONE) {
            g.drawSprite(background, absolutex, absolutey, hs, height);
         } else {
            throw new Error();
         }
      } else if (this.horizontalRenderMode == RenderMode.TILE) {
         if (this.verticalRenderMode == RenderMode.TILE) {
            for (int i = ((absolutex) % hs) - hs; i < Core.view_RenderX + hs + Core.GameWidth; i += hs) {
               for (int j = ((absolutey) % vs) - vs; j < Core.view_RenderY + vs + Core.GameHeight; j += vs) {
                  g.drawSprite(background, i, j);
               }
            }
         } else if (this.verticalRenderMode == RenderMode.NONE) {
            for (int i = ((absolutex) % hs) - hs; i < Core.view_RenderX + Core.GameWidth + hs; i += hs) {
               g.drawSprite(background, i, absolutey);
            }
         } else if (this.verticalRenderMode == RenderMode.STRETCH) {
            for (int i = ((absolutex) % hs) - hs; i < Core.view_RenderX + hs + Core.GameWidth; i += hs) {
               g.drawSprite(background, i, absolutey, hs, height);
            }
         } else {
            throw new Error();
         }
      } else if (this.verticalRenderMode == RenderMode.TILE) {
         if (this.horizontalRenderMode == RenderMode.NONE) {
            for (int i = ((absolutey) % vs) - vs; i < Core.view_RenderY + vs + Core.GameHeight; i += vs) {
               g.drawSprite(background, absolutex, i);
            }
         }
      } else if (horizontalRenderMode == RenderMode.NONE && verticalRenderMode == RenderMode.NONE) {
         g.drawSprite(background, absolutex, absolutey, null);
      } else {
         throw new Error();
      }
   }


In particular:

1  
2  
3  
4  
5  
6  
7  
if (this.verticalRenderMode == RenderMode.TILE) {
            for (int i = ((absolutex) % hs) - hs; i < Core.view_RenderX + hs + Core.GameWidth; i += hs) {
               for (int j = ((absolutey) % vs) - vs; j < Core.view_RenderY + vs + Core.GameHeight; j += vs) {
                  g.drawSprite(background, i, j);
               }
            }
         }

Pages: [1]
  ignore  |  Print  
 
 

 

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

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (53 views)
2014-04-15 18:08:23

BurntPizza (51 views)
2014-04-15 03:46:01

UprightPath (65 views)
2014-04-14 17:39:50

UprightPath (48 views)
2014-04-14 17:35:47

Porlus (65 views)
2014-04-14 15:48:38

tom_mai78101 (89 views)
2014-04-10 04:04:31

BurntPizza (149 views)
2014-04-08 23:06:04

tom_mai78101 (245 views)
2014-04-05 13:34:39

trollwarrior1 (203 views)
2014-04-04 12:06:45

CJLetsGame (210 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!