How do I move a sprite X units to the right?

Just started using Construct 2? Post your questions here

Post » Sat Oct 08, 2016 8:13 pm

Hi, how can I make an sprite move exactly 600 units to the right using behaviors MoveTo or Custom Movement?
I can't use 'Go to position (x+600,y)', because I need the sprite to get out of the layout so it wraps horizontally.
Thanks!
B
3
Posts: 1
Reputation: 177

Post » Sat Oct 08, 2016 10:29 pm

Let's make this a bit easier: instead of using Custom Movement or MoveTo, you can just calculate the position the Sprite needs to go since you know the width of the Layout.

This just works if I understood you correctly and you want to push the Sprite 600 pixels to the right to make it appear again on the left.

So, the action you need is the following:
Code: Select all
Sprite: set X to: 600-(LayoutWidth-Sprite.X)

That's it, basically.

What happens here?
LayoutWidth-Sprite.X calculates the x distance needed to move the current Sprite.X to the edge of the Layout.
When that gets substracted from 600, you get the distance from the left edge of the layout (x=0) to the wanted x position.

This works for your layout scale. If your layout is bigger than what is displayed, you can use WindowWidth instead.

I hope I could help. :)
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 2 guests

cron