Warp objects on layout width and on x=0 (rotating space view 360°)

0 favourites
  • 4 posts
From the Asset Store
JPEG format 364x HD backgrounds in 2688 x 1536 Resolution
  • I'm trying to create a special level in my game where the spaceship travels in circles to a space station. (which appears to rotate as it is made up of 8 frames).

    The viewport view does not move.

    Only stars and nebulae move (family called axis).

    my idea was to make it so that when the nebulae and stars go out of the layout width they return to x=0.

    When their x value goes below 0 they go back to 3416. (the viewport size for x is 854).

    But obviously something is wrong.

    Probably I'm missing something that I should consider and so I ask you, maybe there is someone who immediately understands what is the problem.

    So how should I do it?

    I also leave a screenshot of the code I tried and a link to my google drive to download the c3p file (if needed).

    https://drive.google.com/file/d/1OybYrRKOcEAyl3wyJ0UvcNrvxDuSI0QT/view?usp=sharing

  • The easiest solution is to use TiledBackground for axis objects, set their width to 1000000 pixels and hope players won't reach the end :)

    Here is an example of infinitely scrolling bg:

    dropbox.com/scl/fi/pzwcxbqkpcbf2tova7pjt/InfiniteParallaxBG.capx

    Also, you need to use delta-time when you are moving objects, or they will move at different speeds on different framerates. Replace "Move 3 pixels" with "Move 180*dt pixels"

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • There is a wrap behavior that kind of does that. But it’s imprecise.

    You also do the wrapping with events and make it a bit better. Here for example the screen is 640 pixels wide. It’s the most basic example and you’ll see when the objects jump from one side to the other.

    Object: x<0
    — object set x to self.x+640
    Object: x>640
    — object set x to self.x-640

    You can solve that by making the position jump further off screen by some margin. A good rule of thumb would be a margin at least as wide as the widest object you’re wrapping around.

    Object: x<-margin
    — object set x to self.x+640+margin*2
    Object: x>640+margin
    — object set x to self.x-640-margin*2

    Now that’s is the scroll position is to the left of the layout. You could make it relative to the screen if you really need to.

    For doing it with a tiled background you’d just need to have the tiled background’s width to the imageWidth+screenWidth and the events would basically be:

    tiledbg: x<imagewidth
    — tiledbg set x to self.x+imagewidth
    tiledbg: x>0
    — tiledbg set x to self.x-imagewidth

    Now if you change the x by more than the imagewidth it will take more frames for it to catch up. Adding a while condition above the x compare conditions is a simple fix. There is probably a nice math way to correct it without a loop too

  • Object: x<-margin
    — object set x to self.x+640+margin*2
    Object: x>640+margin
    — object set x to self.x-640-margin*2

    Yes I had the same idea as in your example 2.

    that's the solution.

    It wasn't working because I was making another mistake.

    Now I've solved it.

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