or from a constructor.
function Battlescene.create ()
1. Setcamera () (1) Create 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 VIEWP ORT).
* @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 vision 0~p (i.e. 0~180度)
[2] aspect ratio of the aspectratio screen
[3] Nearplane The third parameter is the distance from the near plane, notice that the distance is closer to the near plane than the content is not rendered in the game window
[4] Farplane The fourth parameter is the distance from the far plane, notice that the distance is farther than the far plane is not rendered in the game window.
Add camera object to scene but replace default camera (direction vector perpendicular to x, y plane)
Currentlayer:addchild (camera)
(2) Add UI layer Camera:addchild (Uilayer) on camera
So look at the implementation of Uilayer Inituilayer ()
Uilayer:setpositionz (CC. Director:getinstance (): Getzeye ()/4)
Getzeye () Gets the distance to the near plane
The z-coordinate is set to a negative value because: Uilayer is added to the child node of the camera object, it is closer to the camera than the "near plane"
Uilayer:setglobalzorder (3000) Make sure the UI is covered on top
2. Gamecontroller ()
Game state updates for each frame
(1) Movecamera camera's mobile Getfocuspointofheros () Gets the average position of all heroes, that is, the focus position of the camera
[1] auto-shift with character
Local temp = Cc.plerp (cameraposition,
CC.P (focuspoint.x+cameraoffset.x, Cameraoffset.y + FOCUSPOINT.Y-SIZE.HEIGHT*3/4),
2*DT)
Align camera and focuspoint y-coordinates
[2] close-up effect
In fact, the calculation of the orientation (lookAt) of the camera position is temporarily changed within a few seconds of the specialcamera.valid being set to True
A dark gray layer when you have a special effect.
Currentlayer:setcolor (Cc.c3b (),--deep Grey
Interface Cascade (Cascade)
Currentlayer:setcascadecolorenabled (True)
Child nodes can change as the parent node changes color
[3] player swipe to change camera offset
Set the value of Cameraoffset in the ontouchmoved function to implement the
Cameraoffset = Cc.pgetclamppoint (Cc.psub (Cameraoffset, Delta), Cameraoffsetmin,cameraoffsetmax)
Because it's like sliding in the opposite direction, so is the sub
Max and Min for limiting displacements through Pgetclamppoint
(2) Updateparticlepos () Let the example effect move with the character
(3) gamemaster:update (DT) is responsible for the Brush Monsters, Refresh dialog boxes, hints, etc.
(4) Collisiondetect collision detection is maintained by Manager.lua.
(5) Solveattacks damage calculation is maintained by Attackcommand.
3. Createbackground () Create a scene
(1) Ground
Spritebg:setposition3d (CC. V3 ( -2300,-1000,0)) ? For the time being, the author does not give a c3b to the original document.
(2) cc. Realization of Water:create water
In the Water.cpp
4. Registration of some message processing functions
The logical object layer (Knight, Mage, Archer) interacts with the UI layer by sending messages
(1) Buckle Blood Blood_minus
Messagedispatchcenter:registermessage (MessageDispatchCenter.MessageType.BLOOD_MINUS, Bloodminus)
(2) Rage value Angry_change
(3) Give a close-up special_perspective when you put your skills.
(4) Uicontainspoint (position)
This function describes the interaction between the UI layer and the Logical object
Reference:
3D Game Control
http://blog.csdn.net/minsenwu/article/details/17120495
Unity3d camera
Http://game.ceeger.com/Script/Camera/Camera.fieldOfView.html
Analysis of the structure of Fantasywarrior3d
http://cn.cocos2d-x.org/tutorial/show?id=1798
COCOS2DX 3d Open Source project Fantasywarrior3d from zero 3 [Battlescene]