Continuous scrolling background from parts?

0 favourites
  • 9 posts
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • 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!

  • 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...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

    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

    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 :D

  • 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?

  • 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.

  • 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.

  • Thanks, I got it!

  • 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!

  • 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?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)