It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Flash Forum

Help with code

Moderator: Phate

Help with code

Postby mrmmrm on Fri Mar 09, 2007 7:52 am

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;

}
mrmmrm
 
Posts: 2
Joined: Fri Mar 09, 2007 7:49 am

Postby flabbyrabbit on Fri Mar 09, 2007 2:01 pm

Well to start with,

Code: Select all
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: Select all
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
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England

Postby mrmmrm on Fri Mar 09, 2007 10:37 pm

Thank you so much for your help, your explanation was really clear, even for a beginner like me.

Cheers
mrmmrm
 
Posts: 2
Joined: Fri Mar 09, 2007 7:49 am


Who is online

Users browsing this forum: No registered users and 0 guests