cocos2dx 3d开源项目 fantasyWarrior3D 从零走起 3 [BattleScene]

cocos2dx 3d开源项目 fantasyWarrior3D 从零走起 3 [BattleScene],第1张

概述还是从构造函数看起 function BattleScene.create()  1. setCamera()  (1) 创建相机    camera = cc.Camera:createPerspective(60.0, size.width/size.height, 10.0, 4000.0)    cpp中的声明:      /**     * Creates a perspective c 还是从构造函数看起
function BattleScene.create()

1. setCamera() (1) 创建相机
camera = cc.Camera:createPerspective(60.0,size.wIDth/size.height,10.0,4000.0)

cpp中的声明:
/**
* Creates a perspective camera.
*
* @param fIEldOfVIEw The fIEld of vIEw for the perspective camera (normally in the range of 40-60 degrees).
* @param aspectRatio The aspect ratio of the camera (normally the wIDth of the vIEwport divIDed by the height of the vIEwport).
* @param nearPlane The near plane distance.
* @param farPlane The far plane distance.
*/
static Camera* createPerspective(float fIEldOfVIEw,float aspectRatio,float nearPlane,float farPlane);


参数:
[1] fIEldOfVIEw 相机视野 0~p (即 0~180 度) 之间
[2] aspectRatio 屏幕的高宽比
[3] nearPlane 第三个参数是与近平面的距离,请注意距离比与近平面还近的内容都不会呈现在游戏窗口中
[4] farPlane 第四个参数是与远平面的距离,请注意距离比与远平面还远的内容都不会呈现在游戏窗口中。


把camera对象添加到scene但中即可替代默认的camera(方向向量与 x,y 平面垂直)
currentLayer:addChild(camera)

(2) 在相机上面加了ui层 camera:addChild(uiLayer)
那么看看uilayer的实现 initUILayer()


uiLayer:setpositionZ(cc.Director:getInstance():getZEye()/4)
getZEye() 获取到近平面的距离
z坐标设为负值应该是因为: uiLayer被添加为了camera对象的子节点,它相对于"近平面"更靠近"摄像机"
uiLayer:setGlobalZOrder(3000) 确保ui盖在最上面

2. gameController()
每一帧的游戏状态更新

(1) moveCamera 摄像机的移动 getFocusPointOfheros() 获取所有英雄的平均位置,即作为相机的焦点位置


[1] 自动随角色位移
local temp = cc.pLerp(cameraposition,
cc.p(focusPoint.x+cameraOffset.x,cameraOffset.y + focusPoint.y-size.height*3/4),
2*dt)

让camera 和 FocusPoint 的y坐标保持一致

[2] 特写效果
实际上是在specialCamera.valID被置为true的几秒内,临时改变了 camera位置的朝向(lookAt)的计算方式

特效的时候蒙一层深灰色

currentLayer:setcolor(cc.c3b(125,125,125))--deep grey

界面级联(Cascade)
currentLayer:setCascadecolorEnabled(true)
子节点能够随着父节点的颜色改变而改变


[3] 玩家滑动改变 摄像机的偏移量
在 ontouchmoved函数中设置cameraOffset的值来实现
cameraOffset = cc.pGetClampPoint(cc.pSub(cameraOffset,delta),cameraOffsetMin,cameraOffsetMax)
因为是像滑动的反方向,所以是sub
通过pGetClampPoint限制位移的max 和 min


(2) updateParticlePos() 让例子效果根据随角色移动

(3) gameMaster:update(dt) 负责刷怪,刷新对话框,提示 等等,这里就不去深究了

(4) collisionDetect 碰撞检测 由Manager.lua 来维护

(5) solveAttacks 伤害计算 由attackCommand来维护

3. createBackground() 创建场景

(1) 地面

spriteBg:setposition3D(cc.V3(-2300,-1000,0)) ? 暂时没搞清怎么来的,作者又不给个c3b的原文件


(2) cc.Water:create 水的实现

在Water.cpp中


4. 注册了一些消息处理函数 逻辑对象层(骑士,法师,弓箭手)通过发送消息的方式来和UI层交互 (1) 扣血 BLOOD_MINUS MessagedispatchCenter:registerMessage(MessagedispatchCenter.MessageType.BLOOD_MINUS,bloodMinus) (2) 怒气值 angrY_CHANGE (3) 放技能的时候给个特写 SPECIAL_PERSPECTIVE (4)UIcontainsPoint(position) 这个函数描述了UI层与逻辑对象的交互 参考: 3D 游戏控制 http://blog.csdn.net/minsenwu/article/details/17120495 unity3d camera http://game.ceeger.com/Script/Camera/Camera.fIEldOfVIEw.HTML 分析《FantasyWarrior3D》结构 http://cn.cocos2d-x.org/tutorial/show?ID=1798 总结

以上是内存溢出为你收集整理的cocos2dx 3d开源项目 fantasyWarrior3D 从零走起 3 [BattleScene]全部内容,希望文章能够帮你解决cocos2dx 3d开源项目 fantasyWarrior3D 从零走起 3 [BattleScene]所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1016953.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-23
下一篇2022-05-23

发表评论

登录后才能评论

评论列表(0条)

    保存