Copy link to clipboard
Copied
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?
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
}
Copy link to clipboard
Copied
in your hittest, store the movieclip's position as properties (eg, prevX and prevY).
Copy link to clipboard
Copied
Okay, do you know how I would go about doing that? haha
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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
}
Copy link to clipboard
Copied
Alright awesome! Thanks i'll work on this.
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now