Cocos2dx 3d open-source project fantasyWarrior3D starts from scratch. 2 [ChooseRoleScene]
1. Touch events
Function ChooseRoleScene: initTouchDispatcher ()
Initialize the listener object
Local listenner = cc. EventListenerTouchOneByOne: create ()
Register
EventDispatcher: addEventListenerWithSceneGraphPriority (listenner, self. layer)
Set handler Functions
Listenner: registerScriptHandler (function (touch, event)
// Function body
Return true
End, cc. Handler. EVENT_TOUCH_BEGAN)
(1) EVENT_TOUCH_BEGAN achieves rotation. If you click "hero ",
If cc. rectContainsPoint (heroSize, touchbeginPt) then -- rotate
IsRotateavaliable = true
Return true
End
Record the click position touchbeginPt
(2) determine whether to click the device in the backpack because self. _ weaponItem: getBoundingBox () obtains the area relative to the backpack,
So the mouse click position is preferred to switch to the relative position of the backpack
TouchbeginPt = self. _ bag: convertToNodeSpace (touchbeginPt)
If the device is ready, zoom in and adjust the transparency
Self. _ weaponItem: setScale (1.7)
Self. _ weaponItem: setOpacity (150)
(3) EVENT_TOUCH_MOVED: determines whether the sliding position is more than 50 pixels.
Rotate3Heroes
Positions are rotated by moving 3d coordinates, and EaseCircleActionInOut increases the elasticity effect after being slow.
Cc. EaseCircleActionInOut: create (cc. MoveTo: create (rotatetime, pos [3])
(4) EVENT_TOUCH_ENDED update Implementation
SwitchArmour switchWeapon switchHelmet is implemented in each role.
Switch to display and hide the mesh of the two sets of equipment.
However, the scalability of this implementation method remains to be considered. If there are n sets of equipment, does each part need n corresponding mesh?
2. objects on the UI
(1) function ChooseRoleScene: addButton () "Enter game" button
The global variable ReSkin is used to record the device id.
Clear the related lua objects before redirecting to BattleScene.
Package. loaded ["BattleScene"] = nil
Package. loaded ["Manager"] = nil
Package. loaded ["Helper"] = nil
Package. loaded ["MessageDispatchCenter"] = nil
Package. loaded ["BattleFieldUI"] = nil
Set the button position
Next_Button: setNormalizedPosition ({x = 0.34, y = 0.13 })
Node: setNormalizedPosition method. The Node location pixel is calculated based on the size of its parent Node, that is, proportional
(2). function ChooseRoleScene: addBag () equipment and attributes
Self: switchTextWhenRotate () switch between the occupation icon and set the attribute value
In fact, the location of the equipment is completely written, so there is no need for reference.
(3). function ChooseRoleScene: addHeros () Add the role rotation hero:
Local function hero_rotate ()
Local rotation = self. layer: getChildByTag (sortorder [2]): getRotation3D ()
Self. layer: getChildByTag (sortorder [2]): setRotation3D ({x = rotation. x, y = rotation. y + rotate, z = 0 })
End
Sortorder [2] stores the hero in the middle location
SetRotation3D ({x = rotation. x, y = rotation. y + rotate, z = 0}) enables a schedule to rotate 0.5 radians at a time.