View Full Version : still need help putting things in random places
pyroki
July 13th, 2005, 09:04 PM
k for a long time ive been tryin to make powerups and now i finally got it workin except when i assign the powerup's x coordinate to the math.random function it goes all over the stage how do i get it to only randomize once so it just chooses a random x coordinate and stays at that one i also need to use this for choosin wut powerup to come down like if the random number is from 1-25 for this powerup ect. can sum1 help me?
Templarian
July 13th, 2005, 09:38 PM
can we see the code you are using or a sample .fla.
Skribble
July 13th, 2005, 09:43 PM
youve probably got it on an Enterframe handler. Like templarian said, you will need to see your code to help you out better.
pyroki
July 13th, 2005, 10:19 PM
k here is the code i hav for my powerups it is in a movieclip
onClipEvent(load) {
//set text boxes to zero
_root.powerup1 = 0;
_root.powerup2 = 0;
//depth variable
pnum = 0;
//timer for powerups
timer = 200;
}
onClipEvent(enterFrame) {
timer--;
//if timer is at zero
if(timer == 0) {
timer = 200;
newpowerup = _root.attachMovie("power", "helper"+pnum, pnum++)
}
//powerup hitest
if(_root.hero.hitTest(helper)) {
_root.helper.removeMovieClip()
_root.powerup1++;
}
}
//switch weapons
onClipEvent(keyUp) {
if(Key.getCode()==Key.SPACE) {
nextFrame();
}
}
Templarian
July 13th, 2005, 10:27 PM
Just on the Powerups being created put.
onClipEvent(load){_x = Math.Random()*100;_y = Math.Random()*100;}
pyroki
July 14th, 2005, 01:40 AM
thx templarian i get wut ur saying but this isn't on the powerup movieclip this is on like the movieclip that holds information for the powerups so how should i code it plus the powerup movieclip isn't on the screen so i wud hav to code it for the frame so shud i say sumtin like onLoad = function
NiñoScript
July 14th, 2005, 03:05 PM
after saying this:
newpowerup = _root.attachMovie("power", "helper"+pnum, pnum++)
just say this:
_root["helper"+pnum].onLoad = function (){
this._x=randomNumber();
this._y=randomNumber();
}
//i used randomNumber();, becouse i suppose i have a function that returns the random number, if you dont have one, and you dont want one, just put the Math.random()*num or random(num) stuff ;)
pyroki
July 15th, 2005, 12:41 AM
thx nino but all that happens now is it comes in at the point 0,0
pyroki
July 15th, 2005, 09:14 PM
wut is wrong with this code for sum reason when it says onLoad = function the movieclip im sending this to isn't executing this plz help me
onClipEvent(load) {
//set text boxes to zero
_root.powerup1 = 0;
_root.powerup2 = 0;
//depth variable
pnum = 0;
//timer for powerups
timer = 20;
}
onClipEvent(enterFrame) {
timer--;
//if timer is at zero
if(timer == 0) {
timer = 20;
newpowerup = _root.attachMovie("power", "helper"+pnum, pnum++)
_root.helper.onLoad = function() {
this._x = Math.random()*400;
}
}
//powerup hitest
if(_root.hero.hitTest(helper)) {
_root.helper.removeMovieClip()
_root.powerup1++;
}
}
//switch weapons
onClipEvent(keyUp) {
if(Key.getCode()==Key.SPACE) {
nextFrame();
}
}
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.