展会信息港展会大全

cocos2dx 3d开源项目 fantasyWarrior3D 从零走起 3 [BattleScene]
来源:互联网   发布日期:2015-09-27 15:14:40   浏览:3567次  

导读: 还是从构造函数看起 function BattleScene.create()1. setCamera() (1) 创建相机 camera = cc.Camera:createPerspec...

还是从构造函数看起

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层与逻辑对象的交互

赞助本站

人工智能实验室
AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港