# Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

### AppGameKit Classic Chat / Need help with moving and jumping my sprite

Message
Posted: 12th Sep 2011 19:50 Edited at: 12th Sep 2011 19:51
Hi Guys, I'm very new to programming and I have been working through Daniel TGC's video tutorial for scribble squash and it has helped me understand a lot about program flow, variables and other basic stuff.

I'm doing a few things myself just to see how I get on without help but because I'm very new to programming I have ran into a few things that I need help understanding, I'm not looking for someone to code things for me, just maybe give me an example or two to study or explain how I would go about doing this. I'm trying to move the ball with a joystick in my program (which I have attached to this post)

All I want it to do is move left, right and jump using the controls in the program.

Please understand that I might not have a clue what your talking about but I will be very greatful with any help you can give me as I'm totally lost and the help files don't really explain it that well for me.

#### Attachments

Posted: 12th Sep 2011 20:55
So, you're using physics. You've got a few different ways to move objects around.

1 - Gravity. Probably not a good choice, since gravity is what makes the ball fall down in the first place.

2 - World Force. Again, not a good choice if you just want to move the ball, and not the other objects.

3 - Set the velocity of the ball. Better, but still not the best. The ball will keep whatever velocity you assign it, minus gravity, friction, and damping.

4 - Add Force. This is probably the one you want to use. It gives a one-cycle push to the object. So, move your joystick right and give the ball some positive x force. Keep it to the right, more force is added. Let it return to center, the ball slows down due to gravity, friction, and damping. Move the joystick to the left to give the ball some negative x force. Move the joystick up to add some negative y force.

I'm at work, or I would post some code.

One thing about your main loop, it looks like you're setting many physics parameters every time the pointer is pressed. Most of those should only be set once, so some sort of flag or switch would be good, like

You have a good start, and I'll be interested to see what you do next!

Posted: 12th Sep 2011 23:15
Thanks Rich I understand what you mean by setting a flag in the main loop but when it comes to the add force way of moving the ball I honestly don't know where to start

I think I'll just have to do a bit of study and see what I can learn.

Thanks very much for the help.

Posted: 13th Sep 2011 16:37
Hi Rich, I have been trying to get the ball to move all day and all I can get it to do is move left and right using the setspriteposition command with the joystick.

If you get the time would you show me an example of how you would move it using the force method you were talking about.

I feel like I'm banging my head against a brick wall here trying to figure it out

Posted: 13th Sep 2011 17:22
Soulstealer - Sure, I'd be glad to help. I can't test code while I'm at work (no AppGameKit here ) but I can whip up something that might work.

I'll post it in a bit...

Posted: 13th Sep 2011 17:28
Thanks Rich I might be offline until tomorrow but I'll check it as soon as I can.

I'm looking forward to seeing how this is done

Posted: 13th Sep 2011 19:40 Edited at: 14th Sep 2011 04:59
Here's some code that creates a sort-of "Lunar Lander" type situation. Use the joystick to apply spurts of force to the lander (just a ball for this demo).

This code needs no media.

EDIT: Soulstealer, I took the basic idea a step further, here.

Posted: 14th Sep 2011 18:30
Wow thanks very much for the code Rich It really helped me understand how to move the ball using PhysicsForce

Now that I understand that I can progress onto setting up a level and trying to use scrolling.

Thanks again and I really like your Lunar Lander code, again it explains a lot of things.