It looks like you're new here. If you want to get involved, click one of these buttons!
Hi All,
There are many ways to scroll backgrounds from simple sprite drawing to 3D skybox rotation. I have tried my hand at them all but still find myself not knowing the best way to build code for each separate, with different requirements, projects.
One instance I have is drilling a large 2D map which is populated with objects that change move and interact - sprite or mesh?
Another instance involves a psuedo 3D scrolling terrain which is large but also wraps on the edges. It uses a 3D object for the hero and the plain scrolls in all directions.
Finally, not got to this stage yet, but a full infinite scrolling terrain with 3D hero and multi level shaded landscape.
Some of the recent posts from @dave1707 have whetted my appetite again and I have been digging out the old half finished projects.
Just wondering if some of our better programmers could fire in a little help to point me and other users in the direction of best options, and things to consider when trying to code them.
Comments
Hi All,
Just a more specific query, if you have a large mesh terrain which would display well over the limits of the screen - can you select a subset of the mesh for display? Objective to minimise resources and keep tight control on screen output.
This can be done with sprites and large images.
@Bri_G I hacked one of my games to show scrolling over a terrain that measures 5,000,000 by 5,000,000 pixels. You can go even higher depending on the map you use. If the map gets spread to thin, it doesn’t look too good. I tried 1,000,000,000 by 1,000,000,000 pixels and the FPS was still around 60. I don’t think you need a terrain that large. At the speed I have the ship going (100 pixels per second) it would take about 115 days to go 1,000,000,000 pixels. So that’s probably a large enough terrain for a game without having to resort to subsets.
PS. Placing objects on the terrain can probably be done in subsets.
@dave1707 - very impressive but it slightly misses the point. You have stretched one icon over the full size of the texture. In a large terrain Iwould like to fill a texture with multiple small images. Whilst trying to generate that I came across a real oddity - explain this:
Note my iPad has a lot of memory.
@Bri_G this is an infinite scrolling sprite canvas modulated by noise. Turn on
DebugDraw
to see the clipping window version@Bri_G Here’s another version. I didn’t try to solve every issue with this, but just to give an idea. It starts out with 1 terrain area, but it creates a random new area as you fly over a blank area. The more you fly the larger your terrain gets. Still not sure if this helps any, but was interesting to write.
@Simeon - thanks for that neat demo, surprising how little code it took to achieve that. Few things I can apply that to, keep me busy for a while. Thanks again.
@dave1707 - that’s really neat, never seen that done before, it has given me a few ideas. Could be a problem if it keeps on expanding - how easy would it be to duplicate the one you are about to leave beyond the one you are about to move into? That way you could have infinite terrain in just a few graphic areas.
@Bri_G That’s what I was doing in a previous version. I was keeping the eight grids around me and deleting the terrain that I didn’t need anymore. But I figured it was better to keep everything. I’m not sure how many grids can be created before the fps starts to drop.
@Simeon - just noted a peculiarity in your scrolling demo. When I run the demo and scroll, say right to left, there is a flickering on with the new tiles being added on the right. Replace Standard mode with Overlay and the flickering disappears. The Overlay mode is drawing more of the tiled surface but appears faster. Is there an issue with calculations in the Standard mode eliminating the tiles below the parameter window?
@Bri_G odd, I don't see any flickering in STANDARD or FULLSCREEN modes. They are supposed to go all the way to the edges of the screen (you shouldn't be able to see the tiles appear and disappear unless "DebugDraw" is on).
It could be my iPad screen size (Pro 11") is more neatly divisible by the tileSize.
Try changing line 27 to this:
Edit: Or try +2 if that's not enough
@Simeon - bingo, got that in one. The modification made that smooth. Is there any advantage in changing the size of the parameter window?
Size of the parameter window? As in whether Codea is in Fullscreen or Standard size?
@Bri_G Here’s the other scroll I had. It’s set for a 3x3 grid terrain. It creates new terrain in front of you and deletes the terrain behind you to keep you in the middle. It can be changed to 5x5 or 7x7, etc. Because I’m scrolling fast, you can see a slight delay as new terrain is created and the old terrain deleted. If you move at a slower speed, it might not be as noticeable. You can also change the size of each grid. I guess this can be considered an infinite terrain.
PS. This eventually crashes, but I don’t know if it me or a problem with Codea not releasing memory.
@Simeon - forget my last note the issue I was discussing was due, as you pointed out, to the matching of integral tile sizes and will vary from tile size to tile size.
I always set up in Overlay mode as then you only have two possible set-up orientations to deal with. Which just made me think - in the past someone mentioned setting up their own template - is this still possible? And, if so how?
Also, you might consider letting people build their own templates, which would all list below the naming field for new projects, so that you can select it when starting a new project. I think this has been suggested before.
@dave1707 I’m so going to see if I can reproduce this crash with your new project
@dave1707 - just ran your new terrain demo, really smooth - going to see if I can play a few tunes around that. Oh, ran it 20 times for few minutes and stopped it without crashing. Probably memory, which of your machines are you seeing it on and is it consistent across them?
@Bri_G I’m using a 16gb iPad Air and that’s what I see all the crashes on. I have a 128gb iPad Pro, but I rarely use it. When I try those programs on it, it doesnt crash. Maybe I just don’t wait long enough.