Infinite scrolling all directions

For questions about using Classic.

Post » Thu Jul 23, 2009 12:02 am

Hey,

I have this idea for a space game but when I actually sit down to write it in Construct I'm drawing a big blank. I've read lots of info on scrolling and have gone through most examples of .caps on the board that scrolled. Here is what I'm trying to do:

I'm trying to make a game similar to an old space game called Solarwinds. The game would always show your X and Y coordinates. You would get missions like "Go to the planet at 500,500" or go talk to the ship at "10000,10000". I need to be able to create objects (planets, aliens, star bases, etc) at certain points. I also need to be able to give the impression that the world is much bigger than a 2000 x 2000 grid.

So some options are to keep the player in the middle of the screen and just scroll the starfield background. However, then the X and Y coordinates wouldn't be updated. To solve that I could increment a "fake" X and Y in global variables, but then how to solve placing objects on the screen at X and Y coordinates. I think collisions and other actions based on X and Y would be a nightmare as well??

I think the option of actually moving the player are a no go because of the size layout....you would eventually run into the end of the layout.

I'm starting to think this infinite scrolling is a bad idea and I should just implement jumpgates or something like that instead. Of course, even with jumpgates I still can't be having the player fly to the "edge of space" all the time. So I guess I still need some way to have infinite scroll even in that case!!

I'd appreciate any ideas!
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Thu Jul 23, 2009 12:12 am

Enable unbounded scrolling and you can scroll anywhere!
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Thu Jul 23, 2009 12:31 am

[quote="Ashley":1zvearw7]Enable unbounded scrolling and you can scroll anywhere![/quote:1zvearw7]

If you do this then you will have to place all of your planets, space stations, etc. at runtime (using events to set the X and Y of the objects) rather than placing them in the layout. A bit of extra work, but probably the best solution.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Thu Jul 23, 2009 1:07 am

placing tiny objects in a monster layout isn't very comfortable anyway.
You could place objects using an editor (made by yourself) that creates a text file with the data.
Or, you could generate positions randomly.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Thu Jul 23, 2009 3:19 am

>>>Enable unbounded scrolling and you can scroll anywhere!
>>>If you do this then you will have to place all of your planets, space stations, etc. at runtime

I can't believe I gave up on this before. I tried the unlimited scrolling a day or so ago, but once the ship got off the tilebackground of the starfield, then it looked weird because it was all black. I didn't even think of dynamically generating more starfield. I still think I may not be doing it the best way possible. What I do is check if the ship object is not within a certain distance of overlapping the starfield, and if so I create a new starfield. This ends up overlapping the old starfield. To help deal with this I destroy the starfield when it leaves the screen. I'm getting some choppy behavior sometimes.


Here is the .cap. [url:3ec7koig]http://www.mediafire.com/file/3zy1jym2n2r/unlimited_scrolling2.cap[/url:3ec7koig]

I'm using car behavior, because physics behavior still has 20000 limit. Still I think this might just work out. I'll have to look into making an editor, haven't tried to before.
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Thu Jul 23, 2009 7:29 am

For the stars, why not just put them on a separate layer that doesn't scroll?

You can use a Tiled Background object for your star field (or a few if you want parallax), and simply set their offset, in effect scrolling the inside of the tile without actually moving it. Of course, the textures will have to be power-of-two in order to use the offset feature.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Thu Jul 23, 2009 8:28 am

if you really need physics you could bound the world to the required size, clamping or wrapping as necesary.

If that world is too small, you could use layout zoom and resize everything to a smaller size, thus making the world appear larger (although numerically it won't).

If that's STILL too small, you could generate stuff in grids and spawn them when needed, moving stuff around when boundaries are reached to keep numerical weirdness in check. This would give you a universe the size of your grid size times the maximum grid index, which could go up to 2^32. Very large.

You should also take special care of the physics behavior, it might not like being repositioned (I gotta try that btw).
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Thu Jul 23, 2009 9:00 am

Have several layers of background.
- bottom, fixed background - usually features that don't ever move as you do, a significant space feature such as galactic core, distant galaxies etc.)
- middle, "slow" layers - scroll slower than the main display - usually large features such as nebulae, dust clouds etc.
- top, "fast" layer - immediate surroundings scroll fast, typically planets and stuff
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Fri Jul 24, 2009 3:32 am

Ok, I'm sure there is an easy answer but it eludes me...

I decided to go with car behavior for now, I kinda like the controls even though its not "true" space.

I'm dynamically placing objects (like an enemy ship). However, to actually create the object I have to place it somewhere during creation time. The common thing to do (shown in tutorials) is to place it off the layout, but this doesn't help in my case because the ship travels off the layout as well. How to create a sprite and NOT put in statically on the layout during creation time??

A more complex problem. When the player flys over a planet they may have an option to "land" on that planet. This causes the player to move to another layout just for that planet. However, when the player decides to "takeoff" and return to the space layout, everything is back to the way it was during game start. Is there a way to keep state between layouts? So the player's ship will be over the planet when you return to the layout?
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Fri Jul 24, 2009 6:05 am

[quote="scidave":3113gjn5]Ok, I'm sure there is an easy answer but it eludes me...
I'm dynamically placing objects (like an enemy ship). However, to actually create the object I have to place it somewhere during creation time. The common thing to do (shown in tutorials) is to place it off the layout, but this doesn't help in my case because the ship travels off the layout as well. How to create a sprite and NOT put in statically on the layout during creation time??
[/quote:3113gjn5]

I have wondered this myself. It seems very peculiar that we have to actually place the object (for example a sprite) somewhere on the layout (even if off to the side) to use it.
B
2
G
3
Posts: 68
Reputation: 986

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests