Flash physical engine application: Creating Particles

Source: Internet
Author: User

When I was just getting started with this engine, I felt very powerful and had a good performance in some demonstration aspects. These are all foreign class libraries. Relatively speaking, it is still a headache to explain English. Most of the time, if you don't know the entire architecture, you can simply find it and record it.

 

Check out this class package: COM. fileitup. fisixengine. Participant

There are four kinds of approximate particles in the documentation API: Circular particles, navigation particles (should not be prepared), square particles, and a rotating particle.

 

Circular particles: Dynamic circles with coordinate axes and central lines

Navigation particle: used to connect a rigid body object

Square particle; processing Polygon

Rotating Particle: it is similar to a circular particle, but it can rotate,

 

Try to create a simple particle: when we open these packages, we will try to see what they mean. After all, you have to try a foreign language if it is hard to grasp.

 

According to our habits, Let's first look at the first particle: circleparticle

1. Its Constructor

Circleparticle (X: Number, Y: Number, rad: Number) creates an instance of a circleparticle creates an independent circular Particle

 

 

 

 

 

There are many ways to do this. Let's try something simple to see if it can happen.

First, import the desired package.

Import com. fileitup. fisixengine. Core. fisixengine;
Import com. fileitup. fisixengine. participant. circleparticle;
 

Use flex to create an as project. Name: Example

Package <br/> {<br/> Import COM. fileitup. fisixengine. core. fisixengine; <br/> Import COM. fileitup. fisixengine. participant. circleparticle; </P> <p> Import flash. display. movieclip; </P> <p>/** in this example, a jello-type object is created and manipulated by the mouse <br/> */<br/> [SWF (width = '000000', Height = '000000 ', backgroundcolor = '0x50464b', framerate = '30')] <br/> public class example extends movieclip {<br/> private var myengine: fisixengine </P> <p> Public Function example () {</P> <p> myengine = new fisixengine () <br/> myengine. setgravity (0, 1) <br/> var circle: circleparticle = myengine. newcircleparticle (, 30, 30); <br/> // circle. bounce = 0.7; </P> <p> myengine. setrender (true); <br/> // tell the engine where to render to <br/> myengine. setrendergraphics (graphics) <br/> myengine. startengine (30); </P> <p >}< br/>}

 

Program entry:

Myengine = new fisixengine () // create a physical engine,
Myengine. setgravity (0, 1) // specify its gravity

 

2. Create a circle:

 

VaR circle: circleparticle = myengine. newcircleparticle (, 30); // I guess it is to create a separate circle for this physical engine, with a radius of 30 and coordinates (, 30 ).

 

Next, start the engine, render the object, and set the frame speed of the engine.

Myengine. setrender (true );
Myengine. setrendergraphics (graphics)
Myengine. startengine (30 );

 

A simple circle seems to have been completed. See how it works: For ease of display, I enlarge the radius

 

 

 

In my opinion, it is a pleasure to get this circle, because the road to exploration is starting. The following highlights:

You can also set collision walls, elasticity, and other effects.

 

Package <br/> {<br/> Import COM. fileitup. fisixengine. core. fisixengine; <br/> Import COM. fileitup. fisixengine. participant. circleparticle; <br/> Import COM. fileitup. fisixengine. utils. boundingbox; </P> <p> Import flash. display. movieclip; </P> <p>/** in this example, a jello-type object is created and manipulated by the mouse <br/> */<br/> [SWF (width = '000000', Height = '000000 ', backgroundcolor = '0x50464b', framerate = '30')] <br/> public class example2 extends movieclip {<br/> private var myengine: fisixengine </P> <p> Public Function example2 () {</P> <p> myengine = new fisixengine () <br/> myengine. setgravity (0, 1) <br/> myengine. setbounds (New boundingbox (0, 0, 700,500); <br/> myengine. boundscollisions = true; <br/> var circle: circleparticle = myengine. newcircleparticle (, 30, 30); <br/> circle. bounce = 0.7; </P> <p> myengine. setrender (true); <br/> // tell the engine where to render to <br/> myengine. setrendergraphics (graphics) <br/> myengine. startengine (30); </P> <p >}< br/>

 

Further evolution: The following results can be achieved:

Package <br/> {<br/> Import COM. fileitup. fisixengine. constraints. springconstraint; <br/> Import COM. fileitup. fisixengine. core. fisixengine; <br/> Import COM. fileitup. fisixengine. core. fisixobject; <br/> Import COM. fileitup. fisixengine. utils. boundingbox; </P> <p> Import flash. display. bitmap; <br/> Import flash. display. movieclip; <br/> Import flash. events. event; <br/> Import flash. text. textfield; </P> <p>/** in this example, a jello-type object is created and manipulated by the mouse <br/> */<br/> [SWF (width = '000000', Height = '000000 ', backgroundcolor = '0x50464b', framerate = '30')] <br/> [embed (Source = "1.jpg")] <br/> public class example2 extends movieclip {<br/> private var myengine: fisixengine <br/> private var txtfps: textfield </P> <p> Public Function example2 () {<br/> // first, create an instance of the fisixengine object </P> <p> myengine = new fisixengine () </P> <p> // bound all of the objects in the simulation within a box <br/> myengine. setbounds (New boundingbox (0,0, 700,500) <br/> // enable collisions with the bounding box <br/> myengine. boundscollisions = true </P> <p> // set the gravity to pull down at a rate of 1 pixel per second <br/> myengine. setgravity (0, 1) </P> <p> // create a jello cube <br/> var jello: fisixobject = myengine. newfisixobject (); </P> <p> for (var I: uint = 0; I <12; I ++) <br/> jello. newcircleparticle (250 + 100 * Math. cos (I * 30), 200 + 100 * Math. sin (I * 30), 20); <br/> springconstraint. constraintall (jello, jello. particle ,. 9); </P> <p> // attach the corner of the jello to the mouse <br/> myengine. newmouseattacher (jello. participant [0], root, 3) </P> <p> // turn on primitive rendering <br/> myengine. setrender (true); <br/> // tell the engine where to render to <br/> myengine. setrendergraphics (graphics) </P> <p> addeventlistener (event. enter_frame, onenterframe) </P> <p> txtfps = new textfield () <br/> addchild (txtfps) <br/>}</P> <p> private function onenterframe (E: Event): void {<br/> myengine. mainloop (1) </P> <p> txtfps. TEXT = int (myengine. getrealfps ()). tostring () <br/>}</P> <p>

 

Demo: http://files.cnblogs.com/hero82748274/Example.swf

Ii. Class relationship:

 

Package Com. fileitup. fisixengine. Participant
Class Public class circleparticle
Inheritance Circleparticle --> particle --> collisionobject
Subclasses Circleparticipant leconveyor, projectile, and wheelparticle

 

We can see that the circleparticle class inherits the particle, while partilce inherits the collisionobject

 

Collisionobject is equivalent to their base class, so as to understand this hierarchical relationship. Lay the foundation for our implementation

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.