Skip to main content
June 14, 2013
Answered

Store a Movie Clips x and y coordinates for use in a further frame.

  • June 14, 2013
  • 1 reply
  • 896 views

Hey, i'm making a turn based game where when your character hits an object it takes you to a battle scene. Once the battle is over you return to the previous frame with the character in the same spot it was when it hit the object, but the object isn't there anymore. I'm able to make it so the object isn't there anymore, but my character goes back to the beggining position of the game instead of where it hit the object.

Here is what I have on the character.

onClipEvent (load) {

          speed = 5;

}

onClipEvent (enterFrame) {

                    this._x = _root.xa;

                    this._y = _root.ya;

          }

xa and ya are 2 dynamic texts i have off the stage that just hold the numbers.

The code in the frame is:

stop();

xa = _root.xa;

ya = _root.ya;

And the code I have in the battle frame is the same.

I know that this shouldn't work, but i'm not sure what I could do to make it work. Any suggestions?

This topic has been closed for replies.
Correct answer kglad

Okay thanks. Do you think you could give me an example of what the code should look like if I were to assign instance names to my objects instead of attatching code to the objects?


mc.speed=5;

mc._x=xa;

mc._y=ya;

and there should be one enterframe loop in which everything on-stage is updated.  in that loop,

mc._x+=?

mc._y+=?

if(mc.hitTest(?)){

mc.prevX=mc._x;

mc.prevY=mc._y;

delete this.onEnterFrame;

// do whatever with the battle and when that's done, restart this loop. after updating mc._x=mc.prevX,mc._y=mc.prevY

}

1 reply

kglad
Community Expert
Community Expert
June 14, 2013

in your hittest, store the movieclip's position as properties (eg, prevX and prevY).

June 14, 2013

Okay, do you know how I would go about doing that? haha

kglad
Community Expert
Community Expert
June 14, 2013

it depends on your hittest code but, from the looks of your message 1 code, you'll probably use something like the following:

this.prevX=this._x;

this.prevY=this._y;

just before the battle scene and then use:

this._x=this.prevX;

this._y=this.prevY;

after returning from the battle scene.

p.s. you should NOT attach code to objects.  you should assign instance names to your objects and attach code to frames using those names.