初始化

This commit is contained in:
SmallMain
2022-06-25 00:23:03 +08:00
commit ef0589e8e5
2264 changed files with 617829 additions and 0 deletions

View File

@@ -0,0 +1 @@
var mng = new cc.ActionManager();

View File

@@ -0,0 +1,2 @@
//register a schedule to scheduler
cc.director.getScheduler().schedule(callback, this, interval, !this._isRunning);

View File

@@ -0,0 +1,3 @@
//register a schedule to scheduler
var scheduler = cc.director.getScheduler();
scheduler.scheduleCallbackForTarget(this, function, interval, repeat, delay, !this._isRunning);

View File

@@ -0,0 +1,3 @@
//register this object to scheduler
var scheduler = cc.director.getScheduler();
scheduler.scheduleUpdateForTarget(this, priority, !this._isRunning );

View File

@@ -0,0 +1,3 @@
//unschedule a callback of target
var scheduler = cc.director.getScheduler();
scheduler.unscheduleCallbackForTarget(this, callback);

View File

@@ -0,0 +1,3 @@
//unschedules the "update" method.
var scheduler = cc.director.getScheduler();
scheduler.unscheduleUpdateForTarget(this);

View File

@@ -0,0 +1,58 @@
{
// 根节点不用查找路径
// root properties
props: {
x: [
{ frame: 0, value: 0, curve: [0,0.5,0.5,1] },
{ frame: 1, value: 200, curve: null }
]
},
comps: {
// component
'comp-1': {
// component properties
'prop-1': [
{ frame: 0, value: 10, curve: [0,0.5,0.5,1] },
{ frame: 1, value: 20, curve: null }
]
}
},
paths: {
// key 为节点到root的路径名, 通过cc.find找到
'foo/bar': {
// node properties
props: {
x: [
{ frame: 0, value: 0, curve: [0,0.5,0.5,1]
{ frame: 1, value: 200, curve: null }
]
},
comps: {
// component
'comp-1': {
// component property
'prop-1': [
{ frame: 0, value: 10, curve: [0,0.5,0.
{ frame: 1, value: 20, curve: null }
]
}
}
},
'hello': {
props: {
position: [
{
frame: 0,
value: [0,0],
motionPath: [
[320, 240, 0, 240, 640, 240],
[640, 0, 400, 0, 1000, 0]
]
},
{ frame: 5, value: [640, 480] }
]
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
// frame : The exactly time in second.
// func : Callback function name
// params : Callback parameters
[
{ frame: 0, func: 'onAnimationEvent1', params:['param-1', 'param-2'] },
{ frame: 2, func: 'onAnimationEvent3', params:['param-1', 'param-2'] },
{ frame: 3, func: 'onAnimationEvent2', params:['param-1'] },
// The second event at frame 3
{ frame: 3, func: 'onAnimationEvent4', params:['param-1'] },
{ frame: 4, func: 'onAnimationEvent4', params:['param-1'] }
]

View File

@@ -0,0 +1,3 @@
---------
var sprite = new _ccsg.Sprite();
sprite.initWithSpriteFrameName("grossini_dance_01.png");

View File

@@ -0,0 +1,18 @@
// Create KEYBOARD EventListener.
cc.EventListener.create({
event: cc.EventListener.KEYBOARD,
onKeyPressed: function (keyCode, event) {
cc.log('pressed key: ' + keyCode);
},
onKeyReleased: function (keyCode, event) {
cc.log('released key: ' + keyCode);
}
});
// Create ACCELERATION EventListener.
cc.EventListener.create({
event: cc.EventListener.ACCELERATION,
callback: function (acc, event) {
cc.log('acc: ' + keyCode);
}
});

View File

@@ -0,0 +1,20 @@
// Add KEYBOARD EventListener To StatusLabel.
cc.eventManager.addListener({
event: cc.EventListener.KEYBOARD,
onKeyPressed: function(keyCode, event){
var label = event.getCurrentTarget();
label.setString("Key " + keyCode.toString() + " was pressed!");
},
onKeyReleased: function(keyCode, event){
var label = event.getCurrentTarget();
label.setString("Key " + keyCode.toString() + " was released!");
}
}, statusLabel);
// Create ACCELERATION EventListener To Sprite.
cc.eventManager.addListener({
event: cc.EventListener.ACCELERATION,
callback: function(acc, event){
//Here processing logic.
}
}, sprite);

View File

@@ -0,0 +1,22 @@
// 1. remove eventManager add Listener;
var mouseListener1 = cc.eventManager.addListener({
event: cc.EventListener.MOUSE,
onMouseDown: function(keyCode, event){ },
onMouseUp: function(keyCode, event){ },
onMouseMove: function () { },
onMouseScroll: function () { }
}, node);
cc.eventManager.removeListener(mouseListener1);
// 2. remove eventListener create Listener;
var mouseListener2 = cc.EventListener.create({
event: cc.EventListener.MOUSE,
onMouseDown: function(keyCode, event){ },
onMouseUp: function(keyCode, event){ },
onMouseMove: function () { },
onMouseScroll: function () { }
});
cc.eventManager.removeListener(mouseListener2);

View File

@@ -0,0 +1,8 @@
----------
Subclasses can override this method to make event propagable
```js
for (var target = this._parent; target; target = target._parent) {
if (target._capturingListeners && target._capturingListeners.hasEventListener(type)) {
array.push(target);
}
}

View File

@@ -0,0 +1,18 @@
cc.Class({
extends: cc.Component,
onLoad: function () {
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
},
destroy () {
cc.systemEvent.off(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
},
onKeyDown: function (event) {
switch(event.keyCode) {
case cc.macro.KEY['0']:
console.log('Press a key');
break;
}
}
});

View File

@@ -0,0 +1,46 @@
// JavaScript:
var WrapMode = cc.Enum({
Repeat: -1,
Clamp: -1
});
// Texture.WrapMode.Repeat == 0
// Texture.WrapMode.Clamp == 1
// Texture.WrapMode[0] == "Repeat"
// Texture.WrapMode[1] == "Clamp"
var FlagType = cc.Enum({
Flag1: 1,
Flag2: 2,
Flag3: 4,
Flag4: 8,
});
var AtlasSizeList = cc.Enum({
128: 128,
256: 256,
512: 512,
1024: 1024,
});
// TypeScript:
// If used in TypeScript, just define a TypeScript enum:
enum Direction {
Up,
Down,
Left,
Right
}
// If you need to inspect the enum in Properties panel, you can call cc.Enum:
const {ccclass, property} = cc._decorator;
@ccclass
class NewScript extends cc.Component {
@property({
type: cc.Enum(Direction) // call cc.Enum
})
direction: Direction = Direction.Up;
}

View File

@@ -0,0 +1,4 @@
----
lerp
cc.misc.lerp(2,10,0.5)//returns 6
cc.misc.lerp(2,10,0.2)//returns 3.6

View File

@@ -0,0 +1,10 @@
-----
var myClass = function () { this.value = 0.5 };
cc.Class.attr(myClass, 'value'); // return undefined
cc.Class.attr(myClass, 'value', {}).min = 0; // assign new attribute table
//associated with 'value', and set its min = 0
cc.Class.attr(myClass, 'value', { // set values max and default
max: 1,
default: 0.5,
});
cc.Class.attr(myClass, 'value'); // return { default: 0.5, min: 0, max: 1 }

View File

@@ -0,0 +1,4 @@
----------------------------------------------------
// add SpriteFrames to SpriteFrameCache With File
cc.spriteFrameCache.addSpriteFrames(s_grossiniPlist);
cc.spriteFrameCache.addSpriteFrames(s_grossiniJson);

View File

@@ -0,0 +1,3 @@
----------------------------------------------------
//get a SpriteFrame by name
var frame = cc.spriteFrameCache.getSpriteFrame("grossini_dance_01.png");

View File

@@ -0,0 +1,7 @@
--------------------------
1. //creates a TextureAtlas with filename
var textureAtlas = new cc.TextureAtlas("res/hello.png", 3);
2. //creates a TextureAtlas with texture
var texture = cc.textureCache.addImage("hello.png");
var textureAtlas = new cc.TextureAtlas(texture, 3);

View File

@@ -0,0 +1,2 @@
----
cc.textureCache.addImage("hello.png");

View File

@@ -0,0 +1,2 @@
---------
var key = cc.textureCache.getKeyByTexture(texture);

View File

@@ -0,0 +1,2 @@
---------------
var cacheTextureForColor = cc.textureCache.getTextureColors(texture);

View File

@@ -0,0 +1,2 @@
------------------
var key = cc.textureCache.getTextureForKey("hello.png");

View File

@@ -0,0 +1,3 @@
--------------------------------------------------
var textureAtlas = new cc.TextureAtlas();
textureAtlas.initWithTexture("hello.png", 3);

View File

@@ -0,0 +1,4 @@
---------------------------
var texture = cc.textureCache.addImage("hello.png");
var textureAtlas = new cc.TextureAtlas();
textureAtlas.initWithTexture(texture, 3);

View File

@@ -0,0 +1,2 @@
--------
cc.textureCache.removeAllTextures();

View File

@@ -0,0 +1,2 @@
-----
cc.textureCache.removeTexture(texture);

View File

@@ -0,0 +1,2 @@
------
cc.textureCache.removeTexture("hello.png");

View File

@@ -0,0 +1,2 @@
------------------
var key = cc.textureCache.textureForKey("hello.png");

View File

@@ -0,0 +1,6 @@
---------------------------------
cc.path.basename("a/b.png"); //-->"b.png"
cc.path.basename("a/b.png?a=1&b=2"); //-->"b.png"
cc.path.basename("a/b.png", ".png"); //-->"b"
cc.path.basename("a/b.png?a=1&b=2", ".png"); //-->"b"
cc.path.basename("a/b.png", ".txt"); //-->"b.png"

View File

@@ -0,0 +1,6 @@
----------------------------------
cc.path.changeBasename("a/b/c.plist", "b.plist"); //-->"a/b/b.plist"
cc.path.changeBasename("a/b/c.plist?a=1&b=2", "b.plist"); //-->"a/b/b.plist?a=1&b=2"
cc.path.changeBasename("a/b/c.plist", ".png"); //-->"a/b/c.png"
cc.path.changeBasename("a/b/c.plist", "b"); //-->"a/b/b"
cc.path.changeBasename("a/b/c.plist", "b", true); //-->"a/b/b.plist"

View File

@@ -0,0 +1,3 @@
---------------------------------
cc.path.changeExtname("a/b.png", ".plist"); //-->"a/b.plist"
cc.path.changeExtname("a/b.png?a=1&b=2", ".plist"); //-->"a/b.plist?a=1&b=2"

View File

@@ -0,0 +1,9 @@
---------------------------------
* unix
cc.path.driname("a/b/c.png"); //-->"a/b"
cc.path.driname("a/b/c.png?a=1&b=2"); //-->"a/b"
cc.path.dirname("a/b/"); //-->"a/b"
cc.path.dirname("c.png"); //-->""
* windows
cc.path.driname("a\\b\\c.png"); //-->"a\b"
cc.path.driname("a\\b\\c.png?a=1&b=2"); //-->"a\b"

View File

@@ -0,0 +1,5 @@
---------------------------
cc.path.extname("a/b.png"); //-->".png"
cc.path.extname("a/b.png?a=1&b=2"); //-->".png"
cc.path.extname("a/b"); //-->null
cc.path.extname("a/b?a=1&b=2"); //-->null

View File

@@ -0,0 +1,6 @@
------------------------------
cc.path.join("a", "b.png"); //-->"a/b.png"
cc.path.join("a", "b", "c.png"); //-->"a/b/c.png"
cc.path.join("a", "b"); //-->"a/b"
cc.path.join("a", "b", "/"); //-->"a/b/"
cc.path.join("a", "b/", "/"); //-->"a/b/"

View File

@@ -0,0 +1,2 @@
node.setPosition(cc.v2(0, 0));
node.setPosition(0, 0);

View File

@@ -0,0 +1,3 @@
---------------------------------
var size = cc.winSize;
node.setPosition(size.width/2, size.height/2);

View File

@@ -0,0 +1,7 @@
-----------------------
// 1. All channels seperately as parameters
var color1 = new cc.Color(255, 255, 255, 255);
// 2. Convert a hex string to a color
var color2 = new cc.Color("#000000");
// 3. An color object as parameter
var color3 = new cc.Color({r: 255, g: 255, b: 255, a: 255});

View File

@@ -0,0 +1,9 @@
// Converts a white color to a black one trough time.
update: function (dt) {
var color = this.node.color;
if (color.equals(cc.Color.BLACK)) {
return;
}
this.ratio += dt * 0.1;
this.node.color = cc.Color.WHITE.lerp(cc.Color.BLACK, ratio);
}

View File

@@ -0,0 +1,4 @@
var size1 = cc.size();
var size2 = cc.size(100,100);
var size3 = cc.size(size2);
var size4 = cc.size({width: 100, height: 100});