Cocos2d-x Lua Example: Effects demo
Below we introduce the use of several special effects through an example, as shown in, is an action menu scene, select Menu can enter the action scene, in the action scene click the Go button can perform our selected feature action, click the Back button can return to the menu scene.
Examples of special effects
Let's focus on the myactionscene scenario, the Myactionscene.lua main code is as follows:
[HTML]View Plaincopy
- ... ...
- Local Sprite①
- Local Gridnodetarget②
- ... ...
- function Myactionscene:createlayer ()
- Cclog ("myactionscene Actionflag =%d", Actionflag)
- Local layer = cc. Layer:create ()
- gridnodetarget = cc. Nodegrid:create () ③
- Layer:addchild (Gridnodetarget) ④
- ... ...
- Local function Gomenu (psender)
- Cclog ("Myactionscene gomenu")
- Local AC1 = cc. Moveby:create (2, CC.P (0))
- Local AC2 = ac1:reverse ()
- Local AC = cc. Sequence:create (AC1, AC2)
- If Actionflag = = Kflipx3d Then
- Gridnodetarget:runaction (CC. Flipx3d:create (3.0)) ⑤
- ElseIf Actionflag = = Kpageturn3d Then
- Gridnodetarget:runaction (CC. Pageturn3d:create (3.0, Cc.size (15,10))) ⑥
- ElseIf Actionflag = = Klens3d Then
- Gridnodetarget:runaction (CC. Lens3d:create (3.0, Cc.size (15,10),
- CC.P (SIZE.WIDTH/2,SIZE.HEIGHT/2), 240) ⑦
- ElseIf Actionflag = = Kshaky3d Then
- Gridnodetarget:runaction (CC. Shaky3d:create (3.0, Cc.size (15,10), 5, false)) ⑧
- ElseIf Actionflag = = Kwaves3d Then
- Gridnodetarget:runaction (CC. Waves3d:create (3.0, Cc.size (15,10), 5, 40)) ⑨
- ElseIf Actionflag = = Kjumptiles3d Then
- Gridnodetarget:runaction (CC. Jumptiles3d:create (3.0, Cc.size (15,10), 2, 30)) ⑩
- ElseIf Actionflag = = Kshakytiles3d Then
- Gridnodetarget:runaction (CC. Shakytiles3d:create (3.0, Cc.size (16,12), 5, false))?
- ElseIf Actionflag = = Kwavestiles3d Then
- Gridnodetarget:runaction (CC. Wavestiles3d:create (3.0, Cc.size (15,10), 4, 120))?
- End
- End
- Backmenuitem:registerscripttaphandler (Backmenu)
- Gomenuitem:registerscripttaphandler (Gomenu)
- return layer
- End
The above code, line ①, declares that the sprite variable is used within the Gamescene module, which is a sprite type. Line ② is declaring the Gamescene module using the Gridnodetarget variable, which is the Nodegrid type, and Nodegrid is the grid action management class, as shown in the class diagram.
Nodegrid class Diagram
Code ③ Line Code CC. Nodegrid:create () Creates a Nodegrid object, the ④ line of code needs to add the Nodegrid object you created Gridnodetarget to the current layer.
The code Gomenu function is to run the effect action, the ⑤ line is to use Flipx3d to achieve the x-axis 3D rollover effect, the parameters of the Create function is the duration.
The first parameter of the CREATE function is the duration, and the second parameter is the size of the grid, which is ⑥ using pageturn3d to achieve the page turn effect.
Line ⑦ is the use of lens3d to achieve convex lens effects, create function The first parameter is the duration, the second parameter is the mesh size, the third parameter mesh lens center point, the fourth parameter is the lens radius.
Line ⑧ is the use of shaky3d to achieve the shaking effect, the first parameter of the CREATE function is the duration, the second parameter is the size of the grid, the third parameter is the range of shaking, the fourth parameter is accompanied by a z-axis shaking.
Line ⑨ is the use of waves3d to achieve 3D volatility effects, the first parameter of the CREATE function is the duration, the second parameter is the size of the grid, the third parameter fluctuation number, the fourth parameter is the amplitude.
Line ⑩ is the use of jumptiles3d to achieve the shaking effect, 3D tile bounce effect, create function The first parameter is the duration, the second parameter is the size of the grid, the third parameter is the number of ticks, the fourth parameter is the beating amplitude.
The first line is the use of shakytiles3d to achieve 3D tile shaking effect, the CREATE function is a duration, the second parameter is the size of the grid, the third parameter is the range of shaking, the fourth parameter is accompanied by a z-axis shaking.
The first line is to use WAVESTILES3D to achieve 3D tile fluctuation effect, the CREATE function is a duration, the second parameter is the size of the grid, the third parameter, the fourth parameter is the amplitude.
Cocos2d-x Lua Example: Effects demo