| View previous topic :: View next topic |
| Author |
Message |
mrmmrm
Joined: 09 Mar 2007 Posts: 2
|
Posted: Fri Mar 09, 2007 8:52 am Post subject: Help with code |
|
|
can someone help with this code? what is doing exactly?
Thank you
onClipEvent(load){
speedX = -10;
speedY = -10;
stageWidth = Stage.width;
stageHeight = Stage.height;
}
onClipEvent(enterFrame){
_x+=speedX;
_y+=speedY;
if(_root.paddle.hitTest(this)){
speedX = Math.abs(speedX);
}
if(_y<_width/2){
speedY = Math.abs(speedY);
}
if(_y>(stageHeight-(_width/2))){
speedY = -10;
} |
|
| Back to top |
|
 |
|
|
flabbyrabbit 500+ Club

Joined: 25 Jan 2007 Posts: 564 Location: UK
|
Posted: Fri Mar 09, 2007 3:01 pm Post subject: Re: Help with code |
|
|
Well to start with,
| Code: |
onClipEvent(load){
speedX = -10;
speedY = -10;
stageWidth = Stage.width;
stageHeight = Stage.height;
}
|
This sets the different variables, the top two are how fast the thing will move. Then the next bit.
| Code: |
onClipEvent(enterFrame){
_x+=speedX;
_y+=speedY;
if(_root.paddle.hitTest(this)){
speedX = Math.abs(speedX);
}
if(_y<_width/2){
speedY = Math.abs(speedY);
}
if(_y>(stageHeight-(_width/2))){
speedY = -10;
} |
Moves the object until it hits a MC called paddle. It then does a calculation and changes the value either speedX or speedY depending on what it hits, this will then make the object fly of in a different direction. The last to IF statements say that if the object goes outside the area the direction will be changed so it goes back in again.
Is that what you wanted to know?
Flabby Rabbit |
|
| Back to top |
|
 |
mrmmrm
Joined: 09 Mar 2007 Posts: 2
|
Posted: Fri Mar 09, 2007 11:37 pm Post subject: Re: Help with code |
|
|
Thank you so much for your help, your explanation was really clear, even for a beginner like me.
Cheers |
|
| Back to top |
|
 |
|