您的位置:首页 > 其它

Flash物理引擎演示效果:

2009-03-02 18:13 423 查看
/Files/hero82748274/Example.swf

实现代码:

package

{

import com.fileitup.fisixengine.constraints.SpringConstraint;

import com.fileitup.fisixengine.core.FisixEngine;

import com.fileitup.fisixengine.core.FisixObject;

import com.fileitup.fisixengine.utils.BoundingBox;

import flash.display.Bitmap;

import flash.display.MovieClip;

import flash.events.Event;

import flash.text.TextField;

/**In this example, a jello-type object is created and manipulated by the mouse

*/

[SWF(width='700',height='500',backgroundColor='0x50464b',frameRate='30')]

[Embed (source="1.jpg")]

public class Example2 extends MovieClip{

private var myEngine:FisixEngine

private var txtFPS:TextField

public function Example2 (){

//first, create an instance of the fisixengine object

myEngine = new FisixEngine()

//bound all of the objects in the simulation within a box

myEngine.setBounds(new BoundingBox(0,0,700,500))

//enable collisions with the bounding box

myEngine.boundsCollisions=true

//set the gravity to pull down at a rate of 1 pixel per second

myEngine.setGravity(0,1)

//create a jello cube

var jello:FisixObject = myEngine.newFisixObject();

for(var i:uint=0;i<12;i++)

jello.newCircleParticle(250+100*Math.cos(i*30),200+100*Math.sin(i*30),20);

SpringConstraint.constraintAll(jello,jello.particles,.9);

//attach the corner of the jello to the mouse

myEngine.newMouseAttacher(jello.particles[0],root,3)

//turn on primitive rendering

myEngine.setRender(true);

//tell the engine where to render to

myEngine.setRenderGraphics(graphics)

addEventListener(Event.ENTER_FRAME,onEnterFrame)

txtFPS = new TextField()

addChild(txtFPS)

}

private function onEnterFrame(e:Event):void{

myEngine.mainLoop(1)

txtFPS.text = int(myEngine.getRealFPS()).toString()

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: