[Solved]Move spawned items along with scrolling background

Get help using Construct 2

Post » Thu Dec 10, 2015 9:13 am

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.
Last edited by Solomon on Thu Dec 10, 2015 10:39 am, edited 1 time in total.
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Thu Dec 10, 2015 9:22 am

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
B
45
S
13
G
2
Posts: 173
Reputation: 5,331

Post » Thu Dec 10, 2015 9:41 am

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.
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Thu Dec 10, 2015 10:33 am

Ok great it worked without the custom movement behavior thanks!
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Thu Dec 10, 2015 10:48 am

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.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
292
S
115
G
96
Posts: 7,295
Reputation: 70,795


Return to How do I....?

Who is online

Users browsing this forum: Artcadev, brunopalermo, Jackriduk and 28 guests