Today, I read the flash engine official instructions.
Http://wiki.fisixengine.com/index.php? Title = yourfirstfisixapplication # the_physics_of_fisix
I will explain what it means. After all, I haven't fully figured out this little thing. (Poor English, O (English _ skills) O Haha ~)
I. Start with fisix:
The fisix engine is a very good physical system and is used in your daily engineering. This engine was created based on the WordPress 3.0.
When you implement this engine, you first create a fisixengine, then specify some gravity, resistance, and reflection surfaces. Then, you can create some objects in your application. Next, you can apply these forces to the objects to simulate a real physical effect. Before you start, you must first use your creativity and then use this physical engine.
2. My first fisx Program
Of course, the creation of this engine is very interesting, but the first thing you need to do is to configure this environment. We use flex builder to start our first program:
First
1. Open flex
2. Create a flash Project
3. Create a name such as myfisixdemo and select your project
This project has been created. You can write the following code, as it inherits the sprite class.
Package {<br/> Import flash. display. sprite; </P> <p> public class myfisixdemo extends sprite <br/> {<br/> Public Function myfisixdemo () <br/>{< br/>}< br/>
Next, we need to do some things.
1. Select this project property,
2. Select 'actionscript build path'
3. Select 'library path' for the switch label '"
4. Click 'add SWC... ImportFisx SWC
5. Select youLocation of the fisixengine. SWC File
For example:
After adding the SWC component, we can start to create our first application. First, introduce the required packages to the application.
Import COM. fileitup. fisixengine. collisions. reactionmodes; <br/> Import COM. fileitup. fisixengine. core. fisixengine; <br/> Import COM. fileitup. fisixengine. core. vector; <br/> Import COM. fileitup. fisixengine. participant. wheelparticle; <br/> Import COM. fileitup. fisixengine. primitives. surface; <br/> Import COM. fileitup. fisixengine. participant. circleparticle;
These classes include the engine core class, particle object, collision class, and common graphics class.
Note: The flex class does not exist. We need to manually import it.
First, modify some default SWF methods, such as size and color.
[SWF (width = '000000', Height = '000000', backgroundcolor = '0xffffff', framerate = '30')] <br/> public class myfisixdemo extends sprite <br/>
3. Engine itself
3.1 next, we want to instantiate our independent physical Engine
VaR myengine: fisixengine = new fisixengine ();
3.2 target world
We already have this engine working for us, and we can add some forces to the objects we can respond to these forces.
// Add a surface <br/> var surface1: surface = myengine. newsurface (new vector (0,200), new vector (500,350), 10) <br/> // set the attributes of the surface, rebound force and resistance <br/> surface1.bounce = 0.9; <br/> surface1.friction = 0.5; <br/>
3.3 start our engine:
// Render our objects
Myengine. setrender (true );
Myengine. setrendergraphics (graphics );
Myengine. startengine (stage. framerate );
Code List:
Package {<br/> Import flash. display. sprite; <br/> Import COM. fileitup. fisixengine. core. fisixengine; <br/> Import COM. fileitup. fisixengine. collisions. reactionmodes; <br/> Import COM. fileitup. fisixengine. core. vector; <br/> Import COM. fileitup. fisixengine. participant. wheelparticle; <br/> Import COM. fileitup. fisixengine. primitives. surface; </P> <p> Import flash. display. movieclip; </P> <p> [SWF (width = '000000', Height = '000000', backgroundcolor = '0xffffff', framerate = '30')] <br/> public class myfisixdemo extends sprite <br/>{< br/> Public Function myfisixdemo () <br/> {<br/> // create an instance of our engine. <br/> var myengine: fisixengine = new fisixengine (); <br/> // turn on physical collision reactions <br/> myengine. setreactionmode (reactionmodes. physical); <br/> // set the gravity to pull down at a rate of 1 pixel per second <br/> myengine. setgravity (0, 1 * stage. framerate) </P> <p> // next, add a surface to the engine <br/> var surface1: surface = myengine. newsurface (new vector (0,200), new vector (500,350), 10) <br/> // set the surface's physical properties <br/> surface1.bounce = 0.9; <br/> surface1.friction = 0.5; </P> <p> // Add a circle particle to the surface at position 200,100 with a radius of 50 pixels <br/> var participant 1: wheelparticle = myengine. newwheelparticle (200,100, 50); <br/> Participant 1.bounce = 0.7; <br/> Participant 1.friction = 0.5; </P> <p> // turn on primitive rendering <br/> myengine. setrender (true); <br/> // tell the engine where to render to <br/> myengine. setrendergraphics (graphics); </P> <p> // start the engine <br/> myengine. startengine (30); <br/>}< br/>
Running Effect: a reflector and a roller axis are created.
This is just a simple example. We can add more results to our program.