Cocos2dx-JS learning 01

1
2
3
4
5
6
<body>
<script src="res/loading.js"></script>
<canvas id="gameCanvas" width="480" height="720"></canvas>
<script src="frameworks/cocos2d-html5/CCBoot.js"></script>
<script cocos src="main.js"></script>
</body>

First of all loaded documents is CCBoot.js

The main loop

1
2
3
4
5
6
7
8
9
10
11
12



MAINLOOP: function () {
if (this._purgeDirectorInNextLoop) {
this._purgeDirectorInNextLoop = false;
this.purgeDirector();
}
else if (!this.invalid) {
this.drawScene();
}
},

_purgeDirectorInNextLoop: whether the next frame itself needs to be cleared, usually cc.director.end()assigned to true

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

* Draw the scene. This method is called every frame. Don't call it manually.
*/
drawScene: function () { Were renderer = cc.renderer;


// calculate "global" dt
this.calculateDeltaTime();

Big Box   Cocos2dx-JS learning 01 the n-class = "the Comment"> // tick the before glClear: Issue # 533
if (!this._paused) {
this._scheduler.update(this._deltaTime);
cc.eventManager.dispatchEvent(this._eventAfterUpdate);
}


// executed first task scheduler, and then trigger cc.director.EVENT_AFTER_UPDATE event, check the interactive events, available on the distribution process / * to Avoid Flickr, nextScene the MUST BE here Wallpaper: the before and the After tick Draw. XXX: Which bug . It IS the this One Seems not that IT CAN BE Reproduced with v0.9 * / IF ( the this ._nextScene) { the this .setNextScene (); } // If there is a scene change, then switching // render the current sCENE // Draw SCENE The IF ( the this ._runningScene) { IF (renderer.childrenOrderDirty) { cc.renderer.clearRenderCommands (); cc.renderer.assignedZ = 0 ; the this ._runningScene._renderCmd._curLevel = 0

















; //level start from 0;
this._runningScene.visit();
renderer.resetFlag();
}
else if (renderer.transformDirty()) {
renderer.transform();
}
}

renderer.clear();

The Node Draw Notifications // IF ( the this ._notificationNode) the this ._notificationNode.visit (); // traverse the nodes, the nodes update the space transformation matrix, sends commands to the renderer cc.eventManager.dispatchEvent ( the this ._eventAfterVisit); CC. = g_NumberOfDraws 0 ;






renderer.rendering (cc._renderContext); the this ._totalFrames ++; // sort plotted cc.eventManager.dispatchEvent ( the this ._eventAfterDraw); cc.eventManager.frameUpdateListeners (); // update frame rate the this ._calculateMPF (); },







About Drawing Management

About memory management (reference counting)

scheduler

cc.Node related API

1
2
3
4
node.scheduleUpdate()
node.update = function (dt) {

}

Default Scheduler: Use scheduleUpdate, must override the update function, dt is the time interval

Custom scheduler:

1
node.schedule(callback,inteval,repeate,delay,key)

Callback function (to be), the time interval (default 0), the number of repetitions (default cc.REPEAT_FOREVER), delay time (default 0), the unique identifier

Uninstall Scheduler:

unschedule和unscheduleAllCallbacks

Scene Management

Use stack structure

In a related life cycle function exits, it should be this._super () function on the last call, follow the "last out"

A->B

SceneA before the start SceneB onEixtTransitionDidStart method of execution ctor, so do not do large overhead work in the ctor

Genius

Each sprite generally associated with a texture (Texture2D objects)

Four ways to create

Guess you like

Origin www.cnblogs.com/lijianming180/p/12014235.html