Quote:
Originally Posted by Elk
im guessing its just onPlayerEnters though :S
im trying to get it to be more specified for a defined x/y area, hence playerxy in xy
|
On UN it's also an X/Y box around the warp-in zone.
You want it to fade in when they enter the space and then fade out on its own, and then not re-fade in until they've EXITED the space and subsequently RE-ENTERED the space. Is that what you're saying?
In that case, you simply set a flag when they enter and unset it when they exit. If the flag is false, make it show the text. If it's true, don't show the text.
You'd still create the text under onCreated and initialize it with an alpha of 0. Then you'd simple do:
PHP Code:
function onTimeOut() {
checkArea();
setTimer(0.05);
}
function checkArea() {
if (/* player in area stuff */) {
if (!this.showed) { // If the image hasn't been displayed since their last entrance
this.showed = true; // Flag it as displayed
onFadeIn(); // Start fading in
}
} else {
if (this.showed) { // If it was displayed already
this.showed = false; // Unset it, since they're no longer inside
}
}
}
function onFadeIn() {
if (/* player in area stuff */) {
this.img.alpha += 0.05; // 0.05 is a placeholder, it will take num * 20 seconds to fully fade in, so @ 0.05 it will take 1 second
if (this.img.alpha < 1) { // If it isn't fully visible yet
scheduleEvent(0.05, temp.name, nil); // THIS 0.05 is not a placeholder, it is the tick rate of graal - this will "loop" the fade in
} else {
onPause(3); // '3' is up to you, it's how long it will appear to "hang," this creates the "pausing"
}
} else {
onFadeOut(); // If the player left the area, stop fading in and start fading out instead
}
}
function onPause(timeLeft) {
if (/* Player in area stuff */) {
if (timeLeft > 0) {
scheduleEvent(0.05, temp.name, timeLeft - 0.05); // Keep counting down if the player is inside and there's time left to pause.
} else {
onFadeOut(); // Once time runs out, fade out
}
} else {
onFadeOut(); // If player isn't still in area, pre-maturely fade out.
}
}
function onFadeOut() {
if (/* NOT player in area */) {
this.img.alpha -= 0.05; // Lower the alpha back down, remember: this 0.05 is a placeholder
if (this.img.alpha > 0) { // While it's not 0 yet
scheduleEvent(0.05, temp.name, nil); // Keep looping to decrease it
}
} // No need to put an else {} here to check if they re-enter the area. If they re-enter the area, this will fail and onFadeIn() will be called by checkArea()
}
I haven't tested it, but that's roughly what you're going for, assuming I handled your fringe cases correctly (ie, what you want to happen when the player rapidly enters/exits the area and such like that). There are other ways of doing it if you don't want it to prematurely begin fading out if they exit too soon (ie, you remove onPause() and just change it to a scheduleEvent(3, "fadeOut", nil) call). There are various ways of handling those fringe cases, but this seemed like the most aesthetically appealing at a glance.
EDIT: And if you only want it to happen once EVER then simply don't unset the flag (as I did via the line "this.showed = false;" inside checkArea()). In that scenario you probably don't want the text fading prematurely, even if they walk away from the area, and so you'd do my suggestion in the last paragraph (vis-a-vis removing onPause and changing it to scheduleEvent(3, "fadeOut", nil); )