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

0 favourites
  • 2 posts
From the Asset Store
SCI-FI Units SFX contains 456 sounds With this pack, you can voice almost all the units in your sci-fi strategy game
  • 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!

  • Try Construct 3

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

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

    Sprite: set X to: 600-(LayoutWidth-Sprite.X)[/code:1du7vroh]
    That's it, basically.
    
    What happens here?
    [i]LayoutWidth-Sprite.X[/i] 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 [i]WindowWidth[/i] instead.
    
    I hope I could help. :)
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)