当前位置: 首页 > 后端技术 > Node.js

一款cocos小游戏

时间:2023-04-04 01:27:07 Node.js

1.【启用物理世界】:cc.director.getPhysicsManager().enabled=true;/启用物理世界只能写在load/cc.director.getCollistonManager().enable=true;cc.director.getCollistonManager().enableDebugDraw=true;cc.director.enableDrawBoundingBox=true/获取物理信息,开启物理调试,显示物理模型/[碰撞回调]onBeginContact:function(contact,selfCollider,otherCollide){},/碰撞开始回调/onEndContact:function(contact,selfCollider,otherCollide){},/碰撞结束回调/onPreSolve:function(contact,selfCollider,otherCollide){},/碰撞过程连续回调/onPostSolve:function(contact,selfCollider,otherCollide){}/contactupdatecompletedCallback(可获取冲量信息)//三个参数依次为碰撞信息,脚本挂载刚体碰撞信息,其他刚体碰撞信息/更多API请阅读官方文档2.【Preloadscene]:cc.director.preloadScene("场景名称");3.【加载场景】:cc.director.loadScene("场景名称");4.【添加事件】:node.on("touchstart",this.touchHandle,node);(绑定事件的最后一个参数就是this点,有时候也可以bind(this))5.【加载其他节点资源】:varmain=require("main");/先引入脚本/varmainJS=cc.find("Canvas").getComponent(main);/获取脚本组件/varani=node.getComponent(cc.Animation);/获取动画组件/6.【游戏导演状态】:cc.director.end();/停止游戏/cc.director.pause();/暂停游戏,不停止UI响应和渲染/cc.director.resume();/恢复游戏的暂停/游戏地址,有需要我发教程