Cocos Creator Helpful Resources
note: a Chinese language version can be found here
Videos
- NEW!!! Cocos Creator For Beginners
- Marketing video
- Hands On With Cocos Creator (thank you Game From Scratch!)
PR’s
1. cocos creator Rotating 3d node gimbal deadlock problem
PR: valueType add rotateAround func (#4642) · cocos/cocos-engine@581ef38 · GitHub
2. repairing spine using multiple skins, not showing problems in cache mode
3. 2.0.10 Label is 2.0.9 Carton
PR: native returns unpremultiplied data by minggo · Pull Request #1765 · cocos/engine-native · GitHub
4. Fixed a problem with cc.tween value of 0 may not work
PR: fixed cc.tween by 2youyou2 · Pull Request #4790 · cocos/cocos-engine · GitHub
5. 2.1.1 Using the ray to detect the basic 3D object (cuboid), the detection distance will be affected by the scaling value
6. bmfont memory leak
PR: Optimize memory issues of BMFont. by caryliu1999 · Pull Request #4651 · cocos/cocos-engine · GitHub
7. Cocos Creator 2.0.9 ttf font causes memory leak on iOS devices
8. creator 2.09 WeChat game can’t be closed on background music
PR: fix repeatly recycle audio by PPpro · Pull Request #4793 · cocos/cocos-engine · GitHub
9. spine adjusts the native function BUG via JSB
PR: V2.2.0 spine 3.7 by sunnylanwanjun · Pull Request #1754 · cocos/engine-native · GitHub
10. spine adjusts the native function BUG via JSB
PR: V2.2.0 spine 3.7 by sunnylanwanjun · Pull Request #1754 · cocos/engine-native · GitHub
11. loadResArray has no callback after the network image fails to load multiple times
PR: fix issue that loadRes doesn't callback by holycanvas · Pull Request #4501 · cocos/cocos-engine · GitHub
fix issue that loadRes doesn't callback by holycanvas · Pull Request #96 · cocos-creator-packages/weapp-adapter · GitHub
12. 2.0.10 Font display abnormal system font Arial, in the simulator display suddenly big and small
13. creator h5 sound mute problem
PR: set webAudio volume immediately by PPpro · Pull Request #4767 · cocos/cocos-engine · GitHub
14. loading large files under the WeChat game, json ios directly flashback
15. after the UI adds BlockInputEvents, it still eats events
PR: Modify the calculation of renderOrder in EventManager. by caryliu1999 · Pull Request #4522 · cocos/cocos-engine · GitHub
Fix a sorting error when the node have been removed. by caryliu1999 · Pull Request #4710 · cocos/cocos-engine · GitHub
2.0.10: Sync 2.1.2 bug fix to 2.0.11 by knoxHuang · Pull Request #4653 · cocos/cocos-engine · GitHub
Common Problems
1. 2.1.1 Dynamically modify the material map
A: The texture map receives the
cc.Texture2D
object, so we can add acc.Texture2D
object in the properties panel ourselves.
spriteFrame
can also get itstexture2d
:
spriteFrame.getTexture()
With the texture, we directly call the api of the material system to modify the texture:
this.material.setProperty("diffuseTexture", this.goldTexture);
setProperty This interface can modify almost all properties on the material.
Test demo: https://github.com/Jno1995/DynamicLoadingMaterial
2. cocos H5 can’t be judged on ios getID
A: Because the touchID of these two platforms is not the same, this needs to be noted.
So touchID can’t be used as the serial number of multi-touch.
You should get:
event.getTouches().length;
This field is used to detect the number of contacts
3. cocos creator Rotating 3d node gimbal deadlock problem
4. 2.1.0 Update to 2.1.1 sprite.setState cannot be used
A:
this.sprite.setMaterial(0, cc.Material.getBuiltinMaterial('gray-sprite');
5. VIVO window.requestAnimFrame Uncaught error
A:
Ifwindows.requestAnimFrame
is not initialized, it is assigned a value of 16.
6. button click event invalid
A: This is a bug in version 2.0.10. You need to call it after switching the transparency of the button.
The node’s_onSiblingIndexChanged
function refreshes the scene rendering order according to the arrivalOrder.
You can use it like this:
7. Cancellation of timer failed, timer is still running
A: The reason for this problem is that this.unschedule(callback, target) requires two arguments to specify the timer object that needs to be paused.
callBack must be the same as the callback in this.schedule, anonymous functions do not work.
The target is the environment object of the schedule. If there is any difference, the schedule cannot be stopped normally.
Implementation can refer to:CCScheduler.js -> unschedule
8. How to dynamically switch resources in the editor environment
A: Hello, this requirement now has the following options:
In the editor environment,cc.loader.loadRes
cannot load resource files properly, please usecc.loader.load();
Currently,cc.loader.load()
can only be loaded into unparsed data files. Currently, the interface for manually constructing bitMapFont is not open in the engine, so the label font cannot be dynamically switched. The current switch can be done dynamically.
- the editor environment dynamically switch pictures
var texture2DEnum = cc.Enum({
null: 0,
texture_one: 1,
texture_two: 2
});
cc.Class({
extends: cc.Sprite,
editor: {
disallowMultiple: true,
executeInEditMode: true,
menu: "自定义组件/自定义精灵组件",
},
properties: {
defaultSpriteFrameTexture2D: {
default: texture2DEnum.null,
type: texture2DEnum,
displayName: "图片精灵初始贴图枚举",
notify: function() {
this.onLoadTexture2DToSprite();
}
},
_oldDefaultTexture2D: null,
},
// LIFE-CYCLE CALLBACKS:
// onLoad () {},
start () {
this.onLoadTexture2DToSprite();
},
onLoadTexture2DToSprite () {
this.defaultTextureUrl = cc.url.raw(`resources/texture_${this.defaultSpriteFrameTexture2D}.jpg`);
if (this._oldDefaultTexture2D !== this.defaultTextureUrl) {
this._oldDefaultTexture2D = this.defaultTextureUrl;
if (this.defaultSpriteFrameTexture2D !== texture2DEnum.null) {
cc.loader.load(this.defaultTextureUrl, (err, resTexture2D)=> {
this.spriteFrame = null;
this.spriteFrame = new cc.SpriteFrame(resTexture2D);
});
}
else {
this.spriteFrame = null;
}
}
}
});
2. When planning to drag the script into the property panel, I want to have a default value, such as fnt or spritframe, just like the button is there, there are three images, so you can drag and drop each script.
This requirement can be solved with the creator’s control library plugin:
Pull the prefab you need to the control library, just drag it out the next time you use it.
9. use cc.loader.loadRes
to load cc.BufferAssets
type error
A: Sorry, 2.0.x only supports binary, but it is recognized as cc.Asset type. Only the editor above 2.1 will recognize binary as BufferAsset.
10. Is there any way to get all the keel resources in the Creator project?
A:
Editor.assetdb.queryAssets('db://assets/**\\/*',['dragonbones','dragonbones-atlas'],function ( error, results ) {
});
11. Can’t find subpackage xxx
A: Please test the project after it is released.
Subpackaging information cannot be generated during web preview.
12. About videoPlayer is always displayed at the top of the question
A: Refer to the program of this post
Can meet the needs of most browsers. But on the Android WeChat browser you need to do something like this.
13. Problems with nodesPool using nodes that mount Animation components
A: At present, the engine is designed like this. When the node pool is recycled, the action action registered by the node will be removed, but the animation will only pause and will not be eliminated.
So you need to deal with it yourself during playback and replay it from scratch every time.
14. 2.1.1 Invalid on LabelShadow IOS
A: Currently does not support ios
15. ScrollView nested EditBox, use node pool to reuse EditBox problems
A: Mainly the problem caused by this interface.
removeFromParent()
This interface will clear the registered events of the node by default.
removeFromParent()
can solve your problem by passing in false
16. cdn cache problem
A: This operational problem, our solution is: manifaset put oss, download package put cdn server. Take it away! This problem is also pitted for a long time.
{“version”:“1.0055”,“packageUrl”:“http://cdn.xx.net/xx/fk10055",“remoteManifestUrl”:"http://osscdn.xx.net/xx/fk/project. Manifest”,“remoteVersionUrl”:“http://osscdn.xx.net/xx/fk/version.manifest”}
can also be like this:
{“version”:“1.0055”,“packageUrl”:“http://cdn.xx.net/xx/fk10055",“remoteManifestUrl”:"http://osscdn.xx.net/xx/fk10055/project. Manifest”,“remoteVersionUrl”:“http://osscdn.xx.net/xx/fk10055/version.manifest”} When the code takes the remote manifest and adds the version number to spell it, put the cdn server.
17. Cocos Creator physics engine related issues
A: 1, box2d elastic problem:
Elasticity is a special movement, and the physical system continuously calculates the state and position of the rigid body during the game life cycle. This problem can now be optimized by reducing the precision of the dt parameters passed by the physical system’s update callback.
Find the code in box2d.js and change the code in the red box.
Another option is to turn on a timer that determines if the amplitude is less than a certain value (such as dt) each time it is rebounded, and then manually stop the bounce of the object.
2, 3 belong to the same kind of problem, you can open the friction of the gold rigid body.
18. Editor problem: abnormal opening project
A: Download this DLL repair tool to try to fix.
19. cc.url.raw The path obtained varies by platform?
A: 2. This is normal. This API is just a simple path conversion and does not take into account the file type. In fact, Creator does not have any API or documentation that requires users to directly use the path of suffix xxx.prefab. You should write TestPrefab.json directly if you need it.
(Because Prefab is not a raw asset, only raw assets can use .raw. For normal assets, there is no guarantee that this json will be available because json may merge.)
20. 2.0.2 IOS10 The following can’t run ah
A:
According to the latest data today, iOS 9 is already very small. We tried to support it before, but the effect was not good, so I decided to give up temporarily. After that, we will enable the new JS engine on iOS as soon as possible, so as to avoid the platform fragmentation and the probability of supporting iOS 9 at that time.
Demo Projects
The most important source of examples is the Example Collection project template. There are also many demos to show a complete game:
- Dark Slash basic game loop demo. Special thanks to Veewo Games for authorizing us to use original ‘Dark Slash’ game resources to make this tutorial.
- UI Demos including multi-resolution supporting menu interface with cool transition animations, a backpack generated by data and prefab and a Clash Royale style navigation menu showcase.
- Blackjack demo, collaboratively developed with Tencent Games.
- Flappy Bird clone featuring a sheep.
- Star Catcher demo game, in user manual we have a quick start tutorial showing how to build this game step by step.