Back to basics: movement <RESOLVED>

Get help using Construct 2

Post » Fri Nov 11, 2011 7:39 am

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:

IF RIGHTARROW KEY IS PRESSED, MOVE BALL OBJECT 4 PIXELS ON X AXIS

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

Any pointers much appreciated.

Noob.utternoob2011-11-11 17:58:56
B
5
G
2
Posts: 17
Reputation: 1,266

Post » Fri Nov 11, 2011 8:02 am

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.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Fri Nov 11, 2011 9:06 am

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.
B
4
G
3
Posts: 41
Reputation: 982

Post » Fri Nov 11, 2011 5:57 pm

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.
B
5
G
2
Posts: 17
Reputation: 1,266

Post » Sat Nov 12, 2011 4:04 am

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.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Sat Nov 12, 2011 4:55 am

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.
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620


Return to How do I....?

Who is online

Users browsing this forum: TELLES0808 and 18 guests