首先 谢谢拉登大叔

预览效果

AS3代码

package
{import flash.display.Sprite;import flash.events.Event;import flash.events.MouseEvent;import nape.geom.Vec2;import nape.phys.*;import nape.shape.Polygon;import nape.space.Space;import nape.util.ShapeDebug;/*** @author jacky<br>* * 创建时间:2013-9-23 下午03:20:18**/[SWF(width= 550,height= 400,backgroundColor=0xffffff,frameRate=60)]public class NapeExe1 extends Sprite{private var space:Space;private var debug:ShapeDebug;public function NapeExe1(){//1.创建一个基本的Nape空间//声明空间重力var gravity:Vec2 = new Vec2(0, 400);space = new Space(gravity);//2.创建静态的Nape刚体//        a.创建一个Body对象,并指定它的类型和坐标var body:Body = new Body(BodyType.STATIC, new Vec2(stage.stageWidth/2, stage.stageHeight-10));//        b.创建刚体的形状shape,可以接收的形状有两种Cirle和Polygon,后者通过指定不同的顶点来创建任何非圆形的形状。var shape:Polygon = new Polygon(Polygon.box(stage.stageWidth, 10));body.shapes.add(shape);//        c.指定刚体所存在的空间,即第一部分提到的空间。body.space = space;//3.创建模拟视图debug = new ShapeDebug(550, 400);addChild(debug.display);addChild(new Stats());//4.在ENTER_FRAME事件处理器中进行Nape模拟
            addEventListener(Event.ENTER_FRAME, loop);stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseEventHandler);}private function mouseEventHandler(e:MouseEvent):void{//        a.创建一个Body对象,并指定它的类型和坐标var body:Body = new Body(BodyType.DYNAMIC, new Vec2(mouseX, mouseY));//        b.创建刚体的形状shape,可以接收的形状有两种Cirle和Polygon,后者通过指定不同的顶点来创建任何非圆形的形状。var shape:Polygon = new Polygon(Polygon.box(Math.random()*30+30,Math.random()*30+30));body.shapes.add(shape);//        c.指定刚体所存在的空间,即第一部分提到的空间。body.space = space;}private function loop(e:Event):void{//Nape空间模拟space.step(1 / 60, 30);//清除视图
            debug.clear();//优化显示图像
            debug.flush();//绘制空间
            debug.draw(space);}}
}

View Code

FPS类

/*** Hi-ReS! Stats* * Released under MIT license:* http://www.opensource.org/licenses/mit-license.php** How to use:* *    addChild( new Stats() );*    *    or*    *    addChild( new Stats( { bg: 0xffffff } );* * version log:**    09.03.28        2.1        Mr.doob            + Theme support.*    09.02.21        2.0        Mr.doob            + Removed Player version, until I know if it's really needed.*                                            + Added MAX value (shows Max memory used, useful to spot memory leaks)*                                            + Reworked text system / no memory leak (original reason unknown)*                                            + Simplified                *    09.02.07        1.5        Mr.doob            + onRemovedFromStage() (thx huihuicn.xu)*    08.12.14        1.4        Mr.doob            + Code optimisations and version info on MOUSE_OVER*    08.07.12        1.3        Mr.doob            + Some speed and code optimisations*    08.02.15        1.2        Mr.doob            + Class renamed to Stats (previously FPS)*    08.01.05        1.2        Mr.doob            + Click changes the fps of flash (half up increases, half down decreases)*    08.01.04        1.1        Mr.doob            + Shameless ripoff of Alternativa's FPS look :P*                            Theo            + Log shape for MEM*                                            + More room for MS*     07.12.13        1.0        Mr.doob            + First version**/package
{import flash.display.Bitmap;import flash.display.BitmapData;import flash.display.Sprite;import flash.events.Event;import flash.events.MouseEvent;import flash.geom.Rectangle;import flash.system.System;import flash.text.StyleSheet;import flash.text.TextField;import flash.utils.getTimer;    /*** <b>Hi-ReS! Stats</b> FPS, MS and MEM, all in one.*/public class Stats extends Sprite{    private var _xml : XML;private var _text : TextField;private var _style : StyleSheet;private var _timer : uint;private var _fps : uint;private var _ms : uint;private var _ms_prev : uint;private var _mem : Number;private var _mem_max : Number;private var _graph : BitmapData;private var _rectangle : Rectangle;private var _fps_graph : uint;private var _mem_graph : uint;private var _mem_max_graph : uint;private var _theme : Object = { bg: 0x000033, fps: 0xffff00, ms: 0x00ff00, mem: 0x00ffff, memmax: 0xff0070 }; /*** <b>Hi-ReS! Stats</b> FPS, MS and MEM, all in one.* * @param theme         Example: { bg: 0x202020, fps: 0xC0C0C0, ms: 0x505050, mem: 0x707070, memmax: 0xA0A0A0 } */public function Stats( theme : Object = null ) : void{if (theme){if (theme.bg != null) _theme.bg = theme.bg;if (theme.fps != null) _theme.fps = theme.fps;if (theme.ms != null) _theme.ms = theme.ms;if (theme.mem != null) _theme.mem = theme.mem;if (theme.memmax != null) _theme.memmax = theme.memmax;}addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true);}private function init(e : Event) : void{removeEventListener(Event.ADDED_TO_STAGE, init);graphics.beginFill(_theme.bg);graphics.drawRect(0, 0, 70, 50);graphics.endFill();_mem_max = 0;_xml = <xml><fps>FPS:</fps><ms>MS:</ms><mem>MEM:</mem><memMax>MAX:</memMax></xml>;
        _style = new StyleSheet();_style.setStyle("xml", {fontSize:'9px', fontFamily:'_sans', leading:'-2px'});_style.setStyle("fps", {color: hex2css(_theme.fps)});_style.setStyle("ms", {color: hex2css(_theme.ms)});_style.setStyle("mem", {color: hex2css(_theme.mem)});_style.setStyle("memMax", {color: hex2css(_theme.memmax)});_text = new TextField();_text.width = 70;_text.height = 50;_text.styleSheet = _style;_text.condenseWhite = true;_text.selectable = false;_text.mouseEnabled = false;addChild(_text);var bitmap : Bitmap = new Bitmap( _graph = new BitmapData(70, 50, false, _theme.bg) );bitmap.y = 50;addChild(bitmap);_rectangle = new Rectangle( 0, 0, 1, _graph.height );            addEventListener(MouseEvent.CLICK, onClick);addEventListener(Event.ENTER_FRAME, update);}private function update(e : Event) : void{_timer = getTimer();if( _timer - 1000 > _ms_prev ){_ms_prev = _timer;_mem = Number((System.totalMemory * 0.000000954).toFixed(3));_mem_max = _mem_max > _mem ? _mem_max : _mem;_fps_graph = Math.min( 50, ( _fps / stage.frameRate ) * 50 );_mem_graph =  Math.min( 50, Math.sqrt( Math.sqrt( _mem * 5000 ) ) ) - 2;_mem_max_graph =  Math.min( 50, Math.sqrt( Math.sqrt( _mem_max * 5000 ) ) ) - 2;_graph.scroll( 1, 0 );_graph.fillRect( _rectangle , _theme.bg );_graph.setPixel( 0, _graph.height - _fps_graph, _theme.fps);_graph.setPixel( 0, _graph.height - ( ( _timer - _ms ) >> 1 ), _theme.ms );_graph.setPixel( 0, _graph.height - _mem_graph, _theme.mem);_graph.setPixel( 0, _graph.height - _mem_max_graph, _theme.memmax);_xml.fps = "FPS: " + _fps + " / " + stage.frameRate;_xml.mem = "MEM: " + _mem;_xml.memMax = "MAX: " + _mem_max;_fps = 0;}_fps++;_xml.ms = "MS: " + (_timer - _ms);_ms = _timer;_text.htmlText = _xml;}private function onClick(e : MouseEvent) : void{mouseY / height > .5 ? stage.frameRate-- : stage.frameRate++;_xml.fps = "FPS: " + _fps + " / " + stage.frameRate;_text.htmlText = _xml;}// .. Utilsprivate function hex2css( color : int ) : String{return "#" + color.toString(16);}}
}

View Code

Nape SWC文件下载点击这里

转载于:https://www.cnblogs.com/LLLoveLL/p/3335009.html

了解Nape 2d物理引擎 第一天相关推荐

  1. 制作简单的2D物理引擎(零)

    最近发现了Github上的开源物理引擎项目Matter.js,对它很感兴趣,发现源码并不算长,算上注释大约1万行左右,值得剖析一番.Matter.js实现一个最小化的2D物理引擎,性能不错,故打算用C ...

  2. python 物理引擎 摩擦力_参赛作品2-phenom的2D物理引擎

    全球图形学领域教育的领先者.自研引擎的倡导者.底层技术研究领域的技术公开者,东汉书院在致力于使得更多人群具备内核级竞争力的道路上,将带给小伙伴们更多的公开技术教学和视频,感谢一路以来有你的支持.我们正 ...

  3. APE 2D物理引擎使用

    先去http://www.cove.org/ape/index.htm 下载作者的最新版APE 然后打开说明文档 docs\api\index.html 这里一共十二个类,看起来很少,所以初学者可以更 ...

  4. 关于2d物理引擎box2d与ape的评论

    APE不行,做点简单的撞球,台球之类游戏还行.我最开始用他实验性做了个简单的基于物理引擎的泡泡龙类游戏,发现稍微多一点的几何体堆叠在一起就会产生渗透现象,没办法只好更改最初的设计.要专注做物理游戏,还 ...

  5. 2D物理引擎--谁碰了我的奶酪

    人生犹如"迷宫",每个人都在其中寻找各自的"奶酪"--稳定的工作.身心的健康.和谐的人际关系.甜蜜美满的爱情,或是令人充满想象的财富-- 那么,你是否正在享受你 ...

  6. Unity Physics2D 2d物理引擎游戏 笔记

    2d 材质 里面可以设置 摩擦力 和 弹力 Simulated:是否在当前的物理环境中模拟,取消勾选该框类似于Disable Rigidbody,但使用这个参数更加高效,因为Disable会销毁内部产 ...

  7. as3 physaxe 2d 物理引擎

    http://drawlogic.com/2008/04/06/physaxe-2d-flash-physics-kit-for-haxe-and-list-of-flash-flex-actions ...

  8. Ophone平台2D游戏引擎实现——物理引擎(一)(二)

    http://dev.10086.cn/cmdn/wiki/index.php?doc-view-4271.html http://dev.10086.cn/cmdn/wiki/index.php?d ...

  9. Farseer:一个用于Silverlight和XNA的开源物理引擎

    当前在演示和越来越多交互界面的推动下,实时动画在很多情况下已经成为不可或缺的要求.当动画涉及到物体在屏幕上互相反弹或者被重力影响的时候,一个物理引擎就是必要的了. Farseer Physics En ...

最新文章

  1. Python入门知识
  2. 风险清退之后,这类平台反而更靠谱
  3. Docker命令查询
  4. [云炬创业基础笔记]第七章创业资源测试4
  5. 缓存-SpringCache-整合体验@Cacheable
  6. MapReduce程序之序列化原理与Writable案例
  7. 工作占用了太多私人时间_下班后还要被逼谈工作,我们应该如何处理?
  8. python 串口助手 简书_python用pyserial读取串口问题解决
  9. 收获,不止SQL优化——抓住SQL的本质--第四章
  10. 小米2019开发者大会:核心技术集体亮相,推动下一代超级互联网
  11. java分桃子_Java经典编程题分桃子
  12. stream场景用法总结
  13. tor the onion router下载_盒马生鲜超市购物app下载,打开盒马鲜生小程序!
  14. 软件技术架构:通过限流与熔断,打造一个“靠谱”的系统
  15. PHP把列表数据的子级内容合并到父级
  16. windows下mongodb安装与使用
  17. 计算机一级考word几,计算机一级word考试主要内容
  18. 基于51单片机+74LS138译码器+8位共阴数码管时钟设计—按键修改时间
  19. Tensorflow2.0---SSD网络原理及代码解析(一)
  20. 由对称性知定点一定在x轴上_圆锥曲线中的定点定值问题的四种模型.doc

热门文章

  1. go 怎么等待所有的协程完成_优雅地等待子协程执行完毕
  2. GitHub星数1.3W!五分钟带你搞定Bash脚本使用技巧
  3. win10资源管理器打开一直正在处理文件加载不出来,桌面图标不加载
  4. 老师想知道从某某同学当中,分数最高的是多少,现在请你编程模拟老师的询问。当然,老师有时候需要更新某位同学的成绩. 输入描述:
  5. 单自由度体系对简谐荷载的反应
  6. 【论文翻译】PLOP: Learning without Forgetting for Continual Semantic Segmentation
  7. java中关于json传图片的方法
  8. 关于谷歌webrtc源码国内镜像的使用问题,以及Kurento媒体服务器
  9. 小程序云开发支持公众号网页开发了
  10. k近邻算法python_k-近邻算法的Python实现