How can i make it so a cloned element comes back if it leaves the screen?
ok i have a cloned element in my star wars game called "fighter" as in the tie fighters. I have them moving and if you dont shoot them they leave the screen. How can i have it so that if they leave the screen, that they come back for you to try to shoot them again?
The simplest things to use are the methods for boundary handling in 3DFA specifically (this is from right from help under element methods):
.boundaryBounce () element will bounce off the sides of the screen
.boundaryJump () element will jump to the opposite side of the screen
.boundaryHide () element will be hidden when it travels off the screen
I have included an example, if you are unsure on how to use these, of the jump method which sounds like what you are looking for.
ok thanks for the file, but in my game there is more than one fighter because it is cloned. The script i used to clone my element "fighter" is different than yours. it is:
f = element ("fighter")
fighter= new Array(num_fighter);
for (i=0;i<num_fighter;i++) {
fighter[i] = f.clone();
fighter[i].x = 399+random(79);
fighter[i].y = 60+random(250);
fighter[i].acceleration.x = -(50);
}
}
so how can i make it so that if the CLONED fighters leave the screen the CLONED fighters appear at the other side?
Those methods don't work with clones obviously, there is a sample under simple that demonstrates how to do this. But it makes them bounce, take a look at it but what you want is to reappear. It is similar
PHP Code:
for (i=0;i<fighter.length;i++) {
if (fighter[i].x>400){//assumes movie is 400 wide
fighter[i].x=0//better to use the width of fighter
}
}
of course you may need to check for x<0 and perhaps y as well but you get the idea I hope.
Put this in a script element that runs every frame
ok thanks, but line four cant be resolved. My original starting place is at x = 675, so i entered that in but it still cant be resolved. What am i doing wrong?
thanks
ok thanks, but line four cant be resolved. My original starting place is at x = 675, so i entered that in but it still cant be resolved. What am i doing wrong?
thanks
Check you code closely I just cut and pasted the above and just added
fighter=new Array() in the start script and it work fine without error
ok i tried changing a few things but then screwd up some other things so i took out the script. This is what i had though,
for (i=0;i<fighter.length;i++) {
if (fighter[i].x>0
fighter[i].x=600
}
}
i thought the script would make it so that once my fighter reached the left hand side of the movie (x=0) that it would go back to the right hand side of the movie (x=600).
i will add my file, though im no where near done with the game maybe u can still help me finish this script im having trouble with. I erased the scrip, but maybe u can help me with what i should put,
I know you have something that works from blanius but I wanted to show how it could be done using the 3DFA methods mentioned above. (At worst case you'll have more than 1 way to do the same thing).
I just modified the for loop, from the original download, "Script 35" element to do a .boundaryJump() for each of the clones.