Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Guest
Jun 13, 2013 Jun 13, 2013

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?

TOPICS
ActionScript
832
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 14, 2013 Jun 14, 2013

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

}

Translate
Community Expert ,
Jun 13, 2013 Jun 13, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 13, 2013 Jun 13, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 14, 2013 Jun 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 14, 2013 Jun 14, 2013

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 14, 2013 Jun 14, 2013

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

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 15, 2013 Jun 15, 2013

Alright awesome! Thanks i'll work on this.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 15, 2013 Jun 15, 2013
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines