RainGame
09-23-2007, 11:51 PM
To start off getting the feel for AS3, I wanted to make a simple gravity simulator. It would have one ball on the stage bounce around and off the walls. I followed a tutorial on how to do this in AS2 years ago (included concepts of gravity, hitTests on the walls, etc.).
Because of AS3's new structure and all, I figured the best idea would be to make a Ball class. The class would keep track of where the ball is on the stage, its current speeds, color, etc. That way I could add more balls easily, and change each of thier values seperately.
I have followed along with a few different tutorials on making my own Visual Class, and I understand them perfectly and assume they would work fine if I were to complete them. But I have one problem. These custom visual class tutorials only deal will simple shapes, usually circles. And though my shape for my project is indeed a circle, I know in the future I will need to do this for advanced shapes.
These tutorials always draw the shape using code like this:
private function draw( ):void {
graphics.beginFill( _color );
graphics.drawCircle( 0, 0, _radius );
graphics.endFill( );
}
I'd like to store my shape inside my Ball class, but somehow get the graphic from my library. I don't know if it is possible or if it is the right way to do it, but i figure if I can store the graphic in my Ball Class, I can assign and alter the x and y positions of the graphic in the Ball Class as well. I do not want to deal with the x and y positions on my main timeline. Is there any way to do this? Thanks.
Because of AS3's new structure and all, I figured the best idea would be to make a Ball class. The class would keep track of where the ball is on the stage, its current speeds, color, etc. That way I could add more balls easily, and change each of thier values seperately.
I have followed along with a few different tutorials on making my own Visual Class, and I understand them perfectly and assume they would work fine if I were to complete them. But I have one problem. These custom visual class tutorials only deal will simple shapes, usually circles. And though my shape for my project is indeed a circle, I know in the future I will need to do this for advanced shapes.
These tutorials always draw the shape using code like this:
private function draw( ):void {
graphics.beginFill( _color );
graphics.drawCircle( 0, 0, _radius );
graphics.endFill( );
}
I'd like to store my shape inside my Ball class, but somehow get the graphic from my library. I don't know if it is possible or if it is the right way to do it, but i figure if I can store the graphic in my Ball Class, I can assign and alter the x and y positions of the graphic in the Ball Class as well. I do not want to deal with the x and y positions on my main timeline. Is there any way to do this? Thanks.