Flash Games
 FAQ   Search   Memberlist   Usergroups   Register  Profile   Log in to check your private messages   Log in 


Help with code



 

Post new topic   Reply to topic  
   DEVPPL Forum Index -> Flash Forum
View previous topic :: View next topic  
Author Message
mrmmrm



Joined: 09 Mar 2007
Posts: 2

PostPosted: Fri Mar 09, 2007 8:52 am    Post subject: Help with code Reply with quote

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
View user's profile Send private message
flabbyrabbit
500+ Club


Joined: 25 Jan 2007
Posts: 567
Location: UK

PostPosted: Fri Mar 09, 2007 3:01 pm    Post subject: Re: Help with code Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
mrmmrm



Joined: 09 Mar 2007
Posts: 2

PostPosted: Fri Mar 09, 2007 11:37 pm    Post subject: Re: Help with code Reply with quote

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

Cheers
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    DEVPPL Forum Index -> Flash Forum All times are GMT + 1 Hour
Page 1 of 1

 
 
Welcome to DEVPPL.com
You are not logged in, which means that you can't post in the forums.
Click here to Register

If you are a current member here on DEVPPL, please login below:

User: Pass:
Log me on automatically each visit:

 


Powered by phpBB © 2001, 2005 phpBB Group - Modified by DEVPPL

Flash Games - Sitemap