[Solved]Move spawned items along with scrolling background

0 favourites
  • 5 posts
From the Asset Store
All popular touch mechanics - scrolling, zooming, swiping
  • I have been thinking about this for about a week now. This actually made me take a brake from Construct but now I'm back at it again and still cant figure it out.

    I have a scrolling background, which is basically set that if I move around it scrolls along with the movement. I can go faster and slower. So the player sprite is standing still only the background is moving.

    Now I would like the randomly spawned items to move in relation to the background and to their position and still have their own movement. So if and sprite/item is moving let us say 10 pixels, when I scroll the background forward it moves less, and I can catch up to it, and when I move back it moves faster, as the combination of my speed is added to its speed. When I - the background is still, the item moves at its own speed only.

    I am getting nowhere with this, I know I have set the bar high for myself, any nudge in the right direction would be greatly appreciated by me.

    In using the custom movement behavior on the background as well as on the spawning sprites/items. I tried pinning them and then also giving them some speed but it doesn't seem that the 2 behaviors work together.

    Thanks.

  • I think you need to manually set X or set Y to the items

    so, I assume that usually the item moves like this

    every 0.5 second | item Set x item.x + item.moveSpeed

    so when you move closer to the item, you'll reduce the item.moveSpeed

    and if you move away from the item, you'll add the item.moveSpeed

    I don't know if it works, haven't tried it, but I think it's a good start

  • Thanks for the response. Does that mean I need to get rid of the custom movement behaviour? And why every 0.5 seconds not every tick?

    Edit: Eh I read it again, yep I see spawning an item every 0.5 seconds in positon of X.

    The problem is that with the custom movement I managed to do so, but when I speed up the item speeds up when I slow down the item slows down.

    There is no difference if I add negative value it still doesnt change.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ok great it worked without the custom movement behavior thanks!

  • You need to use delta time in your game.

    So Daggio's proposal is not completely true/safe.

    Here is a capx made in r218 using only events (and relying on the timer behavior for some aspects).

    The scrolling is horizontal (since you did not give precisions in your first post).

    Objects "Other" are spawned every 5 seconds, given a -25 speed that makes them move from the right to the left towards the "Main" object.

    Using the up and down arrows make the Main object move up and down, limited by the "Bound to layout" behavior.

    Using the right and left arrows change the "ModSpeed" variable value which is used to set the "Speed" of the background scrolling as well as the "speed" of the "Other" objects.

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