Cocos2dx 3d open-source project fantasyWarrior3D starts from scratch [LoadingScene & amp; MainMenuScene] And cocos2dx open-source games

Source: Internet
Author: User

Cocos2dx 3d open-source project fantasyWarrior3D starts from scratch [LoadingScene & MainMenuScene] And cocos2dx open-source games


[AppDelegate. cpp]
Start with applicationDidFinishLaunching ().
It is found that there is an additional method to encrypt the script.
(1) stack-> setXXTEAKeyAndSign ("2 dxLua", strlen ("2 dxLua"), "XXTEA", strlen ("XXTEA "));
(2) Use config. json configuration to find the main. lua entry of lua and execute it. Then jump to the first interface LoadingScene.

Engine-> executeScriptFile (ConfigParser: getInstance ()-> getEntryFile (). c_str ());


[LoadingScene]
1. Construction Sequence of LoadingScene: (1) LoadingScene: create () is called externally
(2) In create, execute LoadingScene: new (). The following definition takes effect.
Initialize yourself as a scene:
Local MainMenuScene = class ("MainMenuScene", function ()
Return cc. Scene: create ()
End
)

(3) ctor ()
Because the class method defined by cocos2dx-lua function. lua is used, the constructor () of the subclass is called by default ()
(4) Call LoadingScene: init () at the end of create to complete initialization of other sub-objects

2. In init (), a scheduler is enabled to execute update to update the sub-object status. cc. ctor: getInstance (): getScheduler (): scheduleScriptFunc (update, 0.1, false)
What has update done:
(1) cache a particle and material every 0.1 seconds
LoadingScene: cachedparticipant leres ()
LoadingScene: cachedTextureRes ()


(2) Adjust the position of the progress bar loadingbar: setPercent (self. _ totalResource-self. _ num)/self. _ totalResource * 100)


(3) jump if loading is completed
Local scene = require ("MainMenuScene ")
Cc. Director: getInstance (): replaceScene (scene: create ())

[MainMenuScene]
// Static function, used to set the default Paster pixel format with ALPHA channel. When an image is created as a texture, if there is an ALPHA channel, the default texture pixel format is generated.
Static void setDefaultAlphaPixelFormat (CCTexture2DPixelFormat format );
1. addCloud add cloud (1) Enable a mobile cloud scheduler at a frequency of 60 times per second
Self. scheduleCloudMove = cc. Director: getInstance (): getScheduler (): scheduleScriptFunc (cloud_move, 1/60, false)
2. addlogo swing back and forth implementation local function logoShake ()
-- Rand_n = range * math. sin (math. rad (time * speed + offset ))
Local rand_x = 0.1 * math. sin (math. rad (time * 0.5 + 4356 ))
Local rand_y = 0.1 * math. sin (math. rad (time * 0.37 + 5436 ))
Local rand_z = 0.1 * math. sin (math. rad (time * 0.2 + 54325 ))
Logo: setRotation3D ({x = math. deg (rand_x), y = math. deg (rand_y), z = math. deg (rand_z )})
Time = time + 1
End
Self. logoSchedule = cc. Director: getInstance (): getScheduler (): scheduleScriptFunc (logoShake, 0, false)

In fact, this code can be viewed
Local rand_x = 0.1 * math. sin (math. rad (time ))
Local rand_y = 0.1 * math. sin (math. rad (time ))
Local rand_z = 0.1 * math. sin (math. rad (time ))
Use math. rad to limit the time To a radian of less than 360, and then use math. sin to convert it to an interval value [-x, x].
In the end, * 0.1 reduces the swing amplitude, so that an x, y, and Z-axis swing is realized.

In this case, we set the value in cocosIDE and found that the border effect suddenly disappeared. The "View" function is still a little bug.

3. addPointLight the guy with wings (1) getLightSprite () used to construct the body and use alpha to mix the color to achieve translucent effect of the wings and other parts
Self. _ lightSprite: setBlendFunc (gl. ONE, gl. ONE_MINUS_SRC_ALPHA)
GL_ONE: 1.0
GL_ONE_MINUS_SRC_ALPHA: 1.0 minus the source Alpha value as a factor

Reference http://cn.cocos2d-x.org/tutorial/show? Id = 1739

(2) normal texture to achieve concave and convex Effects

Local variables tnormalmapped = cc. effectNormalMapped: create ("mainmenuscene/logo_normal.png ");
Extends tnormalmapped: setPointLight (self. _ pointLight)
Extends tnormalmapped: setKBump (50) Is this set the concave and convex value?

(3) circular motion and drag
OnTouchBegin records the current position and opens the mobile processing function movePoint.
OnTouchEnded: Turn off the mobile processing function and call getBezierAction () to start the circular motion again"

MovePoint:
It is worth noting that the lerp function is used to obtain interpolation to achieve a moving Effect of deceleration and acceleration.
MovePoint function: local point = cc. pLerp (lightSpritePos, self. _ prePosition, dt * 2)

Related Article

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.