Back to basics: movement <RESOLVED>

0 favourites
  • 6 posts
From the Asset Store
Helping streamers give their viewers more excitement.
  • Dear all,

    I'm very new to C2 and am trying to ignore habits and methods I've picked up elsewhere.

    To help with this, I like to strip things down and understand how they work. So, while I appreciate adding a behavior is the simplest way to create 8-way or platformer movement, I'd simply like to know what steps are required to make my object move left and right when I press the appropriate arrow keys.

    So, I have a ball object on the layout screen, but I can't find the relevant events that equate to:

    <font color=blue>IF RIGHTARROW KEY IS PRESSED, MOVE BALL OBJECT 4 PIXELS ON X AXIS</font>

    I have searched the forums, but maybe I'm using the wrong search criteria.

    Any pointers much appreciated.

    Noob.

  • What you want is to get its current x, which in expression form is sprite.x.

    Then the simplest way to move it would be to use the action set x.

    So if you were to set its x(sprite.x) to sprite.x+1, it would move the sprite 1 pixel to the right.

    Your condition should be pretty obvious once you add the keyboard object.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If you're not up to using expressions yet the same result can be achieved without them. I tested both methods and there doesn't seem to be any difference in the sprite movement.

    Keyboard/On Right arrow pressed/Sprite/Move at angle/4 pixels at angle 0

    Keyboard/On Left arrow pressed/Sprite/Move at angle/4 pixels at angle 180

    If you use large distances though, the jump rather than fluid movement of a behaviour will be more noticeable.

  • Thank you, both.

    Even though I knew it from the newbie tutorials, I neglected to put a KEYBOARD object on my layout ...so how the darn was I supposed to check for key input? Can't see the wood for the trees, me.

    SET X TO ball.x+4       ...is my new best friend.

    Journey of a thousand miles starts with ...4 pixels in my case.

    Again, thank you.

  • It is very dangerous to use Set X to X + 4.

    Instead, use Set X to X + 240 * dt.

    This 240 * dt replaces the 4 and allows your game to use framerate independence. This is also essential if you ever need to pause your game.

    Click here for a nice tutorial on it.

  • It's not "very dangerous"... Frame rate independence is not always wanted/required, and you don't ALWAYS want things to be affected by time-delta. It's also not essential to pausing a game. I think for the time being he should just focus learning the basics of events and ignore the complicated aspects like time/frame based logic.

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