Cocos2dx 3d open-source project fantasyWarrior3D from scratch 3 [BattleScene]
Or from the constructor
Function BattleScene. create ()
1. setCamera () (1) create a camera
Camera = cc. Camera: createPerspective (60.0, size. width/size. height, 10.0, 4000.0)
The declaration in 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 );
Parameters:
[1] fieldOfView camera field 0 ~ P (0 ~ Between 180 degrees)
[2] aspect ratio of aspectRatio Screen
[3] The third parameter of nearPlane is the distance from the near plane. Please note that the content close to the near plane is not displayed in the game window.
[4] farPlane's fourth parameter is the distance from the far plane. Please note that content far away from the far plane is not displayed in the game window.
Add the camera object to the scene object to replace the default camera (the direction vector is perpendicular to the x and y planes)
CurrentLayer: addChild (camera)
(2) Add the ui Layer camera: addChild (uiLayer) to the camera)
So let's look at the implementation of uilayer initUILayer ()
UiLayer: setPositionZ (cc. ctor: getInstance (): getZEye ()/4)
GetZEye () obtains the distance from the near plane.
Zcoordinate is set to a negative value because uiLayer is added as a child node of the camera object, which is closer to the camera than the near plane.
UiLayer: setGlobalZOrder (3000) Ensure that the ui is at the top
2. gameController ()
Game status update for each frame
(1) moveCamera camera's mobile getFocusPointOfHeros () gets the average position of all heroes, that is, the camera's focus position
[1] automatic shift with role
Local temp = cc. pLerp (cameraPosition,
Cc. p (focusPoint. x + cameraOffset. x, cameraOffset. y + focusPoint. y-size.height * 3/4 ),
2 * dt)
Make y coordinates of camera and FocusPoint consistent
[2] Close-up effect
In fact, in the seconds when specialCamera. valid is set to true, the calculation method of the orientation (lookAt) of the camera position is changed temporarily.
A dark gray layer for special effects
CurrentLayer: setColor (cc. c3b (125,125,125) -- deep gray
Cascade)
CurrentLayer: setCascadeColorEnabled (true)
The child node can change with the color of the parent node
[3] The Player slides to change the camera offset.
Set the value of cameraOffset in the onTouchMoved function.
CameraOffset = cc. pGetClampPoint (cc. pSub (cameraOffset, delta), cameraOffsetMin, cameraOffsetMax)
Because it is the opposite direction of sliding, so it is sub
Limit the max and min of the displacement through pGetClampPoint
(2) updateParticlePos () allows the example effect to be moved with the role
(3) gameMaster: update (dt) is responsible for refresh and refresh the dialog box and prompts. We will not go into details here.
(4) collisionDetect collision detection is maintained by Manager. lua
(5) The solveAttacks damage calculation is maintained by the attackCommand.
3. createBackground () Creation scenario
(1) Ground
SpriteBg: setPosition3D (cc. V3 (-2300,-, 0 ))? I haven't figured out how it came about yet. The author won't give a c3b original file.
(2) cc. Water: create Water implementation
In Water. cpp
4. registered some message processing functions
The logic Object layer (Knight, Mage, and Archer) interacts with the UI Layer by sending messages.
(1) bleeding BLOOD_MINUS
MessageDispatchCenter: registerMessage (MessageDispatchCenter. MessageType. BLOOD_MINUS, bloodMinus)
(2) Anger value ANGRY_CHANGE
(3) give a close-up SPECIAL_PERSPECTIVE when placing skills
(4) UIcontainsPoint (position)
This function describes the interaction between the UI Layer and logical objects.