ForumsProgramming ForumMoving Objects with Keyboard

3 3674
stuhay06
offline
stuhay06
3 posts
Nomad

Ive used this code for moving my object using the directional buttons. But when i testl instead of going back the way it came if eg. travelling left and turn to go right, the object will change direction but also jump up on down the lenght of the object. heres the code:

onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
_y -= 10; _rotation = 270; }}

onClipEvent (enterFrame) {
if (Key.isDown(Key.DOWN)) {
_y -= -10; _rotation = 90; }}

onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_x -= 10; _rotation = 180; }}

onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
_x -= -10; _rotation = 0; }}

any problems here? I thought it could be something to do with the register point, but i cant found out how to move it to check.

  • 3 Replies
PixelSmash
offline
PixelSmash
566 posts
Nomad

Sounds like you've got your pivot point at the wrong place... which means that when you change the rotation from 0 to 180, it will also seemingly displace for it's full length.

Simple solution: place the pivot at the center of the object.
Hard solution: check if the rotation is not what it should be (eg. it's 0 when it should be 180) and if that is so, add an extra amount equal to the object's width.

stuhay06
offline
stuhay06
3 posts
Nomad

yay!! fixed it

Turns out it was the pivot point/register point, whatever you want to call it.

Didnt know how to move it so just deleted my object and redrew it now it works fine. Cheers PixelSmash.

PixelSmash
offline
PixelSmash
566 posts
Nomad

No problem! I found out the hard way that this can cause a lot of headache... glad you worked it out!

Showing 1-3 of 3