Flash physical engine application: fisixobject class (1)

Source: Internet
Author: User

1. Add simple objects

When we enter this class, we can find that there are many ways to create and remove objects. to simulate the physical effect, we first try to add some objects to the engine for simulation. Common particles such as circles and squares

Let's take a look at some simple demos below:

Package {<br/> Import COM. fileitup. fisixengine. core. *; <br/> Import COM. fileitup. fisixengine. participant. circleparticle; </P> <p> Import flash. display. sprite; <br/> public class example3 extends sprite <br/> {<br/> private var myengine: fisixengine; <br/> private var fixobject: fisixobject; <br/> Public Function example3 () <br/>{< br/> Init (); <br/>}</P> <p> private function Init (): void <br/>{< br/> myengine = new fisixengine (); <br/> fixobject = myengine. newfisixobject (); // create a fisixobject <br/> var partic: circleparticle = fixobject. newcircleparticle (50, 50, 50); // Add a circle with a radius of 50 </P> <p> myengine. setgravity (); // set the direction of gravity <br/> myengine. setrender (true); // rendering <br/> myengine. setrendergraphics (graphics); <br/> myengine. startengine (); // start rendering <br/>}< br/>

Step 1: import the library we need

Import com. fileitup. fisixengine. Core. *; <br/> Import com. fileitup. fisixengine. participant. circleparticle; </P> <p> Import flash. display. Sprite;

We don't use many class libraries. We only use two core classes and one particle class.

 

 

Step 2: program entry

Myengine = new fisixengine ();

 

 

 

Step 3: Create a fisixobject object and introduce a fisixobject object to the engine through myengine.

Fixobject = myengine. newfisixobject (); // create a fisixobject

 

 

 

Step 4: Create a circle

VaR partic: circleparticle = fixobject. newcircleparticle (50, 50); // Add a circle with a radius of 50 and coordinates (50, 50)

 

 

Step 5: render and start the engine

Myengine. setgravity (); // you can specify the direction of gravity.
Myengine. setrender (true); // Rendering
Myengine. setrendergraphics (graphics );
Myengine. startengine (); // start the engine

 

Effect: A simple ball is running.

 

 

 

Note: (the development platform is Flex + fisixengine. SWC)

 

 

2. Add a surface

 

We add a surface on the basis of the original, that is to say, we need to add a barrier for the circle we are sliding down.

 

VaR surface: surface = fixobject. newsurface (new vector (0,200), new vector (500,300), 50); // Add a surface

Code List: add only one line of code

 

Package {<br/> Import COM. fileitup. fisixengine. core. *; <br/> Import COM. fileitup. fisixengine. participant. circleparticle; <br/> Import COM. fileitup. fisixengine. primitives. surface; </P> <p> Import flash. display. sprite; <br/> [SWF (width = '000000', Height = '000000', backgroundcolor = '0xffffff', framerate = '30')] <br/> public class example3 extends sprite <br/>{< br/> private var myengine: fisixengine; <br/> private var fixobject: fisixobject; <br/> Public Function example3 () <br/>{< br/> Init (); <br/>}</P> <p> private function Init (): void <br/>{< br/> myengine = new fisixengine (); <br/> fixobject = myengine. newfisixobject (); // create a fisixobject <br/> var partic: circleparticle = fixobject. newcircleparticle (50, 50, 50); // Add a circle with a radius of 50 <br/> var surface: surface = fixobject. newsurface (new vector (0,200), new vector (500,300), 50); // Add a surface </P> <p> myengine. setgravity (); // set the direction of gravity <br/> myengine. setrender (true); // rendering <br/> myengine. setrendergraphics (graphics); <br/> myengine. startengine (); // start rendering <br/>}< br/>

 

A simple result is displayed.

 

 

 

 

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.