Cocos2d-x Lua Example: Effects demo

Source: Internet
Author: User

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
  1. ... ...
  2. Local Sprite①
  3. Local Gridnodetarget②
  4. ... ...
  5. function Myactionscene:createlayer ()
  6. Cclog ("myactionscene Actionflag =%d", Actionflag)
  7. Local layer = cc. Layer:create ()
  8. gridnodetarget = cc. Nodegrid:create () ③
  9. Layer:addchild (Gridnodetarget) ④
  10. ... ...
  11. Local function Gomenu (psender)
  12. Cclog ("Myactionscene gomenu")
  13. Local AC1 = cc. Moveby:create (2, CC.P (0))
  14. Local AC2 = ac1:reverse ()
  15. Local AC = cc. Sequence:create (AC1, AC2)
  16. If Actionflag = = Kflipx3d Then
  17. Gridnodetarget:runaction (CC. Flipx3d:create (3.0)) ⑤
  18. ElseIf Actionflag = = Kpageturn3d Then
  19. Gridnodetarget:runaction (CC. Pageturn3d:create (3.0, Cc.size (15,10))) ⑥
  20. ElseIf Actionflag = = Klens3d Then
  21. Gridnodetarget:runaction (CC. Lens3d:create (3.0, Cc.size (15,10),
  22. CC.P (SIZE.WIDTH/2,SIZE.HEIGHT/2), 240) ⑦
  23. ElseIf Actionflag = = Kshaky3d Then
  24. Gridnodetarget:runaction (CC. Shaky3d:create (3.0, Cc.size (15,10), 5, false)) ⑧
  25. ElseIf Actionflag = = Kwaves3d Then
  26. Gridnodetarget:runaction (CC. Waves3d:create (3.0, Cc.size (15,10), 5, 40)) ⑨
  27. ElseIf Actionflag = = Kjumptiles3d Then
  28. Gridnodetarget:runaction (CC. Jumptiles3d:create (3.0, Cc.size (15,10), 2, 30)) ⑩
  29. ElseIf Actionflag = = Kshakytiles3d Then
  30. Gridnodetarget:runaction (CC. Shakytiles3d:create (3.0, Cc.size (16,12), 5, false))?
  31. ElseIf Actionflag = = Kwavestiles3d Then
  32. Gridnodetarget:runaction (CC. Wavestiles3d:create (3.0, Cc.size (15,10), 4, 120))?
  33. End
  34. End
  35. Backmenuitem:registerscripttaphandler (Backmenu)
  36. Gomenuitem:registerscripttaphandler (Gomenu)
  37. return layer
  38. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.