Hi,
This will be an easy one for you experts out there. I just want to have a ball randomly float through the movie & realize when it hits the wall of the movie & change directions. The moving part is no problem. I just need the logic for when the ball encounters the wall. Any help would be greatly appreciated,
let’s say your movie is 400x400 and the ball is 20x20…
onClipEvent(load){
nXmov=(Math.random()9)-4;
nYmov=(Math.random()9)-4;
}
onClipEvent(enterFrame){
if(_x<10){
_x=10;
nXmov=-1;
} else if (_x>390){
_x=390;
nXmov=-1;
}
if(_y<10){
_y=10;
nYmov*=-1;
} else if (_y>390){
_y=390;
nYmov*=-1;
}
_x+=nXmov;
_y+=nYmov;
}
Ok, the code below works great & I think I understand it. I’m new to the game so bear with me. Anyone want to take a crack @ commenting this for me. Please don’t be afraid to over explain. Thanks again. It’s much appreciated,
Tim
let’s say your movie is 400x400 and the ball is 20x20…
onClipEvent(load){
nXmov=(Math.random()9)-4;
nYmov=(Math.random()9)-4;
}
onClipEvent(enterFrame){
if(_x<10){
_x=10;
nXmov=-1;
} else if (_x>390){
_x=390;
nXmov=-1;
}
if(_y<10){
_y=10;
nYmov*=-1;
} else if (_y>390){
_y=390;
nYmov*=-1;
}
_x+=nXmov;
_y+=nYmov;
}
onClipEvent(load){
// set the speed for this movie clip.
nXmov=(Math.random()9)-4;
nYmov=(Math.random()9)-4;
}
onClipEvent(enterFrame){
if(_x<10){
// if this clip is ‘out of bounds’ on the _x axis place it ‘in bounds’ and reverse it’s direction on the _x axis.
_x=10;
nXmov=-1;
} else if (_x>390){
_x=390;
nXmov=-1;
}
if(_y<10){
// if this clip is ‘out of bounds’ on the _y axis place it ‘in bounds’ and reverse it’s direction on the _y axis.
_y=10;
nYmov*=-1;
} else if (_y>390){
_y=390;
nYmov*=-1;
}
// move this clip.
_x+=nXmov;
_y+=nYmov;
}
ha! I don’t think you ever really started out slow with Flash. I think you were born (or produced rather) with the Macromedia symbol printed across your forehead. j/k…true…everyone has to start somewhere…