Continuous scrolling background from parts?

Get help using Construct 2

Post » Thu Jan 12, 2012 9:40 pm

I'm making a sidescroller with a background that is continuously moving behind the ship. This background will be made of several types of interchangable "blocks" of scenery. And of course I'd be scrolling these blocks backwards in the opposite direction of the ship to give the appearance of movement. I'm trying to use 2 sprites for this; when sprite A starts to move off the screen sprite B will move ahead of it, when B starts to move off, A moves back ahead, so with only two sprites that can have their image changed, I can have a level essentially go on forever. Can anyone who has done this keep me some pointers on how to go about this? I've done it with code before, but never in Construct. Thanks!
B
7
S
2
G
4
Posts: 5
Reputation: 2,676

Post » Thu Jan 12, 2012 9:49 pm

The logic looks kind of like this in construct.. This is sloppy, sorry...

Place Blocks in separate layer

When movement key pressed
->move block Block.x - (whatever px value)

Is Bock on screen? (Inverted) //Is Block off of screen
->Delete block
->create new block at spawn point at right of screen // using a spawn sprite, or telling it exactly where to spawn at position...Zetar2012-01-12 21:50:06
B
192
S
6
G
7
Posts: 213
Reputation: 10,178

Post » Thu Jan 12, 2012 11:09 pm

I would put the origin at top left of the background sprite.
Put your two background in two animation frame of the same sprite
set the speed of the animation to 0
And then
[code]
Global Variable offsetX = 0 //Offset for the next background
Global Variable before = 0 //before or not (for picking)
+Player:is Overlapping Background
-> System: set offset = Background.X+Background.Width
-> System: set before = 0
+Background: X<Player.X+Background.Width/2
    -> System: set offset = Background.X
    -> System: set before = 1
+Player:[invert] is Overlaping Background
+System: before = 1
    ->System: substract Background.width from offset
->System: set X to Offset[/code]

If you overlap two background at the same times, this code will become a bit wonky, but as the result only apply to the background you don't overlap, there shouldn't be any visible issue... To try :DYann2012-01-12 23:09:57
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Jan 13, 2012 2:17 am

Well, I can't really use one sprite type because I may have different properties. See, the type of game is a spy hunter type game, so the big tiles are different types of roads, such as narrow 1 lane and 2 lane stretches of highway. These different road types would also, of course, have different collision polygons so I know when the player has gone off the road. So how to I generically refer to these sprites when they may be different object types?
B
7
S
2
G
4
Posts: 5
Reputation: 2,676

Post » Fri Jan 13, 2012 4:58 am

You can use one sprite and have many different animations for that sprite object (each with its own sprite image) set at 0 speed. Each Animation Sprite can be different sizes, and have different collision polygons. I do it all the time. The drawback (not really for me) is that you must have every variable for all the sprites in the one main sprite holding all the animations. I would set those like this:

Road Sprite Variables: (use your own naming convention)
road_type
road_onoff
switch_A   // and so on.

When spawning the SPRITE OBJECT, you set the animation # or name for that object. On the layout screen you see only the first animation Frame/sprite, but if you set them all to different animations you get the right picture when you run it... :)

I hope that makes sense.
Zetar2012-01-13 05:00:47
B
192
S
6
G
7
Posts: 213
Reputation: 10,178

Post » Fri Jan 13, 2012 12:32 pm

Yeah usually it's better to group things to avoid code copy/pasting. And grouping things under the same objecttype is a workaround while we wait for families.
But in most cases, even if families were available, I would still use the same sprite. Because to me it's the same concept "background" and it makes capx cleaner.
An you can have one collision polygon per frame.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sat Jan 14, 2012 5:57 pm

Thanks, I got it!
B
7
S
2
G
4
Posts: 5
Reputation: 2,676

Post » Sat Mar 17, 2012 2:47 am

I wanted to know how I might be able to turn this into an auto scrolling idea, where the player character sits still and the background just scrolls behind, picking from random backgrounds.

Also a bit of the discussion is a little hard to parse, I'm not a programmer by any means.

Any help would be great, thanks!skizomaniak2012-03-17 02:47:23
B
3
Posts: 1
Reputation: 284

Post » Wed Nov 28, 2012 12:26 pm

Me too! I'm trying to get a sprite to do parallax scrolling, rather than making animation of the sprite scrolling in every frame. If there is an event of parallax scrolling for Tiled Background, I can let it scroll in any angle I want and I could even change the speed of the scrolling. Can anyone help?
B
25
S
6
G
4
Posts: 76
Reputation: 5,163


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 23 guests