mirror of https://github.com/axmolengine/axmol.git
Remove samples/TestJavascript/Resources
This commit is contained in:
parent
2cf579de6b
commit
a763e4242f
|
@ -1 +0,0 @@
|
|||
1dcdf55f77f03e091227a0e3ecb4e22370811560
|
Binary file not shown.
|
@ -1 +0,0 @@
|
|||
c2eabd7cd8b62d39967387739fe05799de4ca764
|
|
@ -1 +0,0 @@
|
|||
4da0aa09555ebddf2caf1c9ece272f2fe38d2a4b
|
|
@ -1 +0,0 @@
|
|||
263832e2766c734b77335f353e3066033c158c90
|
|
@ -1 +0,0 @@
|
|||
a6ca8414e453957fa2fbc456b47160ac402ea35e
|
Binary file not shown.
Binary file not shown.
|
@ -1 +0,0 @@
|
|||
796a33e41fb8a78b122fdf0d8a626510629bbb80
|
|
@ -1 +0,0 @@
|
|||
8d997c0f9ffd94aa8868b58c9edd1b0c667c468a
|
|
@ -1 +0,0 @@
|
|||
ee5dba70cef2d704598a1ada6e1ddce3bc6afb9f
|
|
@ -1 +0,0 @@
|
|||
3988cfdf6548eaab2f408422c470140b7e74f464
|
|
@ -1 +0,0 @@
|
|||
b62acc9fb494f76ea75df3ec90cb0e53a58b9348
|
|
@ -1 +0,0 @@
|
|||
8167faf6c40ffd95a03028f1dcee1abdaa48b222
|
|
@ -1 +0,0 @@
|
|||
0a94a2f92306357e37c17ec39bf461a489e8fcdf
|
|
@ -1 +0,0 @@
|
|||
e037d3eb1e84411568cca1858d4fe5405d7ee661
|
|
@ -1 +0,0 @@
|
|||
52cb8d4dbb2f104a279eb8d6ecbb09d73b26e00b
|
|
@ -1 +0,0 @@
|
|||
c839baf9990fed7ddcaca66167188203ceaf9370
|
|
@ -1 +0,0 @@
|
|||
ff92f0108295bbc40a5db01b99cd97153f2601a2
|
|
@ -1 +0,0 @@
|
|||
8957affa037faf5669fc5fdedb51eb70abc583bb
|
|
@ -1 +0,0 @@
|
|||
d04c7f9966964a7f6384212b434d088473703ae5
|
|
@ -1 +0,0 @@
|
|||
acf81f7757cc397010702111c6a77aa986f037f1
|
|
@ -1 +0,0 @@
|
|||
6b9dcb4915a36e3aefef3f153949a96b145fba0d
|
|
@ -1 +0,0 @@
|
|||
d3589866bebe92b749e4b19d9118ff8486ae9ef4
|
|
@ -1 +0,0 @@
|
|||
95b23e939a17b088a08cb7dee0e3f38b75d28fb3
|
|
@ -1 +0,0 @@
|
|||
20818e1441e4e79925c0737c45c35d8d2787b082
|
|
@ -1 +0,0 @@
|
|||
40efb79bc18cbfa251d654afac9a0d3c8c09c048
|
|
@ -1 +0,0 @@
|
|||
3d8867f9108c8083aecfdb50f3c2220f09bdb3d6
|
|
@ -1 +0,0 @@
|
|||
72cdfd91838c9561ea035317291dc43c1660f4c8
|
|
@ -1 +0,0 @@
|
|||
26ec1ef81b0f7f6b965db4bb6bcbc31a9f18638c
|
|
@ -1 +0,0 @@
|
|||
1c7a836ea6bbf903d55e87d7a29a27997e86139f
|
|
@ -1 +0,0 @@
|
|||
148fa797a0a84fcbfac307b2d8482fd60b3002ff
|
|
@ -1 +0,0 @@
|
|||
8e1219b732d1ee3fd7270ce9f60c88e94dbb082a
|
|
@ -1 +0,0 @@
|
|||
0f2bff88acfd23787b3262d2b3b1f21f27c05e78
|
|
@ -1 +0,0 @@
|
|||
6dc9a563f11917ddea9db8ed1ff59da6762d34b1
|
Binary file not shown.
Before Width: | Height: | Size: 11 KiB |
|
@ -1 +0,0 @@
|
|||
910e2d46f0b8e9e52a381d49f6d0bccb279ce8b3
|
|
@ -1 +0,0 @@
|
|||
ba79d2996afc6b11cac08008b665d6890855b7ba
|
|
@ -1 +0,0 @@
|
|||
8b3f5ca94364bd86d2835c8eba1ac95bf0a65900
|
|
@ -1 +0,0 @@
|
|||
ebf660a26008ecdfc20455ae52db242309c1bd6f
|
|
@ -1 +0,0 @@
|
|||
648460ef0e39cadf28017dc30a4ac3c3ae017977
|
|
@ -1 +0,0 @@
|
|||
67b1f4a471f50a0df9c0bcd97d27b474d91f28e2
|
|
@ -1 +0,0 @@
|
|||
cc8dd1d0d875569db4112955e0305486374285ae
|
|
@ -1 +0,0 @@
|
|||
a648cdbe1a0668d60bcee196aea024055767496c
|
|
@ -1 +0,0 @@
|
|||
b246dd4d711b4039b68d800f0dc098a923f5c747
|
|
@ -1,517 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var TAG_BASE = 2000;
|
||||
var MAX_NODES = 1500;
|
||||
var NODES_INCREASE = 50;
|
||||
var s_nCurCase = 0;
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// NodeChildrenMenuLayer
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var NodeChildrenMenuLayer = PerformBasicLayer.extend({
|
||||
_maxCases:4,
|
||||
showCurrentTest:function () {
|
||||
var nodes = (this.getParent()).getQuantityOfNodes();
|
||||
var scene = null;
|
||||
switch (this._curCase) {
|
||||
case 0:
|
||||
scene = new IterateSpriteSheetCArray();
|
||||
break;
|
||||
case 1:
|
||||
scene = new AddSpriteSheet();
|
||||
break;
|
||||
case 2:
|
||||
scene = new RemoveSpriteSheet();
|
||||
break;
|
||||
case 3:
|
||||
scene = new ReorderSpriteSheet();
|
||||
break;
|
||||
}
|
||||
s_nCurCase = this._curCase;
|
||||
|
||||
if (scene) {
|
||||
scene.initWithQuantityOfNodes(nodes);
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// NodeChildrenMainScene
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var NodeChildrenMainScene = cc.Scene.extend({
|
||||
_lastRenderedCount:null,
|
||||
_quantityOfNodes:null,
|
||||
_currentQuantityOfNodes:null,
|
||||
|
||||
ctor:function () {
|
||||
var parent = new cc.Scene();
|
||||
__associateObjWithNative(this, parent);
|
||||
this.init();
|
||||
},
|
||||
|
||||
initWithQuantityOfNodes:function (nodes) {
|
||||
//srand(time());
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
// Title
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 40);
|
||||
this.addChild(label, 1);
|
||||
label.setPosition(cc.p(s.width / 2, s.height - 32));
|
||||
label.setColor(cc.c3b(255, 255, 40));
|
||||
|
||||
// Subtitle
|
||||
var strSubTitle = this.subtitle();
|
||||
if (strSubTitle.length) {
|
||||
var l = cc.LabelTTF.create(strSubTitle, "Thonburi", 16);
|
||||
this.addChild(l, 1);
|
||||
l.setPosition(cc.p(s.width / 2, s.height - 80));
|
||||
}
|
||||
|
||||
this._lastRenderedCount = 0;
|
||||
this._currentQuantityOfNodes = 0;
|
||||
this._quantityOfNodes = nodes;
|
||||
|
||||
cc.MenuItemFont.setFontSize(65);
|
||||
var that = this;
|
||||
var decrease = cc.MenuItemFont.create(" - ", this, this.onDecrease);
|
||||
decrease.setColor(cc.c3b(0, 200, 20));
|
||||
var increase = cc.MenuItemFont.create(" + ", this, this.onIncrease);
|
||||
increase.setColor(cc.c3b(0, 200, 20));
|
||||
|
||||
var menu = cc.Menu.create(decrease, increase);
|
||||
menu.alignItemsHorizontally();
|
||||
menu.setPosition(cc.p(s.width / 2, s.height / 2 + 15));
|
||||
this.addChild(menu, 1);
|
||||
|
||||
var infoLabel = cc.LabelTTF.create("0 nodes", "Marker Felt", 30);
|
||||
infoLabel.setColor(cc.c3b(0, 200, 20));
|
||||
infoLabel.setPosition(cc.p(s.width / 2, s.height / 2 - 15));
|
||||
this.addChild(infoLabel, 1, TAG_INFO_LAYER);
|
||||
|
||||
var menu = new NodeChildrenMenuLayer(true, 4, s_nCurCase);
|
||||
this.addChild(menu);
|
||||
|
||||
this.updateQuantityLabel();
|
||||
this.updateQuantityOfNodes();
|
||||
},
|
||||
title:function () {
|
||||
return "No title";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "";
|
||||
},
|
||||
updateQuantityOfNodes:function () {
|
||||
|
||||
},
|
||||
onDecrease:function (sender) {
|
||||
this._quantityOfNodes -= NODES_INCREASE;
|
||||
if (this._quantityOfNodes < 0) {
|
||||
this._quantityOfNodes = 0;
|
||||
}
|
||||
|
||||
this.updateQuantityLabel();
|
||||
this.updateQuantityOfNodes();
|
||||
},
|
||||
onIncrease:function (sender) {
|
||||
this._quantityOfNodes += NODES_INCREASE;
|
||||
if (this._quantityOfNodes > MAX_NODES) {
|
||||
this._quantityOfNodes = MAX_NODES
|
||||
}
|
||||
|
||||
this.updateQuantityLabel();
|
||||
this.updateQuantityOfNodes();
|
||||
},
|
||||
updateQuantityLabel:function () {
|
||||
if (this._quantityOfNodes != this._lastRenderedCount) {
|
||||
var infoLabel = this.getChildByTag(TAG_INFO_LAYER);
|
||||
var str = this._quantityOfNodes + " nodes";
|
||||
infoLabel.setString(str);
|
||||
|
||||
this._lastRenderedCount = this._quantityOfNodes;
|
||||
}
|
||||
},
|
||||
getQuantityOfNodes:function () {
|
||||
return this._quantityOfNodes;
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// IterateSpriteSheet
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var IterateSpriteSheet = NodeChildrenMainScene.extend({
|
||||
_batchNode:null,
|
||||
_profilingTimer:null,
|
||||
ctor:function () {
|
||||
if (cc.ENABLE_PROFILERS) {
|
||||
this._profilingTimer = new cc.ProfilingTimer();
|
||||
}
|
||||
},
|
||||
updateQuantityOfNodes:function () {
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
// increase nodes
|
||||
if (this._currentQuantityOfNodes < this._quantityOfNodes) {
|
||||
for (var i = 0; i < (this._quantityOfNodes - this._currentQuantityOfNodes); i++) {
|
||||
var sprite = cc.Sprite.createWithTexture(this._batchNode.getTexture(), cc.rect(0, 0, 32, 32));
|
||||
this._batchNode.addChild(sprite);
|
||||
sprite.setPosition(cc.p(cc.RANDOM_0_1() * s.width, cc.RANDOM_0_1() * s.height));
|
||||
}
|
||||
}
|
||||
|
||||
// decrease nodes
|
||||
else if (this._currentQuantityOfNodes > this._quantityOfNodes) {
|
||||
for (var i = 0; i < (this._currentQuantityOfNodes - this._quantityOfNodes); i++) {
|
||||
var index = this._currentQuantityOfNodes - i - 1;
|
||||
this._batchNode.removeChildAtIndex(index, true);
|
||||
}
|
||||
}
|
||||
|
||||
this._currentQuantityOfNodes = this._quantityOfNodes;
|
||||
},
|
||||
initWithQuantityOfNodes:function (nodes) {
|
||||
this._batchNode = cc.SpriteBatchNode.create("Images/spritesheet1.png");
|
||||
this.addChild(this._batchNode);
|
||||
|
||||
this._super(nodes);
|
||||
|
||||
if (cc.ENABLE_PROFILERS) {
|
||||
this._profilingTimer = cc.Profiler.timerWithName(this.profilerName(), this);
|
||||
}
|
||||
this.scheduleUpdate();
|
||||
},
|
||||
update:function (dt) {
|
||||
},
|
||||
profilerName:function () {
|
||||
return "none";
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// IterateSpriteSheetFastEnum
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var IterateSpriteSheetFastEnum = IterateSpriteSheet.extend({
|
||||
update:function (dt) {
|
||||
// iterate using fast enumeration protocol
|
||||
var children = this._batchNode.getChildren();
|
||||
|
||||
if (cc.ENABLE_PROFILERS) {
|
||||
cc.ProfilingBeginTimingBlock(this._profilingTimer);
|
||||
}
|
||||
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var sprite = children[i];
|
||||
sprite.setVisible(false);
|
||||
}
|
||||
|
||||
if (cc.ENABLE_PROFILERS) {
|
||||
cc.ProfilingEndTimingBlock(this._profilingTimer);
|
||||
}
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "A - Iterate SpriteSheet";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "Iterate children using Fast Enum API. See console";
|
||||
},
|
||||
profilerName:function () {
|
||||
return "iter fast enum";
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// IterateSpriteSheetCArray
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var IterateSpriteSheetCArray = IterateSpriteSheet.extend({
|
||||
update:function (dt) {
|
||||
// iterate using fast enumeration protocol
|
||||
var children = this._batchNode.getChildren();
|
||||
|
||||
if (cc.ENABLE_PROFILERS) {
|
||||
cc.ProfilingBeginTimingBlock(this._profilingTimer);
|
||||
}
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var sprite = children[i];
|
||||
sprite.setVisible(false);
|
||||
}
|
||||
|
||||
if (cc.ENABLE_PROFILERS) {
|
||||
cc.ProfilingEndTimingBlock(this._profilingTimer);
|
||||
}
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "B - Iterate SpriteSheet";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "Iterate children using Array API. See console";
|
||||
},
|
||||
profilerName:function () {
|
||||
return "iter c-array";
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// AddRemoveSpriteSheet
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var AddRemoveSpriteSheet = NodeChildrenMainScene.extend({
|
||||
_batchNode:null,
|
||||
ctor:function () {
|
||||
if (cc.ENABLE_PROFILERS) {
|
||||
this._profilingTimer = new cc.ProfilingTimer();
|
||||
}
|
||||
},
|
||||
updateQuantityOfNodes:function () {
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
// increase nodes
|
||||
if (this._currentQuantityOfNodes < this._quantityOfNodes) {
|
||||
for (var i = 0; i < (this._quantityOfNodes - this._currentQuantityOfNodes); i++) {
|
||||
var sprite = cc.Sprite.createWithTexture(this._batchNode.getTexture(), cc.rect(0, 0, 32, 32));
|
||||
this._batchNode.addChild(sprite);
|
||||
sprite.setPosition(cc.p(cc.RANDOM_0_1() * s.width, cc.RANDOM_0_1() * s.height));
|
||||
sprite.setVisible(false);
|
||||
}
|
||||
}
|
||||
// decrease nodes
|
||||
else if (this._currentQuantityOfNodes > this._quantityOfNodes) {
|
||||
for (var i = 0; i < (this._currentQuantityOfNodes - this._quantityOfNodes); i++) {
|
||||
var index = this._currentQuantityOfNodes - i - 1;
|
||||
this._batchNode.removeChildAtIndex(index, true);
|
||||
}
|
||||
}
|
||||
|
||||
this._currentQuantityOfNodes = this._quantityOfNodes;
|
||||
},
|
||||
initWithQuantityOfNodes:function (nodes) {
|
||||
this._batchNode = cc.SpriteBatchNode.create("Images/spritesheet1.png");
|
||||
this.addChild(this._batchNode);
|
||||
|
||||
this._super(nodes);
|
||||
|
||||
if (cc.ENABLE_PROFILERS) {
|
||||
this._profilingTimer = cc.Profiler.timerWithName(this.profilerName(), this);
|
||||
}
|
||||
|
||||
this.scheduleUpdate();
|
||||
},
|
||||
update:function (dt) {
|
||||
},
|
||||
profilerName:function () {
|
||||
return "none";
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// AddSpriteSheet
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var AddSpriteSheet = AddRemoveSpriteSheet.extend({
|
||||
update:function (dt) {
|
||||
// reset seed
|
||||
//srandom(0);
|
||||
|
||||
// 15 percent
|
||||
var totalToAdd = this._currentQuantityOfNodes * 0.15;
|
||||
|
||||
if (totalToAdd > 0) {
|
||||
var sprites = [];
|
||||
var zs = [];
|
||||
|
||||
// Don't include the sprite creation time and random as part of the profiling
|
||||
for (var i = 0; i < totalToAdd; i++) {
|
||||
var sprite = cc.Sprite.createWithTexture(this._batchNode.getTexture(), cc.rect(0, 0, 32, 32));
|
||||
sprites.push(sprite);
|
||||
zs[i] = cc.RANDOM_MINUS1_1() * 50;
|
||||
}
|
||||
|
||||
// add them with random Z (very important!)
|
||||
if (cc.ENABLE_PROFILERS)
|
||||
cc.ProfilingBeginTimingBlock(this._profilingTimer);
|
||||
}
|
||||
|
||||
for (var i = 0; i < totalToAdd; i++) {
|
||||
this._batchNode.addChild(sprites[i], zs[i], TAG_BASE + i);
|
||||
}
|
||||
|
||||
if (cc.ENABLE_PROFILERS) {
|
||||
cc.ProfilingEndTimingBlock(this._profilingTimer);
|
||||
}
|
||||
|
||||
// remove them
|
||||
for (var i = 0; i < totalToAdd; i++) {
|
||||
this._batchNode.removeChildByTag(TAG_BASE + i, true);
|
||||
}
|
||||
|
||||
delete zs;
|
||||
|
||||
},
|
||||
title:function () {
|
||||
return "C - Add to spritesheet";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "Adds %10 of total sprites with random z. See console";
|
||||
},
|
||||
profilerName:function () {
|
||||
return "add sprites";
|
||||
}
|
||||
})
|
||||
;
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// RemoveSpriteSheet
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var RemoveSpriteSheet = AddRemoveSpriteSheet.extend({
|
||||
update:function (dt) {
|
||||
//srandom(0);
|
||||
|
||||
// 15 percent
|
||||
var totalToAdd = this._currentQuantityOfNodes * 0.15;
|
||||
|
||||
if (totalToAdd > 0) {
|
||||
var sprites = [];
|
||||
|
||||
// Don't include the sprite creation time as part of the profiling
|
||||
for (var i = 0; i < totalToAdd; i++) {
|
||||
var sprite = cc.Sprite.createWithTexture(this._batchNode.getTexture(), cc.rect(0, 0, 32, 32));
|
||||
sprites.push(sprite);
|
||||
}
|
||||
|
||||
// add them with random Z (very important!)
|
||||
for (var i = 0; i < totalToAdd; i++) {
|
||||
this._batchNode.addChild(sprites[i], cc.RANDOM_MINUS1_1() * 50, TAG_BASE + i);
|
||||
}
|
||||
|
||||
// remove them
|
||||
if (cc.ENABLE_PROFILERS) {
|
||||
cc.ProfilingBeginTimingBlock(this._profilingTimer);
|
||||
}
|
||||
|
||||
for (var i = 0; i < totalToAdd; i++) {
|
||||
this._batchNode.removeChildByTag(TAG_BASE + i, true);
|
||||
}
|
||||
|
||||
if (cc.ENABLE_PROFILERS) {
|
||||
cc.ProfilingEndTimingBlock(this._profilingTimer);
|
||||
}
|
||||
}
|
||||
},
|
||||
title:function () {
|
||||
return "D - Del from spritesheet";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "Remove %10 of total sprites placed randomly. See console";
|
||||
},
|
||||
profilerName:function () {
|
||||
return "remove sprites";
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// ReorderSpriteSheet
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var ReorderSpriteSheet = AddRemoveSpriteSheet.extend({
|
||||
|
||||
update:function (dt) {
|
||||
//srandom(0);
|
||||
|
||||
// 15 percent
|
||||
var totalToAdd = this._currentQuantityOfNodes * 0.15;
|
||||
|
||||
if (totalToAdd > 0) {
|
||||
var sprites = [];
|
||||
|
||||
// Don't include the sprite creation time as part of the profiling
|
||||
for (var i = 0; i < totalToAdd; i++) {
|
||||
var sprite = cc.Sprite.createWithTexture(this._batchNode.getTexture(), cc.rect(0, 0, 32, 32));
|
||||
sprites.push(sprite);
|
||||
}
|
||||
|
||||
// add them with random Z (very important!)
|
||||
for (var i = 0; i < totalToAdd; i++) {
|
||||
this._batchNode.addChild(sprites[i], cc.RANDOM_MINUS1_1() * 50, TAG_BASE + i);
|
||||
}
|
||||
|
||||
// [this._batchNode sortAllChildren];
|
||||
|
||||
// reorder them
|
||||
if (cc.ENABLE_PROFILERS) {
|
||||
cc.ProfilingBeginTimingBlock(this._profilingTimer);
|
||||
}
|
||||
|
||||
for (var i = 0; i < totalToAdd; i++) {
|
||||
var node = this._batchNode.getChildren()[i];
|
||||
;
|
||||
this._batchNode.reorderChild(node, cc.RANDOM_MINUS1_1() * 50);
|
||||
}
|
||||
if (cc.ENABLE_PROFILERS) {
|
||||
cc.ProfilingEndTimingBlock(this._profilingTimer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// remove them
|
||||
for (var i = 0; i < totalToAdd; i++) {
|
||||
this._batchNode.removeChildByTag(TAG_BASE + i, true);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "E - Reorder from spritesheet";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "Reorder %10 of total sprites placed randomly. See console";
|
||||
},
|
||||
profilerName:function () {
|
||||
return "reorder sprites";
|
||||
}
|
||||
});
|
||||
|
||||
function runNodeChildrenTest() {
|
||||
var scene = new IterateSpriteSheetCArray();
|
||||
scene.initWithQuantityOfNodes(NODES_INCREASE);
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
}
|
|
@ -1,515 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
var TAG_PARTICLE_SYSTEM = 3;
|
||||
var TAG_LABEL_ATLAS = 4;
|
||||
var MAX_PARTICLES = 1000;
|
||||
var PARTICLE_NODES_INCREASE = 50;
|
||||
var s_nParCurIdx = 0;
|
||||
var TAG_PARTICLE_MENU_LAYER = 1000;
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// ParticleMenuLayer
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var ParticleMenuLayer = PerformBasicLayer.extend({
|
||||
_maxCases:4,
|
||||
showCurrentTest:function () {
|
||||
var scene = this.getParent();
|
||||
var subTest = scene.getSubTestNum();
|
||||
var parNum = scene.getParticlesNum();
|
||||
|
||||
var newScene = null;
|
||||
|
||||
switch (this._curCase) {
|
||||
case 0:
|
||||
newScene = new ParticlePerformTest1;
|
||||
break;
|
||||
case 1:
|
||||
newScene = new ParticlePerformTest2;
|
||||
break;
|
||||
case 2:
|
||||
newScene = new ParticlePerformTest3;
|
||||
break;
|
||||
case 3:
|
||||
newScene = new ParticlePerformTest4;
|
||||
break;
|
||||
}
|
||||
|
||||
s_nParCurIdx = this._curCase;
|
||||
if (newScene) {
|
||||
newScene.initWithSubTest(subTest, parNum);
|
||||
cc.Director.getInstance().replaceScene(newScene);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// ParticleMainScene
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var ParticleMainScene = cc.Scene.extend({
|
||||
_lastRenderedCount:null,
|
||||
_quantityParticles:null,
|
||||
_subtestNumber:null,
|
||||
initWithSubTest:function (asubtest, particles) {
|
||||
//srandom(0);
|
||||
|
||||
this._subtestNumber = asubtest;
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
this._lastRenderedCount = 0;
|
||||
this._quantityParticles = particles;
|
||||
|
||||
cc.MenuItemFont.setFontSize(65);
|
||||
var decrease = cc.MenuItemFont.create(" - ", this, this.onDecrease);
|
||||
decrease.setColor(cc.c3b(0, 200, 20));
|
||||
var increase = cc.MenuItemFont.create(" + ", this, this.onIncrease);
|
||||
increase.setColor(cc.c3b(0, 200, 20));
|
||||
|
||||
var menu = cc.Menu.create(decrease, increase, null);
|
||||
menu.alignItemsHorizontally();
|
||||
menu.setPosition(cc.p(s.width / 2, s.height / 2 + 15));
|
||||
this.addChild(menu, 1);
|
||||
|
||||
var infoLabel = cc.LabelTTF.create("0 nodes", "Marker Felt", 30);
|
||||
infoLabel.setColor(cc.c3b(0, 200, 20));
|
||||
infoLabel.setPosition(cc.p(s.width / 2, s.height - 90));
|
||||
this.addChild(infoLabel, 1, TAG_INFO_LAYER);
|
||||
|
||||
// particles on stage
|
||||
//var labelAtlas = cc.LabelAtlas.create("0000", "res/Images/fps_images.png", 16, 24, '.');
|
||||
var labelAtlas = cc.LabelTTF.create("0000", "Marker Felt", 30);
|
||||
this.addChild(labelAtlas, 0, TAG_LABEL_ATLAS);
|
||||
labelAtlas.setPosition(cc.p(s.width - 66, 50));
|
||||
|
||||
// Next Prev Test
|
||||
var menu = new ParticleMenuLayer(true, 4, s_nParCurIdx);
|
||||
this.addChild(menu, 1, TAG_PARTICLE_MENU_LAYER);
|
||||
|
||||
// Sub Tests
|
||||
cc.MenuItemFont.setFontSize(40);
|
||||
var subMenu = cc.Menu.create(null);
|
||||
for (var i = 1; i <= 3; ++i) {
|
||||
var str = i.toString();
|
||||
var itemFont = cc.MenuItemFont.create(str, this, this.testNCallback);
|
||||
itemFont.setTag(i);
|
||||
subMenu.addChild(itemFont, 10);
|
||||
|
||||
if (i <= 1) {
|
||||
itemFont.setColor(cc.c3b(200, 20, 20));
|
||||
}
|
||||
else {
|
||||
itemFont.setColor(cc.c3b(0, 200, 20));
|
||||
}
|
||||
}
|
||||
subMenu.alignItemsHorizontally();
|
||||
subMenu.setPosition(cc.p(s.width / 2, 80));
|
||||
this.addChild(subMenu, 2);
|
||||
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 40);
|
||||
this.addChild(label, 1);
|
||||
label.setPosition(cc.p(s.width / 2, s.height - 32));
|
||||
label.setColor(cc.c3b(255, 255, 40));
|
||||
|
||||
this.updateQuantityLabel();
|
||||
this.createParticleSystem();
|
||||
|
||||
this.schedule(this.step);
|
||||
},
|
||||
title:function () {
|
||||
return "No title";
|
||||
},
|
||||
|
||||
step:function (dt) {
|
||||
var atlas = this.getChildByTag(TAG_LABEL_ATLAS);
|
||||
var emitter = this.getChildByTag(TAG_PARTICLE_SYSTEM);
|
||||
|
||||
var str = emitter.getParticleCount();
|
||||
atlas.setString(str);
|
||||
},
|
||||
createParticleSystem:function () {
|
||||
var particleSystem = null;
|
||||
|
||||
/*
|
||||
* Tests:
|
||||
* 1 Quad Particle System using 32-bit textures (PNG)
|
||||
* 2: Quad Particle System using 16-bit textures (PNG)
|
||||
* 3: Quad Particle System using 8-bit textures (PNG)
|
||||
* 4: Quad Particle System using 4-bit textures (PVRTC)
|
||||
*/
|
||||
|
||||
this.removeChildByTag(TAG_PARTICLE_SYSTEM, true);
|
||||
|
||||
//todo
|
||||
// remove the "fire.png" from the TextureCache cache.
|
||||
var texture = cc.TextureCache.getInstance().addImage("res/Images/fire.png");
|
||||
cc.TextureCache.getInstance().removeTexture(texture);
|
||||
|
||||
particleSystem = new cc.ParticleSystemQuad();
|
||||
|
||||
switch (this._subtestNumber) {
|
||||
case 1:
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_2D_PIXEL_FORMAT_RGBA8888);
|
||||
particleSystem.initWithTotalParticles(this._quantityParticles);
|
||||
particleSystem.setTexture(cc.TextureCache.getInstance().addImage("res/Images/fire.png"));
|
||||
break;
|
||||
case 2:
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_2D_PIXEL_FORMAT_RGBA4444);
|
||||
particleSystem.initWithTotalParticles(this._quantityParticles);
|
||||
particleSystem.setTexture(cc.TextureCache.getInstance().addImage("res/Images/fire.png"));
|
||||
break;
|
||||
case 3:
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_2D_PIXEL_FORMAT_A8);
|
||||
particleSystem.initWithTotalParticles(this._quantityParticles);
|
||||
particleSystem.setTexture(cc.TextureCache.getInstance().addImage("res/Images/fire.png"));
|
||||
break;
|
||||
default:
|
||||
particleSystem = null;
|
||||
cc.log("Shall not happen!");
|
||||
break;
|
||||
}
|
||||
this.addChild(particleSystem, 0, TAG_PARTICLE_SYSTEM);
|
||||
|
||||
this.doTest();
|
||||
|
||||
// restore the default pixel format
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_2D_PIXEL_FORMAT_RGBA8888);
|
||||
},
|
||||
onDecrease:function (sender) {
|
||||
this._quantityParticles -= PARTICLE_NODES_INCREASE;
|
||||
if (this._quantityParticles < 0)
|
||||
this._quantityParticles = 0;
|
||||
|
||||
this.updateQuantityLabel();
|
||||
this.createParticleSystem();
|
||||
},
|
||||
onIncrease:function (sender) {
|
||||
this._quantityParticles += PARTICLE_NODES_INCREASE;
|
||||
if (this._quantityParticles > MAX_PARTICLES) {
|
||||
this._quantityParticles = MAX_PARTICLES;
|
||||
}
|
||||
this.updateQuantityLabel();
|
||||
this.createParticleSystem();
|
||||
},
|
||||
testNCallback:function (sender) {
|
||||
this._subtestNumber = sender.getTag();
|
||||
var menu = this.getChildByTag(TAG_PARTICLE_MENU_LAYER);
|
||||
menu.restartCallback(sender);
|
||||
},
|
||||
updateQuantityLabel:function () {
|
||||
if (this._quantityParticles != this._lastRenderedCount) {
|
||||
var infoLabel = this.getChildByTag(TAG_INFO_LAYER);
|
||||
var str = this._quantityParticles + " particles";
|
||||
infoLabel.setString(str);
|
||||
|
||||
this._lastRenderedCount = this._quantityParticles;
|
||||
}
|
||||
},
|
||||
getSubTestNum:function () {
|
||||
return this._subtestNumber;
|
||||
},
|
||||
getParticlesNum:function () {
|
||||
return this._quantityParticles;
|
||||
},
|
||||
doTest:function () {
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// ParticlePerformTest1
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var ParticlePerformTest1 = ParticleMainScene.extend({
|
||||
|
||||
title:function () {
|
||||
return "A " + this._subtestNumber + " size=4";
|
||||
},
|
||||
doTest:function () {
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
var particleSystem = this.getChildByTag(TAG_PARTICLE_SYSTEM);
|
||||
|
||||
// duration
|
||||
particleSystem.setDuration(-1);
|
||||
|
||||
// gravity
|
||||
particleSystem.setGravity(cc.p(0, -90));
|
||||
|
||||
// angle
|
||||
particleSystem.setAngle(90);
|
||||
particleSystem.setAngleVar(0);
|
||||
|
||||
// radial
|
||||
particleSystem.setRadialAccel(0);
|
||||
particleSystem.setRadialAccelVar(0);
|
||||
|
||||
// speed of particles
|
||||
particleSystem.setSpeed(180);
|
||||
particleSystem.setSpeedVar(50);
|
||||
|
||||
// emitter position
|
||||
particleSystem.setPosition(cc.p(s.width / 2, 100));
|
||||
particleSystem.setPosVar(cc.p(s.width / 2, 0));
|
||||
|
||||
// life of particles
|
||||
particleSystem.setLife(2.0);
|
||||
particleSystem.setLifeVar(1);
|
||||
|
||||
// emits per frame
|
||||
particleSystem.setEmissionRate(particleSystem.getTotalParticles() / particleSystem.getLife());
|
||||
|
||||
// color of particles
|
||||
var startColor = new cc.Color4F(0.5, 0.5, 0.5, 1.0);
|
||||
particleSystem.setStartColor(startColor);
|
||||
|
||||
var startColorVar = new cc.Color4F(0.5, 0.5, 0.5, 1.0);
|
||||
particleSystem.setStartColorVar(startColorVar);
|
||||
|
||||
var endColor = new cc.Color4F(0.1, 0.1, 0.1, 0.2);
|
||||
particleSystem.setEndColor(endColor);
|
||||
|
||||
var endColorVar = new cc.Color4F(0.1, 0.1, 0.1, 0.2);
|
||||
particleSystem.setEndColorVar(endColorVar);
|
||||
|
||||
// size, in pixels
|
||||
particleSystem.setEndSize(4.0);
|
||||
particleSystem.setStartSize(4.0);
|
||||
particleSystem.setEndSizeVar(0);
|
||||
particleSystem.setStartSizeVar(0);
|
||||
|
||||
// additive
|
||||
particleSystem.setBlendAdditive(false);
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// ParticlePerformTest2
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var ParticlePerformTest2 = ParticleMainScene.extend({
|
||||
|
||||
title:function () {
|
||||
return "B " + this._subtestNumber + " size=8";
|
||||
},
|
||||
doTest:function () {
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
var particleSystem = this.getChildByTag(TAG_PARTICLE_SYSTEM);
|
||||
|
||||
// duration
|
||||
particleSystem.setDuration(-1);
|
||||
|
||||
// gravity
|
||||
particleSystem.setGravity(cc.p(0, -90));
|
||||
|
||||
// angle
|
||||
particleSystem.setAngle(90);
|
||||
particleSystem.setAngleVar(0);
|
||||
|
||||
// radial
|
||||
particleSystem.setRadialAccel(0);
|
||||
particleSystem.setRadialAccelVar(0);
|
||||
|
||||
// speed of particles
|
||||
particleSystem.setSpeed(180);
|
||||
particleSystem.setSpeedVar(50);
|
||||
|
||||
// emitter position
|
||||
particleSystem.setPosition(cc.p(s.width / 2, 100));
|
||||
particleSystem.setPosVar(cc.p(s.width / 2, 0));
|
||||
|
||||
// life of particles
|
||||
particleSystem.setLife(2.0);
|
||||
particleSystem.setLifeVar(1);
|
||||
|
||||
// emits per frame
|
||||
particleSystem.setEmissionRate(particleSystem.getTotalParticles() / particleSystem.getLife());
|
||||
|
||||
// color of particles
|
||||
var startColor = new cc.Color4F(0.5, 0.5, 0.5, 1.0);
|
||||
particleSystem.setStartColor(startColor);
|
||||
|
||||
var startColorVar = new cc.Color4F(0.5, 0.5, 0.5, 1.0);
|
||||
particleSystem.setStartColorVar(startColorVar);
|
||||
|
||||
var endColor = new cc.Color4F(0.1, 0.1, 0.1, 0.2);
|
||||
particleSystem.setEndColor(endColor);
|
||||
|
||||
var endColorVar = new cc.Color4F(0.1, 0.1, 0.1, 0.2);
|
||||
particleSystem.setEndColorVar(endColorVar);
|
||||
|
||||
// size, in pixels
|
||||
particleSystem.setEndSize(8.0);
|
||||
particleSystem.setStartSize(8.0);
|
||||
particleSystem.setEndSizeVar(0);
|
||||
particleSystem.setStartSizeVar(0);
|
||||
|
||||
// additive
|
||||
particleSystem.setBlendAdditive(false);
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// ParticlePerformTest3
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var ParticlePerformTest3 = ParticleMainScene.extend({
|
||||
|
||||
title:function () {
|
||||
return "C " + this._subtestNumber + " size=32";
|
||||
},
|
||||
doTest:function () {
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
var particleSystem = this.getChildByTag(TAG_PARTICLE_SYSTEM);
|
||||
|
||||
// duration
|
||||
particleSystem.setDuration(-1);
|
||||
|
||||
// gravity
|
||||
particleSystem.setGravity(cc.p(0, -90));
|
||||
|
||||
// angle
|
||||
particleSystem.setAngle(90);
|
||||
particleSystem.setAngleVar(0);
|
||||
|
||||
// radial
|
||||
particleSystem.setRadialAccel(0);
|
||||
particleSystem.setRadialAccelVar(0);
|
||||
|
||||
// speed of particles
|
||||
particleSystem.setSpeed(180);
|
||||
particleSystem.setSpeedVar(50);
|
||||
|
||||
// emitter position
|
||||
particleSystem.setPosition(cc.p(s.width / 2, 100));
|
||||
particleSystem.setPosVar(cc.p(s.width / 2, 0));
|
||||
|
||||
// life of particles
|
||||
particleSystem.setLife(2.0);
|
||||
particleSystem.setLifeVar(1);
|
||||
|
||||
// emits per frame
|
||||
particleSystem.setEmissionRate(particleSystem.getTotalParticles() / particleSystem.getLife());
|
||||
|
||||
// color of particles
|
||||
var startColor = new cc.Color4F(0.5, 0.5, 0.5, 1.0);
|
||||
particleSystem.setStartColor(startColor);
|
||||
|
||||
var startColorVar = new cc.Color4F(0.5, 0.5, 0.5, 1.0);
|
||||
particleSystem.setStartColorVar(startColorVar);
|
||||
|
||||
var endColor = new cc.Color4F(0.1, 0.1, 0.1, 0.2);
|
||||
particleSystem.setEndColor(endColor);
|
||||
|
||||
var endColorVar = new cc.Color4F(0.1, 0.1, 0.1, 0.2);
|
||||
particleSystem.setEndColorVar(endColorVar);
|
||||
|
||||
// size, in pixels
|
||||
particleSystem.setEndSize(32.0);
|
||||
particleSystem.setStartSize(32.0);
|
||||
particleSystem.setEndSizeVar(0);
|
||||
particleSystem.setStartSizeVar(0);
|
||||
|
||||
// additive
|
||||
particleSystem.setBlendAdditive(false);
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// ParticlePerformTest4
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var ParticlePerformTest4 = ParticleMainScene.extend({
|
||||
|
||||
title:function () {
|
||||
return "D " + this._subtestNumber + " size=64";
|
||||
},
|
||||
doTest:function () {
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
var particleSystem = this.getChildByTag(TAG_PARTICLE_SYSTEM);
|
||||
|
||||
// duration
|
||||
particleSystem.setDuration(-1);
|
||||
|
||||
// gravity
|
||||
particleSystem.setGravity(cc.p(0, -90));
|
||||
|
||||
// angle
|
||||
particleSystem.setAngle(90);
|
||||
particleSystem.setAngleVar(0);
|
||||
|
||||
// radial
|
||||
particleSystem.setRadialAccel(0);
|
||||
particleSystem.setRadialAccelVar(0);
|
||||
|
||||
// speed of particles
|
||||
particleSystem.setSpeed(180);
|
||||
particleSystem.setSpeedVar(50);
|
||||
|
||||
// emitter position
|
||||
particleSystem.setPosition(cc.p(s.width / 2, 100));
|
||||
particleSystem.setPosVar(cc.p(s.width / 2, 0));
|
||||
|
||||
// life of particles
|
||||
particleSystem.setLife(2.0);
|
||||
particleSystem.setLifeVar(1);
|
||||
|
||||
// emits per frame
|
||||
particleSystem.setEmissionRate(particleSystem.getTotalParticles() / particleSystem.getLife());
|
||||
|
||||
// color of particles
|
||||
var startColor = new cc.Color4F(0.5, 0.5, 0.5, 1.0);
|
||||
particleSystem.setStartColor(startColor);
|
||||
|
||||
var startColorVar = new cc.Color4F(0.5, 0.5, 0.5, 1.0);
|
||||
particleSystem.setStartColorVar(startColorVar);
|
||||
|
||||
var endColor = new cc.Color4F(0.1, 0.1, 0.1, 0.2);
|
||||
particleSystem.setEndColor(endColor);
|
||||
|
||||
var endColorVar = new cc.Color4F(0.1, 0.1, 0.1, 0.2);
|
||||
particleSystem.setEndColorVar(endColorVar);
|
||||
|
||||
// size, in pixels
|
||||
particleSystem.setEndSize(64.0);
|
||||
particleSystem.setStartSize(64.0);
|
||||
particleSystem.setEndSizeVar(0);
|
||||
particleSystem.setStartSizeVar(0);
|
||||
|
||||
// additive
|
||||
particleSystem.setBlendAdditive(false);
|
||||
}
|
||||
});
|
||||
|
||||
function runParticleTest() {
|
||||
var scene = new ParticlePerformTest1;
|
||||
scene.initWithSubTest(1, PARTICLE_NODES_INCREASE);
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
}
|
|
@ -1,576 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
var MAX_SPRITES = 1000;
|
||||
var SPRITES_INCREASE = 50;
|
||||
|
||||
var TAG_INFO_LAYER = 1;
|
||||
var TAG_MAIN_LAYER = 2;
|
||||
var TAG_SPRITE_MENU_LAYER = (MAX_SPRITES + 1000);
|
||||
|
||||
var s_nSpriteCurCase = 0;
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// SubTest
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var SubTest = cc.Class.extend({
|
||||
_subtestNumber:null,
|
||||
_batchNode:null,
|
||||
_parent:null,
|
||||
removeByTag:function (tag) {
|
||||
switch (this._subtestNumber) {
|
||||
case 1:
|
||||
case 4:
|
||||
case 7:
|
||||
this._parent.removeChildByTag(tag + 100, true);
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
case 5:
|
||||
case 6:
|
||||
case 8:
|
||||
case 9:
|
||||
this._batchNode.removeChildAtIndex(tag, true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
},
|
||||
createSpriteWithTag:function (tag) {
|
||||
// create
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_PIXELFORMAT_RGBA8888);
|
||||
|
||||
var sprite = null;
|
||||
switch (this._subtestNumber) {
|
||||
case 1:
|
||||
{
|
||||
sprite = cc.Sprite.create("Images/grossinis_sister1.png");
|
||||
this._parent.addChild(sprite, 0, tag + 100);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
case 3:
|
||||
{
|
||||
sprite = cc.Sprite.createWithTexture(this._batchNode.getTexture(), cc.rect(0, 0, 52, 139));
|
||||
this._batchNode.addChild(sprite, 0, tag + 100);
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
var idx = parseInt(cc.RANDOM_0_1() * 14) + 1;
|
||||
idx = idx < 10 ? "0" + idx : idx.toString();
|
||||
var str = "Images/grossini_dance_" + idx + ".png";
|
||||
sprite = cc.Sprite.create(str);
|
||||
this._parent.addChild(sprite, 0, tag + 100);
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
case 6:
|
||||
{
|
||||
var idx = 0 | (cc.RANDOM_0_1() * 14);
|
||||
var x = (idx % 5) * 85;
|
||||
var y = (0 | (idx / 5)) * 121;
|
||||
sprite = cc.Sprite.createWithTexture(this._batchNode.getTexture(), cc.rect(x, y, 85, 121));
|
||||
this._batchNode.addChild(sprite, 0, tag + 100);
|
||||
break;
|
||||
}
|
||||
|
||||
case 7:
|
||||
{
|
||||
var y, x;
|
||||
var r = 0 | (cc.RANDOM_0_1() * 64);
|
||||
|
||||
y = parseInt(r / 8);
|
||||
x = parseInt(r % 8);
|
||||
|
||||
var str = "Images/sprites_test/sprite-" + x + "-" + y + ".png";
|
||||
sprite = cc.Sprite.create(str);
|
||||
this._parent.addChild(sprite, 0, tag + 100);
|
||||
break;
|
||||
}
|
||||
|
||||
case 8:
|
||||
case 9:
|
||||
{
|
||||
var y, x;
|
||||
var r = 0 | (cc.RANDOM_0_1() * 64);
|
||||
|
||||
y = (0 | (r / 8)) * 32;
|
||||
x = (r % 8) * 32;
|
||||
sprite = cc.Sprite.createWithTexture(this._batchNode.getTexture(), cc.rect(x, y, 32, 32));
|
||||
this._batchNode.addChild(sprite, 0, tag + 100);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_PIXELFORMAT_DEFAULT);
|
||||
|
||||
return sprite;
|
||||
},
|
||||
initWithSubTest:function (subTest, p) {
|
||||
this._subtestNumber = subTest;
|
||||
this._parent = p;
|
||||
this._batchNode = null;
|
||||
/*
|
||||
* Tests:
|
||||
* 1: 1 (32-bit) PNG sprite of 52 x 139
|
||||
* 2: 1 (32-bit) PNG Batch Node using 1 sprite of 52 x 139
|
||||
* 3: 1 (16-bit) PNG Batch Node using 1 sprite of 52 x 139
|
||||
* 4: 1 (4-bit) PVRTC Batch Node using 1 sprite of 52 x 139
|
||||
|
||||
* 5: 14 (32-bit) PNG sprites of 85 x 121 each
|
||||
* 6: 14 (32-bit) PNG Batch Node of 85 x 121 each
|
||||
* 7: 14 (16-bit) PNG Batch Node of 85 x 121 each
|
||||
* 8: 14 (4-bit) PVRTC Batch Node of 85 x 121 each
|
||||
|
||||
* 9: 64 (32-bit) sprites of 32 x 32 each
|
||||
*10: 64 (32-bit) PNG Batch Node of 32 x 32 each
|
||||
*11: 64 (16-bit) PNG Batch Node of 32 x 32 each
|
||||
*12: 64 (4-bit) PVRTC Batch Node of 32 x 32 each
|
||||
*/
|
||||
|
||||
// purge textures
|
||||
log("initWithSubTest 01");
|
||||
var mgr = cc.TextureCache.getInstance();
|
||||
log("initWithSubTest 02");
|
||||
// [mgr removeAllTextures];
|
||||
mgr.removeTexture(mgr.addImage("Images/grossinis_sister1.png"));
|
||||
mgr.removeTexture(mgr.addImage("Images/grossini_dance_atlas.png"));
|
||||
mgr.removeTexture(mgr.addImage("Images/spritesheet1.png"));
|
||||
log("initWithSubTest 03");
|
||||
switch (this._subtestNumber) {
|
||||
case 1:
|
||||
case 4:
|
||||
case 7:
|
||||
break;
|
||||
///
|
||||
case 2:
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_PIXELFORMAT_RGBA8888);
|
||||
this._batchNode = cc.SpriteBatchNode.create("Images/grossinis_sister1.png", 100);
|
||||
p.addChild(this._batchNode, 0);
|
||||
break;
|
||||
case 3:
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_PIXELFORMAT_RGBA4444);
|
||||
this._batchNode = cc.SpriteBatchNode.create("Images/grossinis_sister1.png", 100);
|
||||
p.addChild(this._batchNode, 0);
|
||||
break;
|
||||
|
||||
///
|
||||
case 5:
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_PIXELFORMAT_RGBA8888);
|
||||
this._batchNode = cc.SpriteBatchNode.create("Images/grossini_dance_atlas.png", 100);
|
||||
p.addChild(this._batchNode, 0);
|
||||
break;
|
||||
case 6:
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_PIXELFORMAT_RGBA4444);
|
||||
this._batchNode = cc.SpriteBatchNode.create("Images/grossini_dance_atlas.png", 100);
|
||||
p.addChild(this._batchNode, 0);
|
||||
break;
|
||||
|
||||
///
|
||||
case 8:
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_PIXELFORMAT_RGBA8888);
|
||||
this._batchNode = cc.SpriteBatchNode.create("Images/spritesheet1.png", 100);
|
||||
p.addChild(this._batchNode, 0);
|
||||
break;
|
||||
case 9:
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_PIXELFORMAT_RGBA4444);
|
||||
this._batchNode = cc.SpriteBatchNode.create("Images/spritesheet1.png", 100);
|
||||
p.addChild(this._batchNode, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
log("initWithSubTest 04");
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_PIXELFORMAT_DEFAULT);
|
||||
log("initWithSubTest 05");
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// SpriteMenuLayer
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var SpriteMenuLayer = PerformBasicLayer.extend({
|
||||
_maxCases:7,
|
||||
showCurrentTest:function () {
|
||||
var scene = null;
|
||||
var preScene = this.getParent();
|
||||
var subTest = preScene.getSubTestNum();
|
||||
var nodes = preScene.getNodesNum();
|
||||
|
||||
switch (this._curCase) {
|
||||
case 0:
|
||||
scene = new SpritePerformTest1();
|
||||
break;
|
||||
case 1:
|
||||
scene = new SpritePerformTest2();
|
||||
break;
|
||||
case 2:
|
||||
scene = new SpritePerformTest3();
|
||||
break;
|
||||
case 3:
|
||||
scene = new SpritePerformTest4();
|
||||
break;
|
||||
case 4:
|
||||
scene = new SpritePerformTest5();
|
||||
break;
|
||||
case 5:
|
||||
scene = new SpritePerformTest6();
|
||||
break;
|
||||
case 6:
|
||||
scene = new SpritePerformTest7();
|
||||
break;
|
||||
}
|
||||
s_nSpriteCurCase = this._curCase;
|
||||
|
||||
if (scene) {
|
||||
scene.initWithSubTest(subTest, nodes);
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// SpriteMainScene
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var SpriteMainScene = cc.Scene.extend({
|
||||
_lastRenderedCount:null,
|
||||
_quantityNodes:null,
|
||||
_subTest:null,
|
||||
_subtestNumber:1,
|
||||
|
||||
ctor:function () {
|
||||
var parent = new cc.Scene();
|
||||
__associateObjWithNative(this, parent);
|
||||
this.init();
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "No title";
|
||||
},
|
||||
initWithSubTest:function (asubtest, nodes) {
|
||||
this._subtestNumber = asubtest;
|
||||
this._subTest = new SubTest();
|
||||
this._subTest.initWithSubTest(asubtest, this);
|
||||
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
this._lastRenderedCount = 0;
|
||||
this._quantityNodes = 0;
|
||||
|
||||
// add title label
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 40);
|
||||
this.addChild(label, 1);
|
||||
label.setPosition(cc.p(s.width / 2, s.height - 32));
|
||||
label.setColor(cc.c3b(255, 255, 40));
|
||||
|
||||
cc.MenuItemFont.setFontSize(65);
|
||||
var decrease = cc.MenuItemFont.create(" - ", this, this.onDecrease);
|
||||
decrease.setColor(cc.c3b(0, 200, 20));
|
||||
var increase = cc.MenuItemFont.create(" + ", this, this.onIncrease);
|
||||
increase.setColor(cc.c3b(0, 200, 20));
|
||||
|
||||
var menu = cc.Menu.create(decrease, increase);
|
||||
menu.alignItemsHorizontally();
|
||||
|
||||
menu.setPosition(cc.p(s.width / 2, s.height - 65));
|
||||
this.addChild(menu, 1);
|
||||
|
||||
var infoLabel = cc.LabelTTF.create("0 nodes", "Marker Felt", 30);
|
||||
infoLabel.setColor(cc.c3b(0, 200, 20));
|
||||
infoLabel.setPosition(cc.p(s.width / 2, s.height - 90));
|
||||
this.addChild(infoLabel, 1, TAG_INFO_LAYER);
|
||||
|
||||
// add menu
|
||||
var menu = new SpriteMenuLayer(true, 7, s_nSpriteCurCase);
|
||||
this.addChild(menu, 1, TAG_SPRITE_MENU_LAYER);
|
||||
|
||||
// Sub Tests
|
||||
cc.MenuItemFont.setFontSize(32);
|
||||
var subMenu = cc.Menu.create();
|
||||
for (var i = 1; i <= 9; ++i) {
|
||||
var text = i.toString();
|
||||
var itemFont = cc.MenuItemFont.create(text, this, this.testNCallback);
|
||||
itemFont.setTag(i);
|
||||
subMenu.addChild(itemFont, 10);
|
||||
|
||||
if (i <= 3)
|
||||
itemFont.setColor(cc.c3b(200, 20, 20));
|
||||
else if (i <= 6)
|
||||
itemFont.setColor(cc.c3b(0, 200, 20));
|
||||
else
|
||||
itemFont.setColor(cc.c3b(0, 20, 200));
|
||||
}
|
||||
|
||||
subMenu.alignItemsHorizontally();
|
||||
subMenu.setPosition(cc.p(s.width / 2, 80));
|
||||
this.addChild(subMenu, 2);
|
||||
|
||||
while (this._quantityNodes < nodes) {
|
||||
this.onIncrease(this);
|
||||
}
|
||||
},
|
||||
updateNodes:function () {
|
||||
if (this._quantityNodes != this._lastRenderedCount) {
|
||||
var infoLabel = this.getChildByTag(TAG_INFO_LAYER);
|
||||
var str = this._quantityNodes + " nodes";
|
||||
infoLabel.setString(str);
|
||||
|
||||
this._lastRenderedCount = this._quantityNodes;
|
||||
}
|
||||
},
|
||||
testNCallback:function (sender) {
|
||||
this._subtestNumber = sender.getTag();
|
||||
var menu = this.getChildByTag(TAG_SPRITE_MENU_LAYER);
|
||||
menu.restartCallback(sender);
|
||||
},
|
||||
onIncrease:function (sender) {
|
||||
if (this._quantityNodes >= MAX_SPRITES)
|
||||
return;
|
||||
|
||||
for (var i = 0; i < SPRITES_INCREASE; i++) {
|
||||
var sprite = this._subTest.createSpriteWithTag(this._quantityNodes);
|
||||
this.doTest(sprite);
|
||||
this._quantityNodes++;
|
||||
}
|
||||
|
||||
this.updateNodes();
|
||||
},
|
||||
onDecrease:function (sender) {
|
||||
if (this._quantityNodes <= 0)
|
||||
return;
|
||||
|
||||
for (var i = 0; i < SPRITES_INCREASE; i++) {
|
||||
this._quantityNodes--;
|
||||
this._subTest.removeByTag(this._quantityNodes);
|
||||
}
|
||||
|
||||
this.updateNodes();
|
||||
},
|
||||
|
||||
doTest:function (sprite) {
|
||||
|
||||
},
|
||||
|
||||
getSubTestNum:function () {
|
||||
return this._subtestNumber
|
||||
},
|
||||
getNodesNum:function () {
|
||||
return this._quantityNodes
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// For test functions
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
function performanceActions(sprite) {
|
||||
var size = cc.Director.getInstance().getWinSize();
|
||||
sprite.setPosition(cc.p(parseInt(Math.random() * size.width), parseInt(Math.random() * size.height)));
|
||||
|
||||
var period = 0.5 + (Math.random() * 1000) / 500.0;
|
||||
var rot = cc.RotateBy.create(period, 360.0 * cc.RANDOM_0_1());
|
||||
var rot_back = rot.reverse();
|
||||
var permanentRotation = cc.RepeatForever.create(cc.Sequence.create(rot, rot_back));
|
||||
sprite.runAction(permanentRotation);
|
||||
|
||||
var growDuration = 0.5 + (Math.random() * 1000) / 500.0;
|
||||
var grow = cc.ScaleBy.create(growDuration, 0.5, 0.5);
|
||||
var permanentScaleLoop = cc.RepeatForever.create(cc.Sequence.create(grow, grow.reverse()));
|
||||
sprite.runAction(permanentScaleLoop);
|
||||
}
|
||||
|
||||
function performanceActions20(sprite) {
|
||||
var size = cc.Director.getInstance().getWinSize();
|
||||
if (cc.RANDOM_0_1() < 0.2)
|
||||
sprite.setPosition(cc.p(parseInt(Math.random() * size.width), parseInt(Math.random() * size.height)));
|
||||
else
|
||||
sprite.setPosition(cc.p(-1000, -1000));
|
||||
|
||||
var period = 0.5 + (Math.random() * 1000) / 500.0;
|
||||
var rot = cc.RotateBy.create(period, 360.0 * cc.RANDOM_0_1());
|
||||
var rot_back = rot.reverse();
|
||||
var permanentRotation = cc.RepeatForever.create(cc.Sequence.create(rot, rot_back));
|
||||
sprite.runAction(permanentRotation);
|
||||
|
||||
var growDuration = 0.5 + (Math.random() * 1000) / 500.0;
|
||||
var grow = cc.ScaleBy.create(growDuration, 0.5, 0.5);
|
||||
var permanentScaleLoop = cc.RepeatForever.create(cc.Sequence.create(grow, grow.reverse()));
|
||||
sprite.runAction(permanentScaleLoop);
|
||||
}
|
||||
|
||||
function performanceRotationScale(sprite) {
|
||||
var size = cc.Director.getInstance().getWinSize();
|
||||
sprite.setPosition(cc.p(parseInt(Math.random() * size.width), parseInt(Math.random() * size.height)));
|
||||
sprite.setRotation(cc.RANDOM_0_1() * 360);
|
||||
sprite.setScale(cc.RANDOM_0_1() * 2);
|
||||
}
|
||||
|
||||
function performancePosition(sprite) {
|
||||
var size = cc.Director.getInstance().getWinSize();
|
||||
log("performancePosition 01");
|
||||
sprite.setPosition(cc.p(parseInt(Math.random() * size.width), parseInt(Math.random() * size.height)));
|
||||
log("performancePosition 02");
|
||||
}
|
||||
|
||||
function performanceout20(sprite) {
|
||||
var size = cc.Director.getInstance().getWinSize();
|
||||
|
||||
if (cc.RANDOM_0_1() < 0.2)
|
||||
sprite.setPosition(cc.p(parseInt(Math.random() * size.width), parseInt(Math.random() * size.height)));
|
||||
else
|
||||
sprite.setPosition(cc.p(-1000, -1000));
|
||||
}
|
||||
|
||||
function performanceOut100(sprite) {
|
||||
sprite.setPosition(cc.p(-1000, -1000));
|
||||
}
|
||||
|
||||
function performanceScale(sprite) {
|
||||
var size = cc.Director.getInstance().getWinSize();
|
||||
sprite.setPosition(cc.p(parseInt(Math.random() * size.width), parseInt(Math.random() * size.height)));
|
||||
sprite.setScale(cc.RANDOM_0_1() * 100 / 50);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// SpritePerformTest1
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var SpritePerformTest1 = SpriteMainScene.extend({
|
||||
doTest:function (sprite) {
|
||||
performancePosition(sprite);
|
||||
},
|
||||
title:function () {
|
||||
return "A (" + this._subtestNumber + ") position";
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// SpritePerformTest2
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var SpritePerformTest2 = SpriteMainScene.extend({
|
||||
doTest:function (sprite) {
|
||||
performanceScale(sprite);
|
||||
},
|
||||
title:function () {
|
||||
return "B (" + this._subtestNumber + ") scale";
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// SpritePerformTest3
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var SpritePerformTest3 = SpriteMainScene.extend({
|
||||
doTest:function (sprite) {
|
||||
performanceRotationScale(sprite);
|
||||
},
|
||||
title:function () {
|
||||
return "C (" + this._subtestNumber + ") scale + rot";
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// SpritePerformTest4
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var SpritePerformTest4 = SpriteMainScene.extend({
|
||||
doTest:function (sprite) {
|
||||
performanceOut100(sprite);
|
||||
},
|
||||
title:function () {
|
||||
return "D (" + this._subtestNumber + ") 100% out";
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// SpritePerformTest5
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var SpritePerformTest5 = SpriteMainScene.extend({
|
||||
doTest:function (sprite) {
|
||||
performanceout20(sprite);
|
||||
},
|
||||
title:function () {
|
||||
return "E (" + this._subtestNumber + ") 80% out";
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// SpritePerformTest6
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var SpritePerformTest6 = SpriteMainScene.extend({
|
||||
doTest:function (sprite) {
|
||||
performanceActions(sprite);
|
||||
},
|
||||
title:function () {
|
||||
return "F (" + this._subtestNumber + ") actions";
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// SpritePerformTest7
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var SpritePerformTest7 = SpriteMainScene.extend({
|
||||
doTest:function (sprite) {
|
||||
performanceActions20(sprite);
|
||||
},
|
||||
title:function () {
|
||||
return "G (" + this._subtestNumber + ") actions 80% out";
|
||||
}
|
||||
});
|
||||
|
||||
function runSpriteTest() {
|
||||
log("runSpriteTest 01");
|
||||
var scene = new SpritePerformTest1;
|
||||
log("runSpriteTest 02");
|
||||
scene.initWithSubTest(1, 50);
|
||||
log("runSpriteTest 03");
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
log("runSpriteTest 04");
|
||||
}
|
|
@ -1,188 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
require("js/PerformanceTest/testResource.js");
|
||||
require("js/PerformanceTest/testbasic.js");
|
||||
|
||||
/*
|
||||
require("js/PerformanceTest/PerformanceParticleTest.js");
|
||||
require("js/PerformanceTest/PerformanceTextureTest.js");
|
||||
*/
|
||||
|
||||
var ITEM_TAG_BASIC = 1000;
|
||||
var nCurCase = 0;
|
||||
|
||||
var PerformanceTests = [
|
||||
"PerformanceNodeChildrenTest",
|
||||
"PerformanceParticleTest",
|
||||
"PerformanceSpriteTest",
|
||||
"PerformanceTextureTest",
|
||||
"PerformanceTouchesTest"
|
||||
];
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// PerformanceMainLayer
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var PerformanceMainLayer = cc.Layer.extend({
|
||||
ctor:function () {
|
||||
var parent = new cc.Layer();
|
||||
__associateObjWithNative(this, parent);
|
||||
this.init();
|
||||
},
|
||||
|
||||
onEnter:function () {
|
||||
//this._super();
|
||||
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
var menu = cc.Menu.create();
|
||||
menu.setPosition(cc.POINT_ZERO);
|
||||
cc.MenuItemFont.setFontName("Arial");
|
||||
cc.MenuItemFont.setFontSize(24);
|
||||
|
||||
for (var i = 0; i < PerformanceTests.length; i++) {
|
||||
var pItem = cc.MenuItemFont.create(PerformanceTests[i], this, this.menuCallback);
|
||||
pItem.setPosition(cc.p(s.width / 2, s.height - (i + 1) * LINE_SPACE));
|
||||
menu.addChild(pItem, ITEM_TAG_BASIC + i);
|
||||
}
|
||||
|
||||
this.addChild(menu);
|
||||
},
|
||||
menuCallback:function (sender) {
|
||||
var index = sender.getZOrder() - ITEM_TAG_BASIC;
|
||||
|
||||
// create the test scene and run it
|
||||
switch (index) {
|
||||
case 0:
|
||||
require("js/PerformanceTest/PerformanceNodeChildrenTest.js");
|
||||
runNodeChildrenTest();
|
||||
break;
|
||||
case 1:
|
||||
//runParticleTest();
|
||||
break;
|
||||
case 2:
|
||||
require("js/PerformanceTest/PerformanceSpriteTest.js");
|
||||
runSpriteTest();
|
||||
break;
|
||||
case 3:
|
||||
//runTextureTest();
|
||||
break;
|
||||
case 4:
|
||||
//runTouchesTest();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// PerformBasicLayer
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var PerformBasicLayer = cc.Layer.extend({
|
||||
_controlMenuVisible:true,
|
||||
_maxCases:1,
|
||||
_curCase:0,
|
||||
ctor:function () {
|
||||
this._curCase = nCurCase;
|
||||
var parent = new cc.Layer();
|
||||
__associateObjWithNative(this, parent);
|
||||
this.init();
|
||||
},
|
||||
onEnter:function () {
|
||||
// this._super();
|
||||
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
cc.MenuItemFont.setFontName("Arial");
|
||||
cc.MenuItemFont.setFontSize(24);
|
||||
var mainItem = cc.MenuItemFont.create("Back", this, this.toMainLayer);
|
||||
mainItem.setPosition(cc.p(s.width - 50, 25));
|
||||
var menu = cc.Menu.create(mainItem);
|
||||
menu.setPosition(cc.POINT_ZERO);
|
||||
|
||||
if (this._controlMenuVisible) {
|
||||
var item1 = cc.MenuItemImage.create(s_pathB1, s_pathB2, this, this.backCallback);
|
||||
var item2 = cc.MenuItemImage.create(s_pathR1, s_pathR2, this, this.restartCallback);
|
||||
var item3 = cc.MenuItemImage.create(s_pathF1, s_pathF2, this, this.nextCallback);
|
||||
item1.setPosition(cc.p(s.width / 2 - 100, 30));
|
||||
item2.setPosition(cc.p(s.width / 2, 30));
|
||||
item3.setPosition(cc.p(s.width / 2 + 100, 30));
|
||||
|
||||
menu.addChild(item1, ITEM_TAG_BASIC);
|
||||
menu.addChild(item2, ITEM_TAG_BASIC);
|
||||
menu.addChild(item3, ITEM_TAG_BASIC);
|
||||
}
|
||||
this.addChild(menu);
|
||||
},
|
||||
restartCallback:function (sender) {
|
||||
this.showCurrentTest();
|
||||
},
|
||||
nextCallback:function (sender) {
|
||||
this._curCase++;
|
||||
this._curCase = this._curCase % this._maxCases;
|
||||
nCurCase = this._curCase;
|
||||
this.showCurrentTest();
|
||||
},
|
||||
backCallback:function (sender) {
|
||||
this._curCase--;
|
||||
if (this._curCase < 0) {
|
||||
this._curCase += this._maxCases;
|
||||
}
|
||||
nCurCase = this._curCase;
|
||||
this.showCurrentTest();
|
||||
},
|
||||
showCurrentTest:function (sender) {
|
||||
},
|
||||
toMainLayer:function (sender) {
|
||||
var scene = new PerformanceTestScene();
|
||||
scene.runThisTest();
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// PerformanceTestScene
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
var PerformanceTestScene = TestScene.extend({
|
||||
runThisTest:function () {
|
||||
var layer = new PerformanceMainLayer();
|
||||
this.addChild(layer);
|
||||
cc.Director.getInstance().replaceScene(this);
|
||||
}
|
||||
});
|
||||
|
||||
function runPerformanceTest() {
|
||||
var scene = new PerformanceTestScene();
|
||||
scene.runThisTest();
|
||||
}
|
||||
|
||||
runPerformanceTest();
|
|
@ -1,171 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var s_nTexCurCase = 0;
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// TextureMenuLayer
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var TextureMenuLayer = PerformBasicLayer.extend({
|
||||
showCurrentTest:function () {
|
||||
var scene = null;
|
||||
switch (this._curCase) {
|
||||
case 0:
|
||||
scene = TextureTest.scene();
|
||||
break;
|
||||
}
|
||||
s_nTexCurCase = this._curCase;
|
||||
|
||||
if (scene) {
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
}
|
||||
},
|
||||
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
// Title
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 40);
|
||||
this.addChild(label, 1);
|
||||
label.setPosition(cc.p(s.width / 2, s.height - 32));
|
||||
label.setColor(cc.c3b(255, 255, 40));
|
||||
|
||||
// Subtitle
|
||||
var strSubTitle = this.subtitle();
|
||||
if (strSubTitle.length) {
|
||||
var l = cc.LabelTTF.create(strSubTitle, "Thonburi", 16);
|
||||
this.addChild(l, 1);
|
||||
l.setPosition(cc.p(s.width / 2, s.height - 80));
|
||||
}
|
||||
|
||||
this.performTests();
|
||||
},
|
||||
title:function () {
|
||||
return "no title";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "no subtitle";
|
||||
},
|
||||
performTests:function () {
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// TextureTest
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var TextureTest = TextureMenuLayer.extend({
|
||||
performTests:function () {
|
||||
cc.log("--------");
|
||||
cc.log("--- PNG 128x128 ---");
|
||||
this.performTestsPNG("res/Images/test_image.png");
|
||||
|
||||
cc.log("--- PNG 512x512 ---");
|
||||
this.performTestsPNG("res/Images/texture512x512.png");
|
||||
|
||||
cc.log("EMPTY IMAGE");
|
||||
cc.log("--- PNG 1024x1024 ---");
|
||||
this.performTestsPNG("res/Images/texture1024x1024.png");
|
||||
|
||||
cc.log("LANDSCAPE IMAGE");
|
||||
cc.log("--- PNG 1024x1024 ---");
|
||||
this.performTestsPNG("res/Images/landscape-1024x1024.png");
|
||||
},
|
||||
title:function () {
|
||||
return "Texture Performance Test";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "See console for results";
|
||||
},
|
||||
performTestsPNG:function (filename) {
|
||||
var now = cc.timeval();
|
||||
var texture;
|
||||
var cache = cc.TextureCache.getInstance();
|
||||
|
||||
cc.log("RGBA 8888");
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_2D_PIXEL_FORMAT_RGBA8888);
|
||||
var now = cc.Time.gettimeofdayCocos2d();
|
||||
texture = cache.addImage(filename);
|
||||
if (texture)
|
||||
cc.log(" ms:" + calculateDeltaTime(now));
|
||||
else
|
||||
cc.log(" ERROR");
|
||||
cache.removeTexture(texture);
|
||||
|
||||
cc.log("RGBA 4444");
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_2D_PIXEL_FORMAT_RGBA4444);
|
||||
var now = cc.Time.gettimeofdayCocos2d();
|
||||
texture = cache.addImage(filename);
|
||||
if (texture)
|
||||
cc.log(" ms:" + calculateDeltaTime(now));
|
||||
else
|
||||
cc.log(" ERROR");
|
||||
cache.removeTexture(texture);
|
||||
|
||||
cc.log("RGBA 5551");
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_2D_PIXEL_FORMAT_RGB5A1);
|
||||
var now = cc.Time.gettimeofdayCocos2d();
|
||||
texture = cache.addImage(filename);
|
||||
if (texture)
|
||||
cc.log(" ms:" + calculateDeltaTime(now));
|
||||
else
|
||||
cc.log(" ERROR");
|
||||
cache.removeTexture(texture);
|
||||
|
||||
cc.log("RGB 565");
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_2D_PIXEL_FORMAT_RGB565);
|
||||
var now = cc.Time.gettimeofdayCocos2d();
|
||||
texture = cache.addImage(filename);
|
||||
if (texture)
|
||||
cc.log(" ms:" + calculateDeltaTime(now));
|
||||
else
|
||||
cc.log(" ERROR");
|
||||
cache.removeTexture(texture);
|
||||
}
|
||||
});
|
||||
|
||||
TextureTest.scene = function () {
|
||||
var scene = cc.Scene.create();
|
||||
var layer = new TextureTest(false, 1, s_nTexCurCase);
|
||||
scene.addChild(layer);
|
||||
return scene;
|
||||
};
|
||||
function runTextureTest() {
|
||||
s_nTexCurCase = 0;
|
||||
var scene = TextureTest.scene();
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
}
|
||||
|
||||
function calculateDeltaTime(lastUpdate) {
|
||||
var now = cc.Time.gettimeofdayCocos2d();
|
||||
var dt = (now.tv_sec - lastUpdate.tv_sec) + (now.tv_usec - lastUpdate.tv_usec) / 1000000.0;
|
||||
return dt;
|
||||
}
|
|
@ -1,162 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
var s_nTouchCurCase = 0;
|
||||
|
||||
var TouchesMainScene = PerformBasicLayer.extend({
|
||||
_maxCases:2,
|
||||
_plabel:null,
|
||||
_numberOfTouchesB:0,
|
||||
_numberOfTouchesM:0,
|
||||
_numberOfTouchesE:0,
|
||||
_numberOfTouchesC:0,
|
||||
_elapsedTime:null,
|
||||
showCurrentTest:function () {
|
||||
var layer = null;
|
||||
switch (this._curCase) {
|
||||
case 0:
|
||||
layer = new TouchesPerformTest1(true, 2, this._curCase);
|
||||
break;
|
||||
case 1:
|
||||
layer = new TouchesPerformTest2(true, 2, this._curCase);
|
||||
break;
|
||||
}
|
||||
s_nTouchCurCase = this._curCase;
|
||||
|
||||
if (layer) {
|
||||
var scene = cc.Scene.create();
|
||||
scene.addChild(layer);
|
||||
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
}
|
||||
},
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
// add title
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 32);
|
||||
this.addChild(label, 1);
|
||||
label.setPosition(cc.p(s.width / 2, s.height - 50));
|
||||
|
||||
this.scheduleUpdate();
|
||||
|
||||
this._plabel = cc.LabelTTF.create("00.0", "Arial", 16);
|
||||
this._plabel.setPosition(cc.p(s.width / 2, s.height / 2));
|
||||
this.addChild(this._plabel);
|
||||
|
||||
this._elapsedTime = 0;
|
||||
this._numberOfTouchesB = this._numberOfTouchesM = this._numberOfTouchesE = this._numberOfTouchesC = 0;
|
||||
},
|
||||
title:function () {
|
||||
return "No title";
|
||||
},
|
||||
update:function (dt) {
|
||||
this._elapsedTime += dt;
|
||||
|
||||
if (this._elapsedTime > 1.0) {
|
||||
var frameRateB = (this._numberOfTouchesB / this._elapsedTime).toFixed(1);
|
||||
var frameRateM = (this._numberOfTouchesM / this._elapsedTime).toFixed(1);
|
||||
var frameRateE = (this._numberOfTouchesE / this._elapsedTime).toFixed(1);
|
||||
var frameRateC = (this._numberOfTouchesC / this._elapsedTime).toFixed(1);
|
||||
this._elapsedTime = 0;
|
||||
this._numberOfTouchesB = this._numberOfTouchesM = this._numberOfTouchesE = this._numberOfTouchesC = 0;
|
||||
|
||||
var str = frameRateB + " " + frameRateM + " " + frameRateE + " " + frameRateC;
|
||||
this._plabel.setString(str);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// TouchesPerformTest1
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var TouchesPerformTest1 = TouchesMainScene.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
this.setTouchEnabled(true);
|
||||
},
|
||||
title:function () {
|
||||
return "Targeted touches";
|
||||
},
|
||||
registerWithTouchDispatcher:function () {
|
||||
cc.Director.getInstance().getTouchDispatcher().addTargetedDelegate(this, 0, true);
|
||||
},
|
||||
onTouchBegan:function (touch, event) {
|
||||
this._numberOfTouchesB++;
|
||||
return true;
|
||||
},
|
||||
onTouchMoved:function (touch, event) {
|
||||
this._numberOfTouchesM++;
|
||||
},
|
||||
onTouchEnded:function (touch, event) {
|
||||
this._numberOfTouchesE++;
|
||||
},
|
||||
onTouchCancelled:function (touch, event) {
|
||||
this._numberOfTouchesC++;
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// TouchesPerformTest2
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var TouchesPerformTest2 = TouchesMainScene.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
this.setTouchEnabled(true);
|
||||
},
|
||||
title:function () {
|
||||
return "Standard touches";
|
||||
},
|
||||
registerWithTouchDispatcher:function () {
|
||||
cc.Director.getInstance().getTouchDispatcher().addStandardDelegate(this, 0);
|
||||
},
|
||||
|
||||
onTouchesBegan:function (touches, event) {
|
||||
this._numberOfTouchesB += touches.length;
|
||||
},
|
||||
onTouchesMoved:function (touches, event) {
|
||||
this._numberOfTouchesM += touches.length;
|
||||
},
|
||||
onTouchesEnded:function (touches, event) {
|
||||
this._numberOfTouchesE += touches.length;
|
||||
},
|
||||
onTouchesCancelled:function (touches, event) {
|
||||
this._numberOfTouchesC += touches.length;
|
||||
}
|
||||
});
|
||||
|
||||
function runTouchesTest() {
|
||||
s_nTouchCurCase = 0;
|
||||
var scene = cc.Scene.create();
|
||||
var layer = new TouchesPerformTest1(true, 2, s_nTouchCurCase);
|
||||
scene.addChild(layer);
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
}
|
|
@ -1,322 +0,0 @@
|
|||
var s_pathGrossini = "Images/grossini.png";
|
||||
var s_pathSister1 = "Images/grossinis_sister1.png";
|
||||
var s_pathSister2 = "Images/grossinis_sister2.png";
|
||||
var s_pathB1 = "Images/b1.png";
|
||||
var s_pathB2 = "Images/b2.png";
|
||||
var s_pathR1 = "Images/r1.png";
|
||||
var s_pathR2 = "Images/r2.png";
|
||||
var s_pathF1 = "Images/f1.png";
|
||||
var s_pathF2 = "Images/f2.png";
|
||||
var s_pathBlock = "Images/blocks.png";
|
||||
var s_back = "Images/background.png";
|
||||
var s_back1 = "Images/background1.png";
|
||||
var s_back2 = "Images/background2.png";
|
||||
var s_back3 = "Images/background3.png";
|
||||
var s_stars1 = "Images/stars.png";
|
||||
var s_stars2 = "Images/stars2.png";
|
||||
var s_fire = "Images/fire.png";
|
||||
var s_snow = "Images/snow.png";
|
||||
var s_streak = "Images/streak.png";
|
||||
var s_playNormal = "Images/btn-play-normal.png";
|
||||
var s_playSelect = "Images/btn-play-selected.png";
|
||||
var s_aboutNormal = "Images/btn-about-normal.png";
|
||||
var s_aboutSelect = "Images/btn-about-selected.png";
|
||||
var s_highNormal = "Images/btn-highscores-normal.png";
|
||||
var s_highSelect = "Images/btn-highscores-selected.png";
|
||||
var s_ball = "Images/ball.png";
|
||||
var s_paddle = "Images/paddle.png";
|
||||
var s_pathClose = "Images/close.png";
|
||||
var s_menuItem = "Images/menuitemsprite.png";
|
||||
var s_shapeModeMenuItem = "Images/shapemode.png";
|
||||
var s_textureModeMenuItem = "Images/texturemode.png";
|
||||
var s_MovementMenuItem = "Images/movement.png";
|
||||
var s_sendScore = "Images/SendScoreButton.png";
|
||||
var s_pressSendScore = "Images/SendScoreButtonPressed.png";
|
||||
var s_power = "Images/powered.png";
|
||||
var s_atlasTest = "Images/atlastest.png";
|
||||
var s_stars2Grayscale = "Images/stars2-grayscale.png";
|
||||
var s_starsGrayscale = "Images/stars-grayscale.png";
|
||||
var s_grossini_dance_atlas = "Images/grossini_dance_atlas.png";
|
||||
var s_piece = "Images/piece.png";
|
||||
var s_grossini_dance_atlas_mono = "Images/grossini_dance_atlas-mono.png";
|
||||
|
||||
var s_grossini = "animations/grossini.png";
|
||||
var s_grossini_gray = "animations/grossini_gray.png";
|
||||
var s_grossini_blue = "animations/grossini_blue.png";
|
||||
var s_grossini_aliases = "animations/grossini-aliases.png";
|
||||
var s_dragon_animation = "animations/dragon_animation.png";
|
||||
var s_ghosts = "animations/ghosts.png";
|
||||
var s_grossini_family = "animations/grossini_family.png";
|
||||
|
||||
var s_boilingFoamPlist = "Images/BoilingFoam.plist";
|
||||
var s_grossiniPlist = "animations/grossini.plist";
|
||||
var s_grossini_grayPlist = "animations/grossini_gray.plist";
|
||||
var s_grossini_bluePlist = "animations/grossini_blue.plist";
|
||||
var s_grossini_aliasesPlist = "animations/grossini-aliases.plist";
|
||||
var s_ghostsPlist = "animations/ghosts.plist";
|
||||
var s_grossini_familyPlist = "animations/grossini_family.plist";
|
||||
var s_animations2Plist = "animations/animations-2.plist";
|
||||
var s_animationsPlist = "animations/animations.plist";
|
||||
|
||||
var s_helloWorld = "Images/HelloWorld.png";
|
||||
var s_grossiniDance01 = "Images/grossini_dance_01.png";
|
||||
var s_grossiniDance02 = "Images/grossini_dance_02.png";
|
||||
var s_grossiniDance03 = "Images/grossini_dance_03.png";
|
||||
var s_grossiniDance04 = "Images/grossini_dance_04.png";
|
||||
var s_grossiniDance05 = "Images/grossini_dance_05.png";
|
||||
var s_grossiniDance06 = "Images/grossini_dance_06.png";
|
||||
var s_grossiniDance07 = "Images/grossini_dance_07.png";
|
||||
var s_grossiniDance08 = "Images/grossini_dance_08.png";
|
||||
var s_grossiniDance09 = "Images/grossini_dance_09.png";
|
||||
var s_grossiniDance10 = "Images/grossini_dance_10.png";
|
||||
var s_grossiniDance11 = "Images/grossini_dance_11.png";
|
||||
var s_grossiniDance12 = "Images/grossini_dance_12.png";
|
||||
var s_grossiniDance13 = "Images/grossini_dance_13.png";
|
||||
var s_grossiniDance14 = "Images/grossini_dance_14.png";
|
||||
|
||||
var s_arrows = "Images/arrows.png";
|
||||
var s_arrowsBar = "Images/arrowsBar.png";
|
||||
var s_arrows_hd = "Images/arrows-hd.png";
|
||||
var s_arrowsBar_hd = "Images/arrowsBar-hd.png";
|
||||
|
||||
// tilemaps resource
|
||||
var s_tilesPng = "TileMaps/tiles.png";
|
||||
var s_levelMapTga = "TileMaps/levelmap.tga";
|
||||
var s_fixedOrthoTest2Png = "TileMaps/fixed-ortho-test2.png";
|
||||
var s_hexaTilesPng = "TileMaps/hexa-tiles.png";
|
||||
var s_isoTestPng = "TileMaps/iso-test.png";
|
||||
var s_isoTest2Png = "TileMaps/iso-test2.png";
|
||||
var s_isoPng = "TileMaps/iso.png";
|
||||
var s_orthoTest1BwPng = "TileMaps/ortho-test1_bw.png";
|
||||
var s_orthoTest1Png = "TileMaps/ortho-test1.png";
|
||||
var s_tilesHdPng = "TileMaps/tiles-hd.png";
|
||||
var s_tmwDesertSpacingHdPng = "TileMaps/tmw_desert_spacing-hd.png";
|
||||
var s_tmwDesertSpacingPng = "TileMaps/tmw_desert_spacing.png";
|
||||
var s_fnTuffyBoldItalicCharmapPng = "fonts/tuffy_bold_italic-charmap.png";
|
||||
var s_fpsImages = "fonts/fps_images.png";
|
||||
|
||||
var s_bitmapFontTest = "fonts/bitmapFontTest.png";
|
||||
var s_bitmapFontTest2 = "fonts/bitmapFontTest2.png";
|
||||
var s_bitmapFontTest3 = "fonts/bitmapFontTest3.png";
|
||||
var s_bitmapFontTest4 = "fonts/bitmapFontTest4.png";
|
||||
var s_bitmapFontTest5 = "fonts/bitmapFontTest5.png";
|
||||
var s_konqa32 = "fonts/konqa32.png";
|
||||
var s_konqa32_hd = "fonts/konqa32-hd.png";
|
||||
var s_bitmapFontChinese = "fonts/bitmapFontChinese.png";
|
||||
var s_arial16 = "fonts/arial16.png";
|
||||
var s_larabie_16 = "fonts/larabie-16.png";
|
||||
var s_larabie_16_hd = "fonts/larabie-16-hd.png";
|
||||
var s_futura48 = "fonts/futura-48.png";
|
||||
var s_arial_unicode_26 = "fonts/arial-unicode-26.png";
|
||||
|
||||
var s_bitmapFontTest_fnt = "fonts/bitmapFontTest.fnt";
|
||||
var s_bitmapFontTest2_fnt = "fonts/bitmapFontTest2.fnt";
|
||||
var s_bitmapFontTest3_fnt = "fonts/bitmapFontTest3.fnt";
|
||||
var s_bitmapFontTest4_fnt = "fonts/bitmapFontTest4.fnt";
|
||||
var s_bitmapFontTest5_fnt = "fonts/bitmapFontTest5.fnt";
|
||||
var s_konqa32_fnt = "fonts/konqa32.fnt";
|
||||
var s_konqa32_hd_fnt = "fonts/konqa32-hd.fnt";
|
||||
var s_bitmapFontChinese_fnt = "fonts/bitmapFontChinese.fnt";
|
||||
var s_arial16_fnt = "fonts/arial16.fnt";
|
||||
var s_futura48_fnt = "fonts/futura-48.fnt";
|
||||
var s_helvetica32_fnt = "fonts/helvetica-32.fnt";
|
||||
var s_geneva32_fnt = "fonts/geneva-32.fnt";
|
||||
var s_arial_unicode_26_fnt = "fonts/arial-unicode-26.fnt";
|
||||
var s_markerFelt_fnt = "fonts/markerFelt.fnt";
|
||||
var s_markerFelt_hd_fnt = "fonts/markerFelt-hd.fnt";
|
||||
|
||||
var s_larabie_16_plist = "fonts/larabie-16.plist";
|
||||
var s_larabie_16_hd_plist = "fonts/larabie-16-hd.plist";
|
||||
var s_tuffy_bold_italic_charmap = "fonts/tuffy_bold_italic-charmap.plist";
|
||||
var s_tuffy_bold_italic_charmap_hd = "fonts/tuffy_bold_italic-charmap-hd.plist";
|
||||
|
||||
var s_particles = "Images/particles.png";
|
||||
var s_particles_hd = "Images/particles-hd.png";
|
||||
|
||||
var g_ressources = [
|
||||
//image ressources
|
||||
{type:"image", src:s_particles},
|
||||
{type:"image", src:s_particles_hd},
|
||||
|
||||
{type:"image", src:s_pathGrossini},
|
||||
{type:"image", src:s_fnTuffyBoldItalicCharmapPng},
|
||||
{type:"image", src:s_fpsImages},
|
||||
{type:"image", src:s_pathSister1},
|
||||
{type:"image", src:s_pathSister2},
|
||||
{type:"image", src:s_pathB1},
|
||||
{type:"image", src:s_pathB2},
|
||||
{type:"image", src:s_pathR1},
|
||||
{type:"image", src:s_pathR2},
|
||||
{type:"image", src:s_pathF1},
|
||||
{type:"image", src:s_pathF2},
|
||||
{type:"image", src:s_pathBlock},
|
||||
{type:"image", src:s_back},
|
||||
{type:"image", src:s_back1},
|
||||
{type:"image", src:s_back2},
|
||||
{type:"image", src:s_back3},
|
||||
{type:"image", src:s_stars1},
|
||||
{type:"image", src:s_stars2},
|
||||
{type:"image", src:s_fire},
|
||||
{type:"image", src:s_snow},
|
||||
{type:"image", src:s_playNormal},
|
||||
{type:"image", src:s_playSelect},
|
||||
{type:"image", src:s_aboutNormal},
|
||||
{type:"image", src:s_aboutSelect},
|
||||
{type:"image", src:s_highNormal},
|
||||
{type:"image", src:s_highSelect},
|
||||
{type:"image", src:s_ball},
|
||||
{type:"image", src:s_paddle},
|
||||
{type:"image", src:s_pathClose},
|
||||
{type:"image", src:s_menuItem},
|
||||
{type:"image", src:s_shapeModeMenuItem},
|
||||
{type:"image", src:s_textureModeMenuItem},
|
||||
{type:"image", src:s_MovementMenuItem},
|
||||
{type:"image", src:s_sendScore},
|
||||
{type:"image", src:s_pressSendScore},
|
||||
{type:"image", src:s_power},
|
||||
{type:"image", src:s_atlasTest},
|
||||
{type:"image", src:s_tilesPng},
|
||||
{type:"image", src:s_streak},
|
||||
{type:"image", src:s_starsGrayscale},
|
||||
{type:"image", src:s_stars2Grayscale},
|
||||
{type:"image", src:s_piece},
|
||||
{type:"image", src:s_grossini_dance_atlas_mono},
|
||||
|
||||
{type:"image", src:s_fixedOrthoTest2Png},
|
||||
{type:"image", src:s_hexaTilesPng},
|
||||
{type:"image", src:s_isoTestPng},
|
||||
{type:"image", src:s_isoTest2Png},
|
||||
{type:"image", src:s_isoPng},
|
||||
{type:"image", src:s_orthoTest1BwPng},
|
||||
{type:"image", src:s_orthoTest1Png},
|
||||
{type:"image", src:s_tilesHdPng},
|
||||
{type:"image", src:s_tmwDesertSpacingHdPng},
|
||||
{type:"image", src:s_tmwDesertSpacingPng},
|
||||
{type:"image", src:s_grossini},
|
||||
{type:"image", src:s_grossini_gray},
|
||||
{type:"image", src:s_grossini_blue},
|
||||
{type:"image", src:s_grossini_dance_atlas},
|
||||
{type:"image", src:s_grossini_aliases},
|
||||
{type:"image", src:s_dragon_animation},
|
||||
{type:"image", src:s_ghosts},
|
||||
{type:"image", src:s_grossini_family},
|
||||
|
||||
{type:"image", src:s_helloWorld},
|
||||
{type:"image", src:s_grossiniDance01},
|
||||
{type:"image", src:s_grossiniDance02},
|
||||
{type:"image", src:s_grossiniDance03},
|
||||
{type:"image", src:s_grossiniDance04},
|
||||
{type:"image", src:s_grossiniDance05},
|
||||
{type:"image", src:s_grossiniDance06},
|
||||
{type:"image", src:s_grossiniDance07},
|
||||
{type:"image", src:s_grossiniDance08},
|
||||
{type:"image", src:s_grossiniDance09},
|
||||
{type:"image", src:s_grossiniDance10},
|
||||
{type:"image", src:s_grossiniDance11},
|
||||
{type:"image", src:s_grossiniDance12},
|
||||
{type:"image", src:s_grossiniDance13},
|
||||
{type:"image", src:s_grossiniDance14},
|
||||
|
||||
{type:"image", src:s_bitmapFontTest},
|
||||
{type:"image", src:s_bitmapFontTest2},
|
||||
{type:"image", src:s_bitmapFontTest3},
|
||||
{type:"image", src:s_bitmapFontTest4},
|
||||
{type:"image", src:s_bitmapFontTest5},
|
||||
{type:"image", src:s_konqa32},
|
||||
{type:"image", src:s_konqa32_hd},
|
||||
{type:"image", src:s_bitmapFontChinese},
|
||||
{type:"image", src:s_arial16},
|
||||
{type:"image", src:s_larabie_16},
|
||||
{type:"image", src:s_larabie_16_hd},
|
||||
{type:"image", src:s_futura48},
|
||||
{type:"image", src:s_arial_unicode_26},
|
||||
|
||||
{type:"image", src:s_arrows},
|
||||
{type:"image", src:s_arrowsBar},
|
||||
{type:"image", src:s_arrows_hd},
|
||||
{type:"image", src:s_arrowsBar_hd},
|
||||
|
||||
{type:"plist", src:s_boilingFoamPlist},
|
||||
{type:"plist", src:s_animations2Plist},
|
||||
{type:"plist", src:s_animationsPlist},
|
||||
{type:"plist", src:s_grossiniPlist},
|
||||
{type:"plist", src:s_grossini_grayPlist},
|
||||
{type:"plist", src:s_grossini_bluePlist},
|
||||
{type:"plist", src:s_grossini_aliasesPlist},
|
||||
{type:"plist", src:s_ghostsPlist},
|
||||
{type:"plist", src:s_grossini_familyPlist},
|
||||
|
||||
{type:"plist", src:s_larabie_16_plist},
|
||||
{type:"plist", src:s_larabie_16_hd_plist},
|
||||
{type:"plist", src:s_tuffy_bold_italic_charmap},
|
||||
{type:"plist", src:s_tuffy_bold_italic_charmap_hd},
|
||||
|
||||
//tmx ressources
|
||||
{type:"tmx", src:"TileMaps/orthogonal-test1.tmx"},
|
||||
{type:"tmx", src:"TileMaps/orthogonal-test1.tsx"},
|
||||
{type:"tmx", src:"TileMaps/orthogonal-test2.tmx"},
|
||||
{type:"tmx", src:"TileMaps/orthogonal-test3.tmx"},
|
||||
{type:"tmx", src:"TileMaps/orthogonal-test4.tmx"},
|
||||
{type:"tmx", src:"TileMaps/orthogonal-test4-hd.tmx"},
|
||||
{type:"tmx", src:"TileMaps/orthogonal-test5.tmx"},
|
||||
{type:"tmx", src:"TileMaps/orthogonal-test6.tmx"},
|
||||
{type:"tmx", src:"TileMaps/orthogonal-test6-hd.tmx"},
|
||||
{type:"tmx", src:"TileMaps/hexa-test.tmx"},
|
||||
{type:"tmx", src:"TileMaps/iso-test.tmx"},
|
||||
{type:"tmx", src:"TileMaps/iso-test1.tmx"},
|
||||
{type:"tmx", src:"TileMaps/iso-test2.tmx"},
|
||||
{type:"tmx", src:"TileMaps/iso-test2-uncompressed.tmx"},
|
||||
{type:"tmx", src:"TileMaps/ortho-objects.tmx"},
|
||||
{type:"tmx", src:"TileMaps/iso-test-objectgroup.tmx"},
|
||||
{type:"tmx", src:"TileMaps/iso-test-zorder.tmx"},
|
||||
{type:"tmx", src:"TileMaps/orthogonal-test-zorder.tmx"},
|
||||
{type:"tmx", src:"TileMaps/iso-test-vertexz.tmx"},
|
||||
{type:"tmx", src:"TileMaps/orthogonal-test-vertexz.tmx"},
|
||||
{type:"tmx", src:"TileMaps/iso-test-movelayer.tmx"},
|
||||
{type:"tmx", src:"TileMaps/orthogonal-test-movelayer.tmx"},
|
||||
{type:"tmx", src:"TileMaps/iso-test-bug787.tmx"},
|
||||
{type:"tmx", src:"TileMaps/test-object-layer.tmx"},
|
||||
{type:"tmx", src:"TileMaps/ortho-tile-property.tmx"},
|
||||
{type:"tmx", src:"TileMaps/ortho-rotation-test.tmx"},
|
||||
|
||||
//audio ressources
|
||||
{type:"bgm", src:"background"},
|
||||
{type:"effect", src:"effect2"},
|
||||
|
||||
//tga ressources
|
||||
{type:"tga", src:s_levelMapTga},
|
||||
|
||||
//fnt ressources
|
||||
{type:"fnt", src:s_bitmapFontTest_fnt},
|
||||
{type:"fnt", src:s_bitmapFontTest2_fnt},
|
||||
{type:"fnt", src:s_bitmapFontTest3_fnt},
|
||||
{type:"fnt", src:s_bitmapFontTest4_fnt},
|
||||
{type:"fnt", src:s_bitmapFontTest5_fnt},
|
||||
{type:"fnt", src:s_konqa32_fnt},
|
||||
{type:"fnt", src:s_konqa32_hd_fnt},
|
||||
{type:"fnt", src:s_bitmapFontChinese_fnt},
|
||||
{type:"fnt", src:s_arial16_fnt},
|
||||
{type:"fnt", src:s_futura48_fnt},
|
||||
{type:"fnt", src:s_helvetica32_fnt},
|
||||
{type:"fnt", src:s_geneva32_fnt},
|
||||
{type:"fnt", src:s_arial_unicode_26_fnt},
|
||||
{type:"fnt", src:s_markerFelt_fnt},
|
||||
{type:"fnt", src:s_markerFelt_hd_fnt},
|
||||
|
||||
{type:"plist", src:"fonts/strings.xml"},
|
||||
{type:"plist", src:"Particles/BoilingFoam.plist"},
|
||||
{type:"plist", src:"Particles/BurstPipe.plist"},
|
||||
{type:"plist", src:"Particles/Comet.plist"},
|
||||
{type:"plist", src:"Particles/debian.plist"},
|
||||
{type:"plist", src:"Particles/ExplodingRing.plist"},
|
||||
{type:"plist", src:"Particles/Flower.plist"},
|
||||
{type:"plist", src:"Particles/Galaxy.plist"},
|
||||
{type:"plist", src:"Particles/LavaFlow.plist"},
|
||||
{type:"plist", src:"Particles/Phoenix.plist"},
|
||||
{type:"plist", src:"Particles/SmallSun.plist"},
|
||||
{type:"plist", src:"Particles/SpinningPeas.plist"},
|
||||
{type:"plist", src:"Particles/Spiral.plist"},
|
||||
{type:"plist", src:"Particles/SpookyPeas.plist"},
|
||||
{type:"plist", src:"Particles/TestPremultipliedAlpha.plist"},
|
||||
{type:"plist", src:"Particles/Upsidedown.plist"}
|
||||
];
|
|
@ -1,330 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var TestScene = cc.Scene.extend({
|
||||
ctor:function (bPortrait) {
|
||||
//this._super();
|
||||
var parent = new cc.Scene();
|
||||
__associateObjWithNative(this, parent);
|
||||
this.init();
|
||||
},
|
||||
onEnter:function () {
|
||||
//this._super();
|
||||
var label = cc.LabelTTF.create("MainMenu", "Arial", 20);
|
||||
var menuItem = cc.MenuItemLabel.create(label, this, this.MainMenuCallback);
|
||||
|
||||
var menu = cc.Menu.create(menuItem);
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
menu.setPosition(cc.POINT_ZERO);
|
||||
menuItem.setPosition(cc.p(s.width - 50, 25));
|
||||
|
||||
this.addChild(menu, 1);
|
||||
},
|
||||
runThisTest:function () {
|
||||
|
||||
},
|
||||
MainMenuCallback:function () {
|
||||
require("js/main.js");
|
||||
/*
|
||||
var scene = cc.Scene.create();
|
||||
var layer = new TestController();
|
||||
scene.addChild(layer);
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
*/
|
||||
}
|
||||
});
|
||||
//Controller stuff
|
||||
var LINE_SPACE = 40;
|
||||
var s_pathClose = null;
|
||||
var curPos = cc.POINT_ZERO;
|
||||
|
||||
var TestController = cc.Layer.extend({
|
||||
_itemMenu:null,
|
||||
_beginPos:cc.POINT_ZERO,
|
||||
isMouseDown:false,
|
||||
ctor:function () {
|
||||
var parent = new cc.Layer();
|
||||
__associateObjWithNative(this, parent);
|
||||
this.init();
|
||||
|
||||
// add close menu
|
||||
if (!s_pathClose) {
|
||||
s_pathClose = cc.TextureCache.getInstance().textureForKey("CloseNormal.png");
|
||||
}
|
||||
var closeItem = cc.MenuItemImage.create(s_pathClose, s_pathClose, this, this.closeCallback);
|
||||
var menu = cc.Menu.create(closeItem);//pmenu is just a holder for the close button
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
menu.setPosition(cc.POINT_ZERO);
|
||||
closeItem.setPosition(cc.p(s.width - 30, s.height - 30));
|
||||
|
||||
// add menu items for tests
|
||||
this._itemMenu = cc.Menu.create();//item menu is where all the label goes, and the one gets scrolled
|
||||
|
||||
for (var i = 0, len = testNames.length; i < len; i++) {
|
||||
var label = cc.LabelTTF.create(testNames[i].title, "Arial", 24);
|
||||
var menuItem = cc.MenuItemLabel.create(label, this, this.menuCallback);
|
||||
this._itemMenu.addChild(menuItem, i + 10000);
|
||||
menuItem.setPosition(cc.p(s.width / 2, (s.height - (i + 1) * LINE_SPACE)));
|
||||
}
|
||||
|
||||
this._itemMenu.setContentSize(cc.size(s.width, (testNames.length + 1) * LINE_SPACE));
|
||||
this._itemMenu.setPosition(curPos);
|
||||
this.setTouchEnabled(true);
|
||||
this.addChild(this._itemMenu);
|
||||
this.addChild(menu, 1);
|
||||
},
|
||||
menuCallback:function (sender) {
|
||||
var idx = sender.getZOrder() - 10000;
|
||||
// get the userdata, it's the index of the menu item clicked
|
||||
// create the test scene and run it
|
||||
var scene = testNames[idx].testScene();
|
||||
if (scene) {
|
||||
scene.runThisTest();
|
||||
}
|
||||
},
|
||||
closeCallback:function () {
|
||||
history.go(-1);
|
||||
},
|
||||
onTouchesBegan:function (touches, event) {
|
||||
if (!this.isMouseDown) {
|
||||
//this._beginPos = cc.p(touches[0].getLocation().x, touches[0].getLocation().y);
|
||||
this._beginPos = touches[0].getLocation().y;
|
||||
}
|
||||
this.isMouseDown = true;
|
||||
},
|
||||
onTouchesMoved:function (touches, event) {
|
||||
if (this.isMouseDown) {
|
||||
var touchLocation = touches[0].getLocation().y;
|
||||
var nMoveY = touchLocation - this._beginPos;
|
||||
curPos = cc.p(this._itemMenu.getPosition().x, this._itemMenu.getPosition().y);
|
||||
|
||||
var nextPos = cc.p(curPos.x, curPos.y + nMoveY);
|
||||
var winSize = cc.Director.getInstance().getWinSize();
|
||||
if (nextPos.y < 0.0) {
|
||||
this._itemMenu.setPosition(cc.POINT_ZERO);
|
||||
return;
|
||||
}
|
||||
|
||||
if (nextPos.y > ((testNames.length + 1) * LINE_SPACE - winSize.height)) {
|
||||
this._itemMenu.setPosition(cc.p(0, ((testNames.length + 1) * LINE_SPACE - winSize.height)));
|
||||
return;
|
||||
}
|
||||
this._itemMenu.setPosition(nextPos);
|
||||
this._beginPos = cc.p(0, touchLocation).y;
|
||||
curPos = nextPos;
|
||||
}
|
||||
},
|
||||
onTouchesEnded:function () {
|
||||
this.isMouseDown = false;
|
||||
}
|
||||
});
|
||||
|
||||
var testNames = [
|
||||
//"Accelerometer",
|
||||
{
|
||||
title:"ActionManagerTest",
|
||||
testScene:function () {
|
||||
return new ActionManagerTestScene();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"ActionsTest",
|
||||
testScene:function () {
|
||||
return new ActionsTestScene();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"Box2DTest",
|
||||
testScene:function () {
|
||||
return new Box2DTestScene();
|
||||
}
|
||||
},
|
||||
//"Box2dTestBed",
|
||||
//"BugsTest",
|
||||
//"ChipmunkTest",
|
||||
{
|
||||
title:"ClickAndMoveTest",
|
||||
testScene:function () {
|
||||
return new ClickAndMoveTestScene();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"CocosDenshionTest",
|
||||
testScene:function () {
|
||||
return new CocosDenshionTestScene();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"CocosNodeTest",
|
||||
testScene:function () {
|
||||
return new CocosNodeTestScene();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"CurrentLanguageTest",
|
||||
testScene:function () {
|
||||
return new CurrentLanguageTestScene();
|
||||
}
|
||||
},
|
||||
//"CurlTest",
|
||||
{
|
||||
title:"DrawPrimitivesTest",
|
||||
testScene:function () {
|
||||
return new DrawPrimitivesTestScene();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"EaseActionsTest",
|
||||
testScene:function () {
|
||||
return new EaseActionsTestScene();
|
||||
}
|
||||
},
|
||||
//"EffectsTest",
|
||||
//"EffectAdvancedTest",
|
||||
//"ExtensionsTest",
|
||||
{
|
||||
title:"FontTest",
|
||||
testScene:function () {
|
||||
return new FontTestScene();
|
||||
}
|
||||
},
|
||||
//"HiResTest",
|
||||
{
|
||||
title:"IntervalTest",
|
||||
testScene:function () {
|
||||
return new IntervalTestScene();
|
||||
}
|
||||
},
|
||||
//"KeyboardTest",
|
||||
{
|
||||
title:"LabelTest",
|
||||
testScene:function () {
|
||||
return new LabelTestScene();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"LayerTest",
|
||||
testScene:function () {
|
||||
return new LayerTestScene();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"MenuTest",
|
||||
testScene:function () {
|
||||
return new MenuTestScene();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"MultiTouchTest",
|
||||
testScene:function () {
|
||||
return new MultiTouchTestScene();
|
||||
}
|
||||
},
|
||||
//"MotionStreakTest",
|
||||
{
|
||||
title:"ParallaxTest",
|
||||
testScene:function () {
|
||||
return new ParallaxTestScene();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"ParticleTest",
|
||||
testScene:function () {
|
||||
return new ParticleTestScene();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"PerformanceTest",
|
||||
testScene:function () {
|
||||
return new PerformanceTestScene();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"ProgressActionsTest",
|
||||
testScene:function () {
|
||||
return new ProgressActionsTestScene();
|
||||
}
|
||||
},
|
||||
//"RenderTextureTest",
|
||||
{
|
||||
title:"RotateWorldTest",
|
||||
testScene:function () {
|
||||
return new RotateWorldTestScene();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"SceneTest",
|
||||
testScene:function () {
|
||||
return new SceneTestScene();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"SchedulerTest",
|
||||
testScene:function () {
|
||||
return new SchedulerTestScene();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"SpriteTest",
|
||||
testScene:function () {
|
||||
return new SpriteTestScene();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"TextInputTest",
|
||||
testScene:function () {
|
||||
return new TextInputTestScene();
|
||||
}
|
||||
},
|
||||
//"Texture2DTest",
|
||||
{
|
||||
title:"TextureCacheTest",
|
||||
testScene:function () {
|
||||
return new TextureCacheTestScene();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"TileMapTest",
|
||||
testScene:function () {
|
||||
return new TileMapTestScene();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"TouchesTest",
|
||||
testScene:function () {
|
||||
return new TouchesTestScene();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"TransitionsTest",
|
||||
testScene:function () {
|
||||
return new TransitionsTestScene();
|
||||
}
|
||||
}
|
||||
//"UserDefaultTest",
|
||||
//"ZwoptexTest",
|
||||
];
|
File diff suppressed because it is too large
Load Diff
|
@ -1,437 +0,0 @@
|
|||
// cocos2d Helper
|
||||
|
||||
cc.c3 = cc.c3 || function (r, g, b) {
|
||||
return {r: r, g: g, b: b};
|
||||
};
|
||||
|
||||
cc.c3b = cc.c3;
|
||||
|
||||
cc.c4 = cc.c4 || function (r, g, b, o) {
|
||||
return {r: r, g: g, b: b, a: o};
|
||||
};
|
||||
|
||||
cc.c4b = cc.c4;
|
||||
|
||||
cc.c4f = cc.c4f || function (r, g, b, o) {
|
||||
return {r: r, g: g, b: b, a: o};
|
||||
};
|
||||
|
||||
cc.p = cc.p || function( x, y )
|
||||
{
|
||||
return {x:x, y:y};
|
||||
};
|
||||
|
||||
cc.g = cc.g || cc.p;
|
||||
cc.log = cc.log || log;
|
||||
|
||||
//
|
||||
// cocos2d constants
|
||||
//
|
||||
cc.TEXTURE_PIXELFORMAT_RGBA8888 = 0;
|
||||
cc.TEXTURE_PIXELFORMAT_RGB888 = 1;
|
||||
cc.TEXTURE_PIXELFORMAT_RGB565 = 2;
|
||||
cc.TEXTURE_PIXELFORMAT_A8 = 3;
|
||||
cc.TEXTURE_PIXELFORMAT_I8 = 4;
|
||||
cc.TEXTURE_PIXELFORMAT_AI88 = 5;
|
||||
cc.TEXTURE_PIXELFORMAT_RGBA4444 = 6;
|
||||
cc.TEXTURE_PIXELFORMAT_RGB5A1 = 7;
|
||||
cc.TEXTURE_PIXELFORMAT_PVRTC4 = 8;
|
||||
cc.TEXTURE_PIXELFORMAT_PVRTC4 = 9;
|
||||
cc.TEXTURE_PIXELFORMAT_DEFAULT = cc.TEXTURE_PIXELFORMAT_RGBA8888;
|
||||
|
||||
cc.TEXT_ALIGNMENT_LEFT = 0;
|
||||
cc.TEXT_ALIGNMENT_CENTER = 1;
|
||||
cc.TEXT_ALIGNMENT_RIGHT = 2;
|
||||
|
||||
cc.VERTICAL_TEXT_ALIGNMENT_TOP = 0;
|
||||
cc.VERTICAL_TEXT_ALIGNMENT_CENTER = 1;
|
||||
cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM = 2;
|
||||
|
||||
cc.IMAGE_FORMAT_JPEG = 0;
|
||||
cc.IMAGE_FORMAT_PNG = 0;
|
||||
|
||||
cc.PROGRESS_TIMER_TYPE_RADIAL = 0;
|
||||
cc.PROGRESS_TIMER_TYPE_BAR = 1;
|
||||
|
||||
cc.PARTICLE_TYPE_FREE = 0;
|
||||
cc.PARTICLE_TYPE_RELATIVE = 1;
|
||||
cc.PARTICLE_TYPE_GROUPED = 2;
|
||||
cc.PARTICLE_DURATION_INFINITY = -1;
|
||||
cc.PARTICLE_MODE_GRAVITY = 0;
|
||||
cc.PARTICLE_MODE_RADIUS = 1;
|
||||
cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE = -1;
|
||||
cc.PARTICLE_START_RADIUS_EQUAL_TO_END_RADIUS = -1;
|
||||
|
||||
cc.RED = cc.c3(255,0,0);
|
||||
cc.GREEN = cc.c3(0,255,0);
|
||||
cc.BLUE = cc.c3(0,0,255);
|
||||
cc.BLACK = cc.c3(0,0,0);
|
||||
cc.WHITE = cc.c3(255,255,255);
|
||||
|
||||
cc.POINT_ZERO = {x:0, y:0};
|
||||
|
||||
cc._reuse_p0 = {x:0, y:0};
|
||||
cc._reuse_p1 = {x:0, y:0};
|
||||
cc._reuse_p_index = 0;
|
||||
cc._reuse_color3b = cc.c3(255, 255, 255 );
|
||||
cc._reuse_color4b = cc.c4(255, 255, 255, 255 );
|
||||
cc._reuse_grid = cc.g(0,0);
|
||||
|
||||
// dump config info, but only in debug mode
|
||||
cc.dumpConfig = function()
|
||||
{
|
||||
if( cc.config.debug ) {
|
||||
for(var i in cc.config)
|
||||
cc.log( i + " = " + cc.config[i] );
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Point
|
||||
//
|
||||
cc._p = function( x, y )
|
||||
{
|
||||
if( cc._reuse_p_index === 0 ) {
|
||||
cc._reuse_p0.x = x;
|
||||
cc._reuse_p0.y = y;
|
||||
cc._reuse_p_index = 1;
|
||||
return cc._reuse_p0;
|
||||
} else {
|
||||
cc._reuse_p1.x = x;
|
||||
cc._reuse_p1.y = y;
|
||||
cc._reuse_p_index = 0;
|
||||
return cc._reuse_p1;
|
||||
}
|
||||
};
|
||||
|
||||
cc._to_p = function( point )
|
||||
{
|
||||
return point;
|
||||
};
|
||||
|
||||
cc._from_p = function( size )
|
||||
{
|
||||
return size;
|
||||
};
|
||||
|
||||
//
|
||||
// Grid
|
||||
//
|
||||
cc._g = function( x, y )
|
||||
{
|
||||
cc._reuse_grid.x = x;
|
||||
cc._reuse_grid.y = y;
|
||||
return cc._reuse_grid;
|
||||
}
|
||||
|
||||
//
|
||||
// Color
|
||||
//
|
||||
//
|
||||
// Color 3B
|
||||
//
|
||||
cc.c3b = function( r, g, b )
|
||||
{
|
||||
return {r:r, g:g, b:b };
|
||||
};
|
||||
cc._c3b = function( r, g, b )
|
||||
{
|
||||
cc._reuse_color3b.r = r;
|
||||
cc._reuse_color3b.g = g;
|
||||
cc._reuse_color3b.b = b;
|
||||
return cc._reuse_color3b;
|
||||
};
|
||||
// compatibility
|
||||
cc.c3 = cc.c3b;
|
||||
cc._c3 = cc._c3b;
|
||||
|
||||
//
|
||||
// Color 4B
|
||||
//
|
||||
cc.c4b = function( r, g, b, a )
|
||||
{
|
||||
return {r:r, g:g, b:b, a:a };
|
||||
};
|
||||
cc._c4b = function( r, g, b, a )
|
||||
{
|
||||
cc._reuse_color4b.r = r;
|
||||
cc._reuse_color4b.g = g;
|
||||
cc._reuse_color4b.b = b;
|
||||
cc._reuse_color4b.a = a;
|
||||
return cc._reuse_color4b;
|
||||
};
|
||||
// compatibility
|
||||
cc.c4 = cc.c4b;
|
||||
cc._c4 = cc._c4b;
|
||||
|
||||
|
||||
//
|
||||
// Size
|
||||
//
|
||||
cc.size = function(w,h)
|
||||
{
|
||||
return {width:w, height:h};
|
||||
}
|
||||
|
||||
cc._to_size = function( size )
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
cc._from_size = function( size )
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
//
|
||||
// Rect
|
||||
//
|
||||
cc.rect = function(x,y,w,h)
|
||||
{
|
||||
return {x:x, y:y, width:w, height:h};
|
||||
}
|
||||
|
||||
cc._to_rect = function( rect )
|
||||
{
|
||||
return rect;
|
||||
}
|
||||
|
||||
cc._from_rect = function( rect )
|
||||
{
|
||||
return rect;
|
||||
}
|
||||
|
||||
// XXX Should be done in native
|
||||
cc.rectIntersectsRect = function( rectA, rectB )
|
||||
{
|
||||
var bool = ! ( rectA.x > rectB.x + rectB.width ||
|
||||
rectA.x + rectA.width < rectB.x ||
|
||||
rectA.y > rectB.y +rectB.height ||
|
||||
rectA.y + rectA.height < rectB.y );
|
||||
|
||||
return bool;
|
||||
}
|
||||
|
||||
// point functions
|
||||
cc.pAdd = cc.pAdd || function (p1, p2) {
|
||||
return {x: p1.x + p2.x, y: p1.y + p2.y};
|
||||
};
|
||||
|
||||
cc.pSub = cc.pSub || function (p1, p2) {
|
||||
return {x: p1.x - p2.x, y: p1.y - p2.y};
|
||||
}
|
||||
|
||||
cc.pMult = cc.pMult || function (p1, s) {
|
||||
return {x: p1.x * s, y: p1.y * s};
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculates dot product of two points.
|
||||
* @param {cc.Point} v1
|
||||
* @param {cc.Point} v2
|
||||
* @return {Number}
|
||||
*/
|
||||
cc.pDot = function (v1, v2) {
|
||||
return v1.x * v2.x + v1.y * v2.y;
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculates the square length of a cc.Point (not calling sqrt() )
|
||||
* @param {cc.Point} v
|
||||
*@return {cc.pDot}
|
||||
*/
|
||||
cc.pLengthSQ = function (v) {
|
||||
return cc.pDot(v, v);
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculates distance between point an origin
|
||||
* @param {cc.Point} v
|
||||
* @return {Number}
|
||||
*/
|
||||
cc.pLength = function (v) {
|
||||
return Math.sqrt(cc.pLengthSQ(v));
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculates the distance between two points
|
||||
* @param {cc.Point} v1
|
||||
* @param {cc.Point} v2
|
||||
* @return {cc.pLength}
|
||||
*/
|
||||
cc.pDistance = function (v1, v2) {
|
||||
return cc.pLength(cc.pSub(v1, v2));
|
||||
};
|
||||
|
||||
/**
|
||||
* returns a random float between 0 and 1
|
||||
* @return {Number}
|
||||
* @function
|
||||
*/
|
||||
cc.RANDOM_0_1 = function () {
|
||||
return Math.random();
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Array: for cocos2d-hmtl5 compatibility
|
||||
//
|
||||
cc.ArrayRemoveObject = function (arr, delObj) {
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
if (arr[i] == delObj) {
|
||||
arr.splice(i, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Google "subclasses"
|
||||
// borrowed from closure library
|
||||
//
|
||||
var goog = goog || {}; // Check to see if already defined in current scope
|
||||
goog.inherits = function (childCtor, parentCtor) {
|
||||
/** @constructor */
|
||||
function tempCtor() {};
|
||||
tempCtor.prototype = parentCtor.prototype;
|
||||
childCtor.superClass_ = parentCtor.prototype;
|
||||
childCtor.prototype = new tempCtor();
|
||||
childCtor.prototype.constructor = childCtor;
|
||||
|
||||
// Copy "static" method, but doesn't generate subclasses.
|
||||
// for( var i in parentCtor ) {
|
||||
// childCtor[ i ] = parentCtor[ i ];
|
||||
// }
|
||||
};
|
||||
goog.base = function(me, opt_methodName, var_args) {
|
||||
var caller = arguments.callee.caller;
|
||||
if (caller.superClass_) {
|
||||
// This is a constructor. Call the superclass constructor.
|
||||
ret = caller.superClass_.constructor.apply( me, Array.prototype.slice.call(arguments, 1));
|
||||
|
||||
// XXX: SpiderMonkey bindings extensions
|
||||
// __associateObjWithNative( me, ret );
|
||||
return ret;
|
||||
}
|
||||
|
||||
var args = Array.prototype.slice.call(arguments, 2);
|
||||
var foundCaller = false;
|
||||
for (var ctor = me.constructor;
|
||||
ctor; ctor = ctor.superClass_ && ctor.superClass_.constructor) {
|
||||
if (ctor.prototype[opt_methodName] === caller) {
|
||||
foundCaller = true;
|
||||
} else if (foundCaller) {
|
||||
return ctor.prototype[opt_methodName].apply(me, args);
|
||||
}
|
||||
}
|
||||
|
||||
// If we did not find the caller in the prototype chain,
|
||||
// then one of two things happened:
|
||||
// 1) The caller is an instance method.
|
||||
// 2) This method was not called by the right caller.
|
||||
if (me[opt_methodName] === caller) {
|
||||
return me.constructor.prototype[opt_methodName].apply(me, args);
|
||||
} else {
|
||||
throw Error(
|
||||
'goog.base called from a method of one name ' +
|
||||
'to a method of a different name');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Simple subclass
|
||||
//
|
||||
|
||||
cc.Class = function(){};
|
||||
|
||||
cc.Class.extend = function (prop) {
|
||||
var _super = this.prototype;
|
||||
|
||||
// Instantiate a base class (but only create the instance,
|
||||
// don't run the init constructor)
|
||||
initializing = true;
|
||||
var prototype = new this();
|
||||
initializing = false;
|
||||
fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
|
||||
|
||||
// Copy the properties over onto the new prototype
|
||||
for (var name in prop) {
|
||||
// Check if we're overwriting an existing function
|
||||
prototype[name] = typeof prop[name] == "function" &&
|
||||
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
|
||||
(function (name, fn) {
|
||||
return function () {
|
||||
var tmp = this._super;
|
||||
|
||||
// Add a new ._super() method that is the same method
|
||||
// but on the super-class
|
||||
this._super = _super[name];
|
||||
|
||||
// The method only need to be bound temporarily, so we
|
||||
// remove it when we're done executing
|
||||
var ret = fn.apply(this, arguments);
|
||||
this._super = tmp;
|
||||
|
||||
return ret;
|
||||
};
|
||||
})(name, prop[name]) :
|
||||
prop[name];
|
||||
}
|
||||
|
||||
// The dummy class constructor
|
||||
function Class() {
|
||||
// All construction is actually done in the init method
|
||||
if (!initializing && this.ctor)
|
||||
this.ctor.apply(this, arguments);
|
||||
}
|
||||
|
||||
// Populate our constructed prototype object
|
||||
Class.prototype = prototype;
|
||||
|
||||
// Enforce the constructor to be what we expect
|
||||
Class.prototype.constructor = Class;
|
||||
|
||||
// And make this class extendable
|
||||
Class.extend = arguments.callee;
|
||||
|
||||
return Class;
|
||||
};
|
||||
|
||||
cc.Layer.extend = cc.Class.extend;
|
||||
cc.Scene.extend = cc.Class.extend;
|
||||
cc.LayerGradient.extend = cc.Class.extend;
|
||||
cc.Sprite.extend = cc.Class.extend;
|
||||
cc.MenuItemFont.extend = cc.Class.extend;
|
||||
|
||||
//
|
||||
// Chipmunk helpers
|
||||
//
|
||||
var cp = cp || {};
|
||||
|
||||
cp.v = cc.p;
|
||||
cp._v = cc._p;
|
||||
cp.vzero = cp.v(0,0);
|
||||
|
||||
//
|
||||
// OpenGL Helpers
|
||||
//
|
||||
var gl = gl || {};
|
||||
gl.NEAREST = 0x2600;
|
||||
gl.LINEAR = 0x2601;
|
||||
gl.REPEAT = 0x2901;
|
||||
gl.CLAMP_TO_EDGE = 0x812F;
|
||||
gl.CLAMP_TO_BORDER = 0x812D;
|
||||
gl.LINEAR_MIPMAP_NEAREST = 0x2701;
|
||||
gl.NEAREST_MIPMAP_NEAREST = 0x2700;
|
||||
gl.ZERO = 0;
|
||||
gl.ONE = 1;
|
||||
gl.SRC_COLOR = 0x0300;
|
||||
gl.ONE_MINUS_SRC_COLOR = 0x0301;
|
||||
gl.SRC_ALPHA = 0x0302;
|
||||
gl.ONE_MINUS_SRC_ALPHA = 0x0303;
|
||||
gl.DST_ALPHA = 0x0304;
|
||||
gl.ONE_MINUS_DST_ALPHA = 0x0305;
|
||||
gl.DST_COLOR = 0x0306;
|
||||
gl.ONE_MINUS_DST_COLOR = 0x0307;
|
||||
gl.SRC_ALPHA_SATURATE = 0x0308;
|
||||
|
|
@ -1,361 +0,0 @@
|
|||
// cocos2d Helper
|
||||
|
||||
//
|
||||
// cocos2d constants
|
||||
//
|
||||
cc.TEXTURE_PIXELFORMAT_RGBA8888 = 0;
|
||||
cc.TEXTURE_PIXELFORMAT_RGB888 = 1;
|
||||
cc.TEXTURE_PIXELFORMAT_RGB565 = 2;
|
||||
cc.TEXTURE_PIXELFORMAT_A8 = 3;
|
||||
cc.TEXTURE_PIXELFORMAT_I8 = 4;
|
||||
cc.TEXTURE_PIXELFORMAT_AI88 = 5;
|
||||
cc.TEXTURE_PIXELFORMAT_RGBA4444 = 6;
|
||||
cc.TEXTURE_PIXELFORMAT_RGB5A1 = 7;
|
||||
cc.TEXTURE_PIXELFORMAT_PVRTC4 = 8;
|
||||
cc.TEXTURE_PIXELFORMAT_PVRTC4 = 9;
|
||||
cc.TEXTURE_PIXELFORMAT_DEFAULT = cc.TEXTURE_PIXELFORMAT_RGBA8888;
|
||||
|
||||
cc.TEXT_ALIGNMENT_LEFT = 0;
|
||||
cc.TEXT_ALIGNMENT_CENTER = 1;
|
||||
cc.TEXT_ALIGNMENT_RIGHT = 2;
|
||||
|
||||
cc.VERTICAL_TEXT_ALIGNMENT_TOP = 0;
|
||||
cc.VERTICAL_TEXT_ALIGNMENT_CENTER = 1;
|
||||
cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM = 2;
|
||||
|
||||
cc.IMAGE_FORMAT_JPEG = 0;
|
||||
cc.IMAGE_FORMAT_PNG = 0;
|
||||
|
||||
cc.PROGRESS_TIMER_TYPE_RADIAL = 0;
|
||||
cc.PROGRESS_TIMER_TYPE_BAR = 1;
|
||||
|
||||
cc.PARTICLE_TYPE_FREE = 0;
|
||||
cc.PARTICLE_TYPE_RELATIVE = 1;
|
||||
cc.PARTICLE_TYPE_GROUPED = 2;
|
||||
cc.PARTICLE_DURATION_INFINITY = -1;
|
||||
cc.PARTICLE_MODE_GRAVITY = 0;
|
||||
cc.PARTICLE_MODE_RADIUS = 1;
|
||||
cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE = -1;
|
||||
cc.PARTICLE_START_RADIUS_EQUAL_TO_END_RADIUS = -1;
|
||||
|
||||
cc.RED = cc.c3(255,0,0);
|
||||
cc.GREEN = cc.c3(0,255,0);
|
||||
cc.BLUE = cc.c3(0,0,255);
|
||||
cc.BLACK = cc.c3(0,0,0);
|
||||
cc.WHITE = cc.c3(255,255,255);
|
||||
|
||||
cc.POINT_ZERO = {x:0, y:0};
|
||||
|
||||
cc._reuse_p0 = {x:0, y:0};
|
||||
cc._reuse_p1 = {x:0, y:0};
|
||||
cc._reuse_p_index = 0;
|
||||
cc._reuse_color3b = cc.c3(255, 255, 255 );
|
||||
cc._reuse_color4b = cc.c4(255, 255, 255, 255 );
|
||||
cc._reuse_grid = cc.g(0,0);
|
||||
|
||||
// dump config info, but only in debug mode
|
||||
cc.dumpConfig = function()
|
||||
{
|
||||
if( cc.config.debug ) {
|
||||
for( i in cc.config )
|
||||
cc.log( i + " = " + cc.config[i] );
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Point
|
||||
//
|
||||
cc.p = function( x, y )
|
||||
{
|
||||
return {x:x, y:y};
|
||||
};
|
||||
|
||||
cc._p = function( x, y )
|
||||
{
|
||||
if( cc._reuse_p_index === 0 ) {
|
||||
cc._reuse_p0.x = x;
|
||||
cc._reuse_p0.y = y;
|
||||
cc._reuse_p_index = 1;
|
||||
return cc._reuse_p0;
|
||||
} else {
|
||||
cc._reuse_p1.x = x;
|
||||
cc._reuse_p1.y = y;
|
||||
cc._reuse_p_index = 0;
|
||||
return cc._reuse_p1;
|
||||
}
|
||||
};
|
||||
|
||||
cc._to_p = function( point )
|
||||
{
|
||||
return point;
|
||||
};
|
||||
|
||||
cc._from_p = function( size )
|
||||
{
|
||||
return size;
|
||||
};
|
||||
|
||||
cc.c3 = function (r, g, b) {
|
||||
var tmp = new Uint8Array(3);
|
||||
tmp[0] = r;
|
||||
tmp[1] = g;
|
||||
tmp[2] = b;
|
||||
return tmp;
|
||||
};
|
||||
|
||||
cc.c4 = function (r, g, b, o) {
|
||||
var tmp = new Uint8Array(4);
|
||||
tmp[0] = r;
|
||||
tmp[1] = g;
|
||||
tmp[2] = b;
|
||||
tmp[3] = o;
|
||||
return tmp;
|
||||
};
|
||||
|
||||
cc.c4f = function (r, g, b, o) {
|
||||
var tmp = new Float32Array(4);
|
||||
tmp[0] = r;
|
||||
tmp[1] = g;
|
||||
tmp[2] = b;
|
||||
tmp[3] = o;
|
||||
return tmp;
|
||||
};
|
||||
|
||||
//
|
||||
// Grid
|
||||
//
|
||||
cc._g = function( x, y )
|
||||
{
|
||||
cc._reuse_grid.x = x;
|
||||
cc._reuse_grid.y = y;
|
||||
return cc._reuse_grid;
|
||||
}
|
||||
|
||||
//
|
||||
// Color
|
||||
//
|
||||
cc._c3 = function( r, g, b )
|
||||
{
|
||||
cc._reuse_color3b[0] = r;
|
||||
cc._reuse_color3b[1] = g;
|
||||
cc._reuse_color3b[2] = b;
|
||||
return cc._reuse_color3b;
|
||||
}
|
||||
|
||||
cc._c4 = function( r, g, b, a )
|
||||
{
|
||||
cc._reuse_color4b[0] = r;
|
||||
cc._reuse_color4b[1] = g;
|
||||
cc._reuse_color4b[2] = b;
|
||||
cc._reuse_color4b[3] = a;
|
||||
return cc._reuse_color4b;
|
||||
}
|
||||
|
||||
//
|
||||
// Size
|
||||
//
|
||||
cc.size = function(w,h)
|
||||
{
|
||||
return {width:w, height:h};
|
||||
}
|
||||
|
||||
cc._to_size = function( size )
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
cc._from_size = function( size )
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
//
|
||||
// Rect
|
||||
//
|
||||
cc.rect = function(x,y,w,h)
|
||||
{
|
||||
return {x:x, y:y, width:w, height:h};
|
||||
}
|
||||
|
||||
cc._to_rect = function( rect )
|
||||
{
|
||||
return rect;
|
||||
}
|
||||
|
||||
cc._from_rect = function( rect )
|
||||
{
|
||||
return rect;
|
||||
}
|
||||
|
||||
// XXX Should be done in native
|
||||
cc.rectIntersectsRect = function( rectA, rectB )
|
||||
{
|
||||
var bool = ! ( rectA.x > rectB.x + rectB.width ||
|
||||
rectA.x + rectA.width < rectB.x ||
|
||||
rectA.y > rectB.y +rectB.height ||
|
||||
rectA.y + rectA.height < rectB.y );
|
||||
|
||||
return bool;
|
||||
}
|
||||
|
||||
//
|
||||
// Array: for cocos2d-hmtl5 compatibility
|
||||
//
|
||||
cc.ArrayRemoveObject = function (arr, delObj) {
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
if (arr[i] == delObj) {
|
||||
arr.splice(i, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Google "subclasses"
|
||||
// borrowed from closure library
|
||||
//
|
||||
var goog = goog || {}; // Check to see if already defined in current scope
|
||||
goog.inherits = function (childCtor, parentCtor) {
|
||||
/** @constructor */
|
||||
function tempCtor() {};
|
||||
tempCtor.prototype = parentCtor.prototype;
|
||||
childCtor.superClass_ = parentCtor.prototype;
|
||||
childCtor.prototype = new tempCtor();
|
||||
childCtor.prototype.constructor = childCtor;
|
||||
|
||||
// Copy "static" method, but doesn't generate subclasses.
|
||||
// for( var i in parentCtor ) {
|
||||
// childCtor[ i ] = parentCtor[ i ];
|
||||
// }
|
||||
};
|
||||
goog.base = function(me, opt_methodName, var_args) {
|
||||
var caller = arguments.callee.caller;
|
||||
if (caller.superClass_) {
|
||||
// This is a constructor. Call the superclass constructor.
|
||||
ret = caller.superClass_.constructor.apply( me, Array.prototype.slice.call(arguments, 1));
|
||||
|
||||
// XXX: SpiderMonkey bindings extensions
|
||||
// __associateObjWithNative( me, ret );
|
||||
return ret;
|
||||
}
|
||||
|
||||
var args = Array.prototype.slice.call(arguments, 2);
|
||||
var foundCaller = false;
|
||||
for (var ctor = me.constructor;
|
||||
ctor; ctor = ctor.superClass_ && ctor.superClass_.constructor) {
|
||||
if (ctor.prototype[opt_methodName] === caller) {
|
||||
foundCaller = true;
|
||||
} else if (foundCaller) {
|
||||
return ctor.prototype[opt_methodName].apply(me, args);
|
||||
}
|
||||
}
|
||||
|
||||
// If we did not find the caller in the prototype chain,
|
||||
// then one of two things happened:
|
||||
// 1) The caller is an instance method.
|
||||
// 2) This method was not called by the right caller.
|
||||
if (me[opt_methodName] === caller) {
|
||||
return me.constructor.prototype[opt_methodName].apply(me, args);
|
||||
} else {
|
||||
throw Error(
|
||||
'goog.base called from a method of one name ' +
|
||||
'to a method of a different name');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Simple subclass
|
||||
//
|
||||
|
||||
cc.Class = function(){};
|
||||
|
||||
cc.Class.extend = function (prop) {
|
||||
var _super = this.prototype;
|
||||
|
||||
// Instantiate a base class (but only create the instance,
|
||||
// don't run the init constructor)
|
||||
initializing = true;
|
||||
var prototype = new this();
|
||||
initializing = false;
|
||||
fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
|
||||
|
||||
// Copy the properties over onto the new prototype
|
||||
for (var name in prop) {
|
||||
// Check if we're overwriting an existing function
|
||||
prototype[name] = typeof prop[name] == "function" &&
|
||||
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
|
||||
(function (name, fn) {
|
||||
return function () {
|
||||
var tmp = this._super;
|
||||
|
||||
// Add a new ._super() method that is the same method
|
||||
// but on the super-class
|
||||
this._super = _super[name];
|
||||
|
||||
// The method only need to be bound temporarily, so we
|
||||
// remove it when we're done executing
|
||||
var ret = fn.apply(this, arguments);
|
||||
this._super = tmp;
|
||||
|
||||
return ret;
|
||||
};
|
||||
})(name, prop[name]) :
|
||||
prop[name];
|
||||
}
|
||||
|
||||
// The dummy class constructor
|
||||
function Class() {
|
||||
// All construction is actually done in the init method
|
||||
if (!initializing && this.ctor)
|
||||
this.ctor.apply(this, arguments);
|
||||
}
|
||||
|
||||
// Populate our constructed prototype object
|
||||
Class.prototype = prototype;
|
||||
|
||||
// Enforce the constructor to be what we expect
|
||||
Class.prototype.constructor = Class;
|
||||
|
||||
// And make this class extendable
|
||||
Class.extend = arguments.callee;
|
||||
|
||||
return Class;
|
||||
};
|
||||
|
||||
cc.Layer.extend = cc.Class.extend;
|
||||
cc.LayerGradient.extend = cc.Class.extend;
|
||||
cc.Sprite.extend = cc.Class.extend;
|
||||
cc.MenuItemFont.extend = cc.Class.extend;
|
||||
|
||||
//
|
||||
// Chipmunk helpers
|
||||
//
|
||||
//var cp = cp || {};
|
||||
|
||||
cp.v = cc.p;
|
||||
cp._v = cc._p;
|
||||
cp.vzero = cp.v(0,0);
|
||||
|
||||
//
|
||||
// OpenGL Helpers
|
||||
//
|
||||
var gl = gl || {};
|
||||
gl.NEAREST = 0x2600;
|
||||
gl.LINEAR = 0x2601;
|
||||
gl.REPEAT = 0x2901;
|
||||
gl.CLAMP_TO_EDGE = 0x812F;
|
||||
gl.CLAMP_TO_BORDER = 0x812D;
|
||||
gl.LINEAR_MIPMAP_NEAREST = 0x2701;
|
||||
gl.NEAREST_MIPMAP_NEAREST = 0x2700;
|
||||
gl.ZERO = 0;
|
||||
gl.ONE = 1;
|
||||
gl.SRC_COLOR = 0x0300;
|
||||
gl.ONE_MINUS_SRC_COLOR = 0x0301;
|
||||
gl.SRC_ALPHA = 0x0302;
|
||||
gl.ONE_MINUS_SRC_ALPHA = 0x0303;
|
||||
gl.DST_ALPHA = 0x0304;
|
||||
gl.ONE_MINUS_DST_ALPHA = 0x0305;
|
||||
gl.DST_COLOR = 0x0306;
|
||||
gl.ONE_MINUS_DST_COLOR = 0x0307;
|
||||
gl.SRC_ALPHA_SATURATE = 0x0308;
|
||||
|
|
@ -1,219 +0,0 @@
|
|||
//
|
||||
// http://www.cocos2d-iphone.org
|
||||
// http://www.cocos2d-html5.org
|
||||
// http://www.cocos2d-x.org
|
||||
//
|
||||
// Javascript + cocos2d actions tests
|
||||
//
|
||||
|
||||
require("js/helper.js");
|
||||
|
||||
director = cc.Director.getInstance();
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
scenes = []
|
||||
currentScene = 0;
|
||||
|
||||
nextScene = function () {
|
||||
currentScene = currentScene + 1;
|
||||
if( currentScene >= scenes.length )
|
||||
currentScene = 0;
|
||||
|
||||
withTransition = true;
|
||||
loadScene(currentScene);
|
||||
};
|
||||
|
||||
previousScene = function () {
|
||||
currentScene = currentScene -1;
|
||||
if( currentScene < 0 )
|
||||
currentScene = scenes.length -1;
|
||||
|
||||
withTransition = true;
|
||||
loadScene(currentScene);
|
||||
};
|
||||
|
||||
restartScene = function () {
|
||||
loadScene( currentScene );
|
||||
};
|
||||
|
||||
loadScene = function (sceneIdx)
|
||||
{
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var scene = new cc.Scene();
|
||||
scene.init();
|
||||
var layer = new scenes[ sceneIdx ]();
|
||||
|
||||
scene.addChild( layer );
|
||||
|
||||
// scene.walkSceneGraph(0);
|
||||
|
||||
director.replaceScene( scene );
|
||||
// __jsc__.garbageCollect();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Base Layer
|
||||
//
|
||||
|
||||
BaseLayer = cc.LayerGradient.extend({
|
||||
|
||||
ctor:function () {
|
||||
|
||||
var parent = new cc.LayerGradient();
|
||||
__associateObjWithNative(this, parent);
|
||||
this.init(cc.c4b(0, 0, 0, 255), cc.c4b(0, 128, 255, 255));
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "No Title";
|
||||
},
|
||||
|
||||
subtitle:function () {
|
||||
return "";
|
||||
},
|
||||
|
||||
code:function () {
|
||||
return "";
|
||||
},
|
||||
|
||||
restartCallback:function (sender) {
|
||||
restartScene();
|
||||
},
|
||||
|
||||
nextCallback:function (sender) {
|
||||
nextScene();
|
||||
},
|
||||
|
||||
backCallback:function (sender) {
|
||||
previousScene();
|
||||
},
|
||||
|
||||
onEnter:function () {
|
||||
// DO NOT CALL this._super()
|
||||
// this._super();
|
||||
|
||||
// add title and subtitle
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 28);
|
||||
this.addChild(label, 1);
|
||||
label.setPosition( cc.p(winSize.width / 2, winSize.height - 40));
|
||||
|
||||
var strSubtitle = this.subtitle();
|
||||
if (strSubtitle != "") {
|
||||
var l = cc.LabelTTF.create(strSubtitle, "Thonburi", 16);
|
||||
this.addChild(l, 1);
|
||||
l.setPosition( cc.p(winSize.width / 2, winSize.height - 70));
|
||||
}
|
||||
|
||||
var strCode = this.code();
|
||||
if( strCode !="" ) {
|
||||
var label = cc.LabelTTF.create(strCode, 'CourierNewPSMT', 16);
|
||||
label.setPosition( cc.p( winSize.width/2, winSize.height-120) );
|
||||
this.addChild( label,10 );
|
||||
|
||||
var labelbg = cc.LabelTTF.create(strCode, 'CourierNewPSMT', 16);
|
||||
labelbg.setColor( cc.c3b(10,10,255) );
|
||||
labelbg.setPosition( cc.p( winSize.width/2 +1, winSize.height-120 -1) );
|
||||
this.addChild( labelbg,9);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// MainTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
MainTest = BaseLayer.extend({
|
||||
|
||||
_menu : null,
|
||||
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
cc.MenuItemFont.setFontSize(24);
|
||||
var item1 = cc.MenuItemFont.create("Actions: Basic Tests", this, function() { require("js/test-actions.js"); } );
|
||||
var item2 = cc.MenuItemFont.create("Actions: Ease Tests", this, function() { require("js/test-easeactions.js"); } );
|
||||
var item3 = cc.MenuItemFont.create("Actions: Progress Tests", this, function() { require("js/test-actionsprogress.js"); } );
|
||||
var item4 = cc.MenuItemFont.create("Chipmunk Tests", this, function() { require("js/test-chipmunk.js"); } );
|
||||
var item5 = cc.MenuItemFont.create("Effects Tests", this, function() { require("js/test-effects.js"); } );
|
||||
var item6 = cc.MenuItemFont.create("Label Tests", this, function() { require("js/test-label.js"); } );
|
||||
var item7 = cc.MenuItemFont.create("Menu Tests", this, function() { require("js/test-menu.js"); } );
|
||||
var item8 = cc.MenuItemFont.create("Parallax Tests", this, function() { require("js/test-parallax.js"); } );
|
||||
var item9 = cc.MenuItemFont.create("Particle Tests", this, function() { require("js/test-particles.js"); } );
|
||||
var item10 = cc.MenuItemFont.create("RenderTexture Tests", this, function() { require("js/test-rendertexture.js"); } );
|
||||
var item11 = cc.MenuItemFont.create("Sprite Tests", this, function() { require("js/test-sprite.js"); } );
|
||||
var item12 = cc.MenuItemFont.create("Tilemap Tests", this, function() { require("js/test-tilemap.js"); } );
|
||||
var item13 = cc.MenuItemFont.create("CocosDenshion Tests", this, function() { require("js/test-cocosdenshion.js"); } );
|
||||
var item14 = cc.MenuItemFont.create("cocos2d presentation", this, function() { require("js/test-cocos2djs.js"); } );
|
||||
var item14 = cc.MenuItemFont.create("Performance test", this, function() { require("js/PerformanceTest/PerformanceTest.js"); } );
|
||||
|
||||
|
||||
this._menu = cc.Menu.create( item1, item2, item3, item4, item5, item6, item7, item8, item9, item10, item11, item12, item13, item14 );
|
||||
this._menu.alignItemsVertically();
|
||||
|
||||
this._menu.setPosition( cc.p( winSize.width/2, winSize.height/2) );
|
||||
|
||||
this.addChild( this._menu );
|
||||
|
||||
var platform = __getPlatform();
|
||||
if( platform.substring(0,7) == 'desktop' )
|
||||
this.setMouseEnabled( true );
|
||||
else if( platform.substring(0,6) == 'mobile' )
|
||||
this.setTouchEnabled( true );
|
||||
},
|
||||
|
||||
onTouchesMoved:function (touches, event) {
|
||||
var delta = touches[0].getDelta();
|
||||
var current = this._menu.getPosition();
|
||||
this._menu.setPosition( cc.p( current.x, current.y + delta.y ) );
|
||||
return true;
|
||||
},
|
||||
|
||||
onMouseDragged : function( event ) {
|
||||
var delta = event.getDelta();
|
||||
var current = this._menu.getPosition();
|
||||
this._menu.setPosition( cc.p( current.x, current.y + delta.y ) );
|
||||
return true;
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "Javascript tests";
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
|
||||
//
|
||||
// Order of tests
|
||||
//
|
||||
|
||||
scenes.push( MainTest);
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Main entry point
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
function run()
|
||||
{
|
||||
var scene = cc.Scene.create();
|
||||
var layer = new scenes[currentScene]();
|
||||
scene.addChild( layer );
|
||||
|
||||
var runningScene = director.getRunningScene();
|
||||
if( runningScene == null )
|
||||
director.runWithScene( scene );
|
||||
else
|
||||
director.replaceScene( cc.TransitionSplitCols.create(1, scene ) );
|
||||
|
||||
director.setDisplayStats(true);
|
||||
}
|
||||
|
||||
run();
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
require("js/helper.js");
|
||||
|
||||
var randColorComp = function () {
|
||||
return Math.round(Math.random() * 255);
|
||||
};
|
||||
|
||||
var director = cc.Director.getInstance();
|
||||
var audioEngine = cc.AudioEngine.getInstance();
|
||||
var _winSize = director.getWinSize();
|
||||
var winSize = {width:_winSize[0], height:_winSize[1]};
|
||||
|
||||
log("size: " + winSize.width + "," + winSize.height);
|
||||
|
||||
var scene = cc.Scene.create();
|
||||
var layer = cc.LayerGradient.create(cc.c4(0, 0, 0, 255), cc.c4(0, 128, 255, 255));
|
||||
scene.addChild(layer, 0, 1337);
|
||||
|
||||
for (var i=0; i < 30; i++) {
|
||||
var sprite = cc.Sprite.create("Icon.png");
|
||||
var pos = cc.p(Math.random() * winSize.width, Math.random() * winSize.height);
|
||||
sprite.setPosition(pos);
|
||||
sprite.setColor(cc.c3(randColorComp(), randColorComp(), randColorComp()));
|
||||
layer.addChild(sprite);
|
||||
}
|
||||
|
||||
var menu = cc.Menu.create();
|
||||
var label = cc.LabelTTF.create("Testing Label TTF", "Arial", 20.0);
|
||||
label.func = function () {
|
||||
log("menu action from label " + this);
|
||||
}
|
||||
var item = cc.MenuItemLabel.create(label, menu, label.func);
|
||||
menu.addChild(item);
|
||||
menu.setPosition(cc.p(winSize.width / 2, winSize.height / 2));
|
||||
|
||||
var touch = new cc.Touch();
|
||||
var pt = touch.locationInView();
|
||||
log("touch: " + touch.x + "," + touch.y);
|
||||
|
||||
layer.addChild(menu);
|
||||
|
||||
//audioEngine.setBackgroundMusicVolume(0.5);
|
||||
//audioEngine.playBackgroundMusic("bgmusic.mp3", true);
|
||||
|
||||
var testLayer = scene.getChildByTag(1337);
|
||||
log("layer == testLayer: " + (layer == testLayer));
|
||||
|
||||
director.runWithScene(scene);
|
|
@ -1,227 +0,0 @@
|
|||
//
|
||||
// http://www.cocos2d-iphone.org
|
||||
// http://www.cocos2d-html5.org
|
||||
// http://www.cocos2d-x.org
|
||||
//
|
||||
// Javascript + cocos2d actions tests
|
||||
//
|
||||
|
||||
require("js/helpers.js");
|
||||
|
||||
director = cc.Director.sharedDirector();
|
||||
_winSize = director.getWinSize();
|
||||
winSize = {width:_winSize[0], height:_winSize[1]};
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
scenes = []
|
||||
currentScene = 0;
|
||||
|
||||
cc.log("main2.js:1");
|
||||
|
||||
nextScene = function () {
|
||||
currentScene = currentScene + 1;
|
||||
if( currentScene >= scenes.length )
|
||||
currentScene = 0;
|
||||
|
||||
withTransition = true;
|
||||
loadScene(currentScene);
|
||||
};
|
||||
|
||||
previousScene = function () {
|
||||
currentScene = currentScene -1;
|
||||
if( currentScene < 0 )
|
||||
currentScene = scenes.length -1;
|
||||
|
||||
withTransition = true;
|
||||
loadScene(currentScene);
|
||||
};
|
||||
|
||||
restartScene = function () {
|
||||
loadScene( currentScene );
|
||||
};
|
||||
|
||||
loadScene = function (sceneIdx)
|
||||
{
|
||||
_winSize = director.getWinSize();
|
||||
winSize = {width:_winSize[0], height:_winSize[1]};
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var scene = new cc.Scene();
|
||||
scene.init();
|
||||
var layer = new scenes[ sceneIdx ]();
|
||||
|
||||
scene.addChild( layer );
|
||||
|
||||
// scene.walkSceneGraph(0);
|
||||
|
||||
director.replaceScene( scene );
|
||||
// __jsc__.garbageCollect();
|
||||
}
|
||||
|
||||
|
||||
cc.log("main2.js:2");
|
||||
|
||||
//
|
||||
// Base Layer
|
||||
//
|
||||
|
||||
BaseLayer = cc.LayerGradient.extend({
|
||||
|
||||
ctor:function () {
|
||||
|
||||
var parent = new cc.LayerGradient();
|
||||
__associateObjWithNative(this, parent);
|
||||
this.init(cc.c4(0, 0, 0, 255), cc.c4(0, 128, 255, 255));
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "No Title";
|
||||
},
|
||||
|
||||
subtitle:function () {
|
||||
return "";
|
||||
},
|
||||
|
||||
code:function () {
|
||||
return "";
|
||||
},
|
||||
|
||||
restartCallback:function (sender) {
|
||||
restartScene();
|
||||
},
|
||||
|
||||
nextCallback:function (sender) {
|
||||
nextScene();
|
||||
},
|
||||
|
||||
backCallback:function (sender) {
|
||||
previousScene();
|
||||
},
|
||||
|
||||
onEnter:function () {
|
||||
// DO NOT CALL this._super()
|
||||
// this._super();
|
||||
cc.log("baselayer.onenter");
|
||||
// add title and subtitle
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 28);
|
||||
this.addChild(label, 1);
|
||||
label.setPosition( cc.p(winSize.width / 2, winSize.height - 40));
|
||||
|
||||
var strSubtitle = this.subtitle();
|
||||
if (strSubtitle != "") {
|
||||
var l = cc.LabelTTF.create(strSubtitle, "Thonburi", 16);
|
||||
this.addChild(l, 1);
|
||||
l.setPosition( cc.p(winSize.width / 2, winSize.height - 70));
|
||||
}
|
||||
|
||||
var strCode = this.code();
|
||||
if( strCode !="" ) {
|
||||
var label = cc.LabelTTF.create(strCode, 'CourierNewPSMT', 16);
|
||||
label.setPosition( cc.p( winSize.width/2, winSize.height-120) );
|
||||
this.addChild( label,10 );
|
||||
|
||||
var labelbg = cc.LabelTTF.create(strCode, 'CourierNewPSMT', 16);
|
||||
labelbg.setColor( cc.c3(10,10,255) );
|
||||
labelbg.setPosition( cc.p( winSize.width/2 +1, winSize.height-120 -1) );
|
||||
this.addChild( labelbg,9);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
cc.log("main2.js:3");
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// MainTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
MainTest = BaseLayer.extend({
|
||||
|
||||
_menu : null,
|
||||
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
cc.MenuItemFont.setFontSize(24);
|
||||
var item1 = cc.MenuItemFont.create("Actions: Basic Tests", this, function() { require("js/test-actions.js"); } );
|
||||
var item2 = cc.MenuItemFont.create("Actions: Ease Tests", this, function() { require("js/test-easeactions.js"); } );
|
||||
var item3 = cc.MenuItemFont.create("Actions: Progress Tests", this, function() { require("js/test-actionsprogress.js"); } );
|
||||
var item4 = cc.MenuItemFont.create("Chipmunk Tests", this, function() { require("js/test-chipmunk.js"); } );
|
||||
var item5 = cc.MenuItemFont.create("Effects Tests", this, function() { require("js/test-effects.js"); } );
|
||||
var item6 = cc.MenuItemFont.create("Label Tests", this, function() { require("js/test-label.js"); } );
|
||||
var item7 = cc.MenuItemFont.create("Menu Tests", this, function() { require("js/test-menu.js"); } );
|
||||
var item8 = cc.MenuItemFont.create("Parallax Tests", this, function() { require("js/test-parallax.js"); } );
|
||||
var item9 = cc.MenuItemFont.create("Particle Tests", this, function() { require("js/test-particles.js"); } );
|
||||
var item10 = cc.MenuItemFont.create("RenderTexture Tests", this, function() { require("js/test-rendertexture.js"); } );
|
||||
var item11 = cc.MenuItemFont.create("Sprite Tests", this, function() { require("js/test-sprite.js"); } );
|
||||
var item12 = cc.MenuItemFont.create("Tilemap Tests", this, function() { require("js/test-tilemap.js"); } );
|
||||
var item13 = cc.MenuItemFont.create("CocosDenshion Tests", this, function() { require("js/test-cocosdenshion.js"); } );
|
||||
var item14 = cc.MenuItemFont.create("cocos2d presentation", this, function() { require("js/test-cocos2djs.js"); } );
|
||||
|
||||
|
||||
this._menu = cc.Menu.create(item1, item2, item3, item4, item5, item6, item7, item8, item9, item10, item11, item12, item13, item14);
|
||||
this._menu.alignItemsVertically();
|
||||
|
||||
this._menu.setPosition( cc.p( winSize.width/2, winSize.height/2) );
|
||||
|
||||
this.addChild( this._menu );
|
||||
|
||||
var platform = __getPlatform();
|
||||
if( platform.substring(0,7) == 'desktop' )
|
||||
this.setMouseEnabled( true );
|
||||
else if( platform.substring(0,6) == 'mobile' )
|
||||
this.setTouchEnabled( true );
|
||||
},
|
||||
|
||||
onTouchesMoved:function (touches, event) {
|
||||
var delta = touches[0].getDelta();
|
||||
var current = this._menu.getPosition();
|
||||
this._menu.setPosition( cc.p( current[0], current[1] + delta[1] ) );
|
||||
return true;
|
||||
},
|
||||
|
||||
onMouseDragged : function( event ) {
|
||||
var delta = event.getDelta();
|
||||
var current = this._menu.getPosition();
|
||||
this._menu.setPosition( cc.p( current[0], current[1] + delta[1] ) );
|
||||
return true;
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "Javascript tests";
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
cc.log("main2.js:4");
|
||||
|
||||
//
|
||||
// Order of tests
|
||||
//
|
||||
|
||||
scenes.push( MainTest);
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Main entry point
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
function run()
|
||||
{
|
||||
var scene = cc.Scene.create();
|
||||
var layer = new scenes[currentScene]();
|
||||
scene.addChild( layer );
|
||||
|
||||
var runningScene = director.getRunningScene();
|
||||
if( runningScene == null )
|
||||
director.runWithScene( scene );
|
||||
else
|
||||
director.replaceScene( cc.TransitionSplitCols.create(1, scene, cc.c3(0, 0, 0) ) );
|
||||
|
||||
director.setDisplayStats(true);
|
||||
}
|
||||
|
||||
cc.log("main2.js:5");
|
||||
run();
|
||||
cc.log("main2.js:6");
|
|
@ -1,2 +0,0 @@
|
|||
var s = new SimpleNativeClass();
|
||||
s.doSomeProcessing("hello", "world");
|
|
@ -1,784 +0,0 @@
|
|||
//
|
||||
// http://www.cocos2d-iphone.org
|
||||
//
|
||||
// Javascript + cocos2d sprite tests
|
||||
//
|
||||
|
||||
require("js/helpers.js");
|
||||
|
||||
director = cc.Director.sharedDirector();
|
||||
_winSize = director.getWinSize();
|
||||
winSize = {width:_winSize[0], height:_winSize[1]};
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var scenes = []
|
||||
var currentScene = 0;
|
||||
|
||||
var nextSpriteTestAction = function () {
|
||||
currentScene = currentScene + 1;
|
||||
if( currentScene >= scenes.length )
|
||||
currentScene = 0;
|
||||
|
||||
loadScene(currentScene);
|
||||
};
|
||||
var backSpriteTestAction = function () {
|
||||
currentScene = currentScene -1;
|
||||
if( currentScene < 0 )
|
||||
currentScene = scenes.length -1;
|
||||
|
||||
loadScene(currentScene);
|
||||
};
|
||||
var restartSpriteTestAction = function () {
|
||||
loadScene( currentScene );
|
||||
};
|
||||
|
||||
var loadScene = function (sceneIdx)
|
||||
{
|
||||
_winSize = director.getWinSize();
|
||||
winSize = {width:_winSize[0], height:_winSize[1]};
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var scene = new cc.Scene();
|
||||
scene.init();
|
||||
var layer = new scenes[ sceneIdx ]();
|
||||
|
||||
scene.addChild( layer );
|
||||
|
||||
// scene.walkSceneGraph(0);
|
||||
|
||||
director.replaceScene( scene );
|
||||
// __jsc__.garbageCollect();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// BaseLayer
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var BaseLayer = function() {
|
||||
|
||||
//
|
||||
// VERY IMPORTANT
|
||||
//
|
||||
// Only subclasses of a native classes MUST call __associateObjectWithNative
|
||||
// Failure to do so, it will crash.
|
||||
//
|
||||
var parent = goog.base(this);
|
||||
__associateObjWithNative( this, parent );
|
||||
this.init();
|
||||
|
||||
this.title = function () {
|
||||
return "No title";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "No Subtitle";
|
||||
}
|
||||
|
||||
}
|
||||
goog.inherits(BaseLayer, cc.Layer );
|
||||
|
||||
//
|
||||
// Instance 'base' methods
|
||||
// XXX: Should be defined after "goog.inherits"
|
||||
//
|
||||
BaseLayer.prototype.onEnter = function() {
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 28);
|
||||
this.addChild(label, 1);
|
||||
label.setPosition( cc.p(winSize.width / 2, winSize.height - 50));
|
||||
|
||||
var strSubtitle = this.subtitle();
|
||||
if (strSubtitle != "") {
|
||||
var l = cc.LabelTTF.create(strSubtitle, "Thonburi", 16);
|
||||
this.addChild(l, 1);
|
||||
l.setPosition( cc.p(winSize.width / 2, winSize.height - 80));
|
||||
}
|
||||
|
||||
// Menu
|
||||
var item1 = cc.MenuItemImage.create("b1.png", "b2.png", this, this.backCallback);
|
||||
var item2 = cc.MenuItemImage.create("r1.png", "r2.png", this, this.restartCallback);
|
||||
var item3 = cc.MenuItemImage.create("f1.png", "f2.png", this, this.nextCallback);
|
||||
var item4 = cc.MenuItemFont.create("back", function() { require("js/main.js"); }, this );
|
||||
item4.setFontSizeObj( 22 );
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3, item4 );
|
||||
|
||||
menu.setPosition( cc.p(0,0) );
|
||||
item1.setPosition( cc.p(winSize.width / 2 - 100, 30));
|
||||
item2.setPosition( cc.p(winSize.width / 2, 30));
|
||||
item3.setPosition( cc.p(winSize.width / 2 + 100, 30));
|
||||
item4.setPosition( cc.p(winSize.width - 60, winSize.height - 30 ) );
|
||||
|
||||
this.addChild(menu, 1);
|
||||
}
|
||||
|
||||
BaseLayer.prototype.restartCallback = function (sender) {
|
||||
cc.log("restart called");
|
||||
restartSpriteTestAction();
|
||||
}
|
||||
|
||||
BaseLayer.prototype.nextCallback = function (sender) {
|
||||
cc.log("next called");
|
||||
nextSpriteTestAction();
|
||||
}
|
||||
|
||||
BaseLayer.prototype.backCallback = function (sender) {
|
||||
cc.log("back called");
|
||||
backSpriteTestAction();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Sprite Touch test
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteTouchTest = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.initialize = function() {
|
||||
var platform = __getPlatform();
|
||||
if( platform.substring(0,7) == 'desktop' )
|
||||
this.setMouseEnabled( true );
|
||||
else if( platform.substring(0,6) == 'mobile' )
|
||||
this.setTouchEnabled( true );
|
||||
this.addSprite( centerPos );
|
||||
}
|
||||
|
||||
this.addSprite = function(pos) {
|
||||
var sprite = this.createSprite( pos );
|
||||
this.addChild( sprite );
|
||||
}
|
||||
|
||||
this.title = function () {
|
||||
return "Sprite: Simple action test";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "Tap screen to add more sprites";
|
||||
}
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
goog.inherits(SpriteTouchTest, BaseLayer );
|
||||
|
||||
SpriteTouchTest.prototype.onMouseDown = function( event ) {
|
||||
this.addSprite( event.getLocation() );
|
||||
}
|
||||
|
||||
SpriteTouchTest.prototype.onTouchesEnded = function( touches, event ) {
|
||||
var l = touches.length;
|
||||
for( var i=0; i < l; i++) {
|
||||
this.addSprite( touches[i].getLocation() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SpriteTouchTest.prototype.createSprite = function( pos ) {
|
||||
var idx = Math.random() * 1400 / 100;
|
||||
idx = Math.floor( idx );
|
||||
var x = Math.floor(idx%5) * 85;
|
||||
var y = Math.floor(idx/5) * 121;
|
||||
|
||||
var sprite = cc.Sprite.create("grossini_dance_atlas.png", cc.rect(x,y,85,121) );
|
||||
sprite.setPosition( pos );
|
||||
|
||||
var rand = Math.random();
|
||||
|
||||
var action;
|
||||
if( rand < 0.20 ) {
|
||||
action = cc.ScaleBy.create(3, 2 );
|
||||
} else if(rand < 0.40) {
|
||||
action = cc.RotateBy.create(3, 360 );
|
||||
} else if( rand < 0.60) {
|
||||
action = cc.Blink.create(1, 3 );
|
||||
} else if( rand < 0.8 ) {
|
||||
action = cc.TintBy.create(2, 0, -255, -255 );
|
||||
} else {
|
||||
action = cc.FadeOut.create( 2 );
|
||||
}
|
||||
var action_back = action.reverse();
|
||||
var seq = cc.Sequence.create(action, action_back);
|
||||
|
||||
sprite.runAction( cc.RepeatForever.create( seq ) );
|
||||
|
||||
return sprite;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Sprite Batch Touch test
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteBatchTouchTest = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.initialize = function() {
|
||||
this.batch = cc.SpriteBatchNode.create("grossini_dance_atlas.png", 50 );
|
||||
this.addChild( this.batch );
|
||||
|
||||
var platform = __getPlatform();
|
||||
if( platform == 'OSX' ) {
|
||||
this.setIsMouseEnabled( true );
|
||||
} else if( platform == 'iOS' ) {
|
||||
this.setIsTouchEnabled( true );
|
||||
}
|
||||
}
|
||||
|
||||
this.addSprite = function(pos) {
|
||||
var sprite = this.createSprite( pos );
|
||||
this.batch.addChild( sprite );
|
||||
}
|
||||
|
||||
this.title = function () {
|
||||
return "SpriteBatch: Simple action test";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "Tap screen to add more sprites";
|
||||
}
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
goog.inherits( SpriteBatchTouchTest, SpriteTouchTest );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Sprite vs. SpriteBatch Animation
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteFrameTest = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.initialize = function() {
|
||||
var cache = cc.SpriteFrameCache.sharedSpriteFrameCache();
|
||||
cache.addSpriteFramesWithFile( "grossini.plist" );
|
||||
cache.addSpriteFramesWithFile( "grossini_gray.plist", "grossini_gray.png" );
|
||||
cache.addSpriteFramesWithFile( "grossini_blue.plist", "grossini_blue.png" );
|
||||
|
||||
//
|
||||
// Animation using Sprite batch
|
||||
//
|
||||
// A CCSpriteBatchNode can reference one and only one texture (one .png file)
|
||||
// Sprites that are contained in that texture can be instantiatied as CCSprites and then added to the CCSpriteBatchNode
|
||||
// All CCSprites added to a CCSpriteBatchNode are drawn in one OpenGL ES draw call
|
||||
// If the CCSprites are not added to a CCSpriteBatchNode then an OpenGL ES draw call will be needed for each one, which is less efficient
|
||||
//
|
||||
// When you animate a sprite, CCAnimation changes the frame of the sprite using setDisplayFrame: (this is why the animation must be in the same texture)
|
||||
// When setDisplayFrame: is used in the CCAnimation it changes the frame to one specified by the CCSpriteFrames that were added to the animation,
|
||||
// but texture id is still the same and so the sprite is still a child of the CCSpriteBatchNode,
|
||||
// and therefore all the animation sprites are also drawn as part of the CCSpriteBatchNode
|
||||
//
|
||||
|
||||
var sprite1 = cc.Sprite.createWithSpriteFrameName("grossini_dance_01.png");
|
||||
sprite1.setPosition( cc.p( winSize.width/2-80, winSize.height/2) );
|
||||
|
||||
var spritebatch = cc.SpriteBatchNode.create("grossini.pvr.gz");
|
||||
spritebatch.addChild(sprite1);
|
||||
this.addChild( spritebatch );
|
||||
|
||||
var frames = []
|
||||
for( var i = 1; i < 15; i++) {
|
||||
|
||||
if( i < 10 ) {
|
||||
var name = "grossini_dance_0" + i + ".png";
|
||||
} else {
|
||||
var name = "grossini_dance_" + i + ".png";
|
||||
}
|
||||
|
||||
var frame = cache.spriteFrameByName( name );
|
||||
frames.push( frame );
|
||||
}
|
||||
|
||||
var animation = cc.Animation.create( frames, 0.3 );
|
||||
// 14 frames * 1sec = 14 seconds
|
||||
sprite1.runAction( cc.RepeatForever.create( cc.Animate.create( animation ) ) );
|
||||
|
||||
|
||||
//
|
||||
// Animation using standard Sprite
|
||||
//
|
||||
//
|
||||
var sprite2 = cc.Sprite.createWithSpriteFrameName( "grossini_dance_01.png" );
|
||||
sprite2.setPosition( cc.p( winSize.width/2 + 80, winSize.height/2) );
|
||||
this.addChild( sprite2 );
|
||||
|
||||
var moreFrames = []
|
||||
for(var i = 1; i < 15; i++) {
|
||||
if( i < 10 ) {
|
||||
var name = "grossini_dance_gray_0" + i + ".png";
|
||||
} else {
|
||||
var name = "grossini_dance_gray_" + i + ".png";
|
||||
}
|
||||
var frame = cache.spriteFrameByName( name );
|
||||
moreFrames.push( frame );
|
||||
}
|
||||
for( var i = 1; i < 5; i++) {
|
||||
var name = "grossini_blue_0" + i + ".png";
|
||||
var frame = cache.spriteFrameByName( name );
|
||||
moreFrames.push( frame );
|
||||
}
|
||||
|
||||
|
||||
moreFrames.concat( frames );
|
||||
var animMixed = cc.Animation.create( moreFrames, 0.3 );
|
||||
|
||||
// 32 frames * 1 seconds = 32 seconds
|
||||
sprite2.runAction( cc.RepeatForever.create( cc.Animate.create( animMixed ) ) );
|
||||
|
||||
// to test issue #732, uncomment the following line
|
||||
sprite2.setFlipX( false );
|
||||
sprite2.setFlipY( false );
|
||||
}
|
||||
|
||||
this.title = function () {
|
||||
return "Sprite vs. SpriteBatchNode animation";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "Testing issue #792";
|
||||
}
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
goog.inherits( SpriteFrameTest, BaseLayer );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteAnchorPoint
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteAnchorPoint = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.initialize = function() {
|
||||
for(var i=0;i<3;i++) {
|
||||
var sprite = cc.Sprite.create("grossini_dance_atlas.png", cc.rect(85*i, 121*1, 85, 121) );
|
||||
sprite.setPosition( cc.p( winSize.width/4*(i+1), winSize.height/2) );
|
||||
|
||||
var point = cc.Sprite.create( "r1.png" );
|
||||
point.setScale( 0.25 );
|
||||
point.setPosition( sprite.getPosition() );
|
||||
this.addChild( point, 10 );
|
||||
|
||||
if( i == 0 ) {
|
||||
sprite.setAnchorPoint( cc.p( 0, 0) );
|
||||
} else if( i == 1 ) {
|
||||
sprite.setAnchorPoint( cc.p(0.5, 0.5) );
|
||||
} else if( i == 2 ) {
|
||||
sprite.setAnchorPoint( cc.p(1,1) );
|
||||
}
|
||||
|
||||
point.setPosition( sprite.getPosition() );
|
||||
|
||||
var rotate = cc.RotateBy.create(10, 360);
|
||||
var action = cc.RepeatForever.create( rotate );
|
||||
|
||||
sprite.runAction( action );
|
||||
this.addChild( sprite, i );
|
||||
}
|
||||
}
|
||||
|
||||
this.title = function () {
|
||||
return "Sprite: anchor point";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "Testing 3 different anchor points";
|
||||
}
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
goog.inherits( SpriteAnchorPoint, BaseLayer );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteBatchAnchorPoint
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteBatchAnchorPoint = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.initialize = function() {
|
||||
var batch = cc.SpriteBatchNode.create( "grossini_dance_atlas.png" );
|
||||
for(var i=0;i<3;i++) {
|
||||
var sprite = cc.Sprite.create("grossini_dance_atlas.png", cc.rect(85*i, 121*1, 85, 121) );
|
||||
sprite.setPosition( cc.p( winSize.width/4*(i+1), winSize.height/2) );
|
||||
|
||||
var point = cc.Sprite.create( "r1.png" );
|
||||
point.setScale( 0.25 );
|
||||
point.setPosition( sprite.getPosition() );
|
||||
this.addChild( point, 10 );
|
||||
|
||||
if( i == 0 ) {
|
||||
sprite.setAnchorPoint( cc.p( 0, 0) );
|
||||
} else if( i == 1 ) {
|
||||
sprite.setAnchorPoint( cc.p(0.5, 0.5) );
|
||||
} else if( i == 2 ) {
|
||||
sprite.setAnchorPoint( cc.p(1,1) );
|
||||
}
|
||||
|
||||
point.setPosition( sprite.getPosition() );
|
||||
|
||||
var rotate = cc.RotateBy.create(10, 360);
|
||||
var action = cc.RepeatForever.create( rotate );
|
||||
|
||||
sprite.runAction( action );
|
||||
batch.addChild( sprite, i );
|
||||
}
|
||||
this.addChild( batch );
|
||||
}
|
||||
|
||||
this.title = function () {
|
||||
return "Sprite Batch: anchor point";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "Testing 3 different anchor points";
|
||||
}
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
goog.inherits( SpriteBatchAnchorPoint, BaseLayer );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteOffsetAnchorFlip
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteOffsetAnchorFlip = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.initialize = function() {
|
||||
var cache = cc.SpriteFrameCache.sharedSpriteFrameCache();
|
||||
cache.addSpriteFramesWithFile("grossini.plist");
|
||||
cache.addSpriteFramesWithFile("grossini_gray.plist", "grossini_gray.png");
|
||||
|
||||
for(var i=0;i<3;i++) {
|
||||
var sprite = cc.Sprite.create("grossini_dance_atlas.png", cc.rect(85*i, 121*1, 85, 121) );
|
||||
sprite.setPosition( cc.p( winSize.width/4*(i+1), winSize.height/2) );
|
||||
|
||||
var point = cc.Sprite.create( "r1.png" );
|
||||
point.setScale( 0.25 );
|
||||
point.setPosition( sprite.getPosition() );
|
||||
this.addChild( point, 10 );
|
||||
|
||||
if( i == 0 ) {
|
||||
sprite.setAnchorPoint( cc.p( 0, 0) );
|
||||
} else if( i == 1 ) {
|
||||
sprite.setAnchorPoint( cc.p(0.5, 0.5) );
|
||||
} else if( i == 2 ) {
|
||||
sprite.setAnchorPoint( cc.p(1,1) );
|
||||
}
|
||||
|
||||
point.setPosition( sprite.getPosition() );
|
||||
|
||||
var frames = []
|
||||
for( var j = 1; j < 15; j++) {
|
||||
|
||||
if( j < 10 ) {
|
||||
var name = "grossini_dance_0" + j + ".png";
|
||||
} else {
|
||||
var name = "grossini_dance_" + j + ".png";
|
||||
}
|
||||
|
||||
var frame = cache.spriteFrameByName( name );
|
||||
frames.push( frame );
|
||||
}
|
||||
|
||||
var animation = cc.Animation.create( frames, 0.3 );
|
||||
sprite.runAction( cc.RepeatForever.create( cc.Animate.create( animation ) ) );
|
||||
|
||||
var flip = cc.FlipY.create( true );
|
||||
var flip_back = cc.FlipY.create( false );
|
||||
var delay = cc.DelayTime.create( 1 );
|
||||
var delay2 = cc.DelayTime.create( 1 );
|
||||
var seq = cc.Sequence.create( delay, flip, delay2, flip_back );
|
||||
sprite.runAction( cc.RepeatForever.create( seq ) );
|
||||
|
||||
this.addChild( sprite );
|
||||
}
|
||||
}
|
||||
|
||||
this.title = function () {
|
||||
return "Sprite offset + anchor + flip";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "issue #1078";
|
||||
}
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
goog.inherits( SpriteOffsetAnchorFlip, BaseLayer );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteBatchOffsetAnchorFlip
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteBatchOffsetAnchorFlip = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.initialize = function() {
|
||||
var cache = cc.SpriteFrameCache.sharedSpriteFrameCache();
|
||||
cache.addSpriteFramesWithFile("grossini.plist");
|
||||
cache.addSpriteFramesWithFile("grossini_gray.plist", "grossini_gray.png");
|
||||
|
||||
var batch = cc.SpriteBatchNode.create("grossini.pvr.gz");
|
||||
|
||||
for(var i=0;i<3;i++) {
|
||||
var sprite = cc.Sprite.createWithSpriteFrameName("grossini_dance_01.png");
|
||||
sprite.setPosition( cc.p( winSize.width/4*(i+1), winSize.height/2) );
|
||||
|
||||
var point = cc.Sprite.create( "r1.png" );
|
||||
point.setScale( 0.25 );
|
||||
point.setPosition( sprite.getPosition() );
|
||||
this.addChild( point, 10 );
|
||||
|
||||
if( i == 0 ) {
|
||||
sprite.setAnchorPoint( cc.p( 0, 0) );
|
||||
} else if( i == 1 ) {
|
||||
sprite.setAnchorPoint( cc.p(0.5, 0.5) );
|
||||
} else if( i == 2 ) {
|
||||
sprite.setAnchorPoint( cc.p(1,1) );
|
||||
}
|
||||
|
||||
point.setPosition( sprite.getPosition() );
|
||||
|
||||
var frames = []
|
||||
for( var j = 1; j < 15; j++) {
|
||||
|
||||
if( j < 10 ) {
|
||||
var name = "grossini_dance_0" + j + ".png";
|
||||
} else {
|
||||
var name = "grossini_dance_" + j + ".png";
|
||||
}
|
||||
|
||||
var frame = cache.spriteFrameByName( name );
|
||||
frames.push( frame );
|
||||
}
|
||||
|
||||
var animation = cc.Animation.create( frames, 0.3 );
|
||||
sprite.runAction( cc.RepeatForever.create( cc.Animate.create( animation ) ) );
|
||||
|
||||
var flip = cc.FlipY.create( true );
|
||||
var flip_back = cc.FlipY.create( false );
|
||||
var delay = cc.DelayTime.create( 1 );
|
||||
var delay2 = cc.DelayTime.create( 1 );
|
||||
var seq = cc.Sequence.create( delay, flip, delay2, flip_back );
|
||||
sprite.runAction( cc.RepeatForever.create( seq ) );
|
||||
|
||||
batch.addChild( sprite );
|
||||
}
|
||||
this.addChild(batch);
|
||||
}
|
||||
|
||||
this.title = function () {
|
||||
return "SpriteBatch offset + anchor + flip";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "issue #1078";
|
||||
}
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
goog.inherits( SpriteBatchOffsetAnchorFlip, BaseLayer );
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteColorOpacity
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteColorOpacity = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.initialize = function() {
|
||||
var sprite1 = cc.Sprite.create('grossini_dance_atlas.png', cc.rect(85 * 0, 121 * 1, 85, 121));
|
||||
var sprite2 = cc.Sprite.create('grossini_dance_atlas.png', cc.rect(85 * 1, 121 * 1, 85, 121));
|
||||
var sprite3 = cc.Sprite.create('grossini_dance_atlas.png', cc.rect(85 * 2, 121 * 1, 85, 121));
|
||||
var sprite4 = cc.Sprite.create('grossini_dance_atlas.png', cc.rect(85 * 3, 121 * 1, 85, 121));
|
||||
var sprite5 = cc.Sprite.create('grossini_dance_atlas.png', cc.rect(85 * 0, 121 * 1, 85, 121));
|
||||
var sprite6 = cc.Sprite.create('grossini_dance_atlas.png', cc.rect(85 * 1, 121 * 1, 85, 121));
|
||||
var sprite7 = cc.Sprite.create('grossini_dance_atlas.png', cc.rect(85 * 2, 121 * 1, 85, 121));
|
||||
var sprite8 = cc.Sprite.create('grossini_dance_atlas.png', cc.rect(85 * 3, 121 * 1, 85, 121));
|
||||
|
||||
sprite1.setPosition(cc.p((winSize.width / 5) * 1, (winSize.height / 3) * 1));
|
||||
sprite2.setPosition(cc.p((winSize.width / 5) * 2, (winSize.height / 3) * 1));
|
||||
sprite3.setPosition(cc.p((winSize.width / 5) * 3, (winSize.height / 3) * 1));
|
||||
sprite4.setPosition(cc.p((winSize.width / 5) * 4, (winSize.height / 3) * 1));
|
||||
sprite5.setPosition(cc.p((winSize.width / 5) * 1, (winSize.height / 3) * 2));
|
||||
sprite6.setPosition(cc.p((winSize.width / 5) * 2, (winSize.height / 3) * 2));
|
||||
sprite7.setPosition(cc.p((winSize.width / 5) * 3, (winSize.height / 3) * 2));
|
||||
sprite8.setPosition(cc.p((winSize.width / 5) * 4, (winSize.height / 3) * 2));
|
||||
|
||||
var action = cc.FadeIn.create(2);
|
||||
var action_back = action.reverse();
|
||||
var fade = cc.RepeatForever.create( cc.Sequence.create( action, action_back ) );
|
||||
|
||||
var tintRed = cc.TintBy.create(2, 0, -255, -255);
|
||||
// var tintRed = cc.RotateBy.create(2, 360 );
|
||||
var tintRedBack = tintRed.reverse();
|
||||
var red = cc.RepeatForever.create(cc.Sequence.create( tintRed, tintRedBack ) );
|
||||
|
||||
var tintGreen = cc.TintBy.create(2, -255, 0, -255);
|
||||
var tintGreenBack = tintGreen.reverse();
|
||||
var green = cc.RepeatForever.create(cc.Sequence.create( tintGreen, tintGreenBack ) );
|
||||
|
||||
var tintBlue = cc.TintBy.create(2, -255, -255, 0);
|
||||
var tintBlueBack = tintBlue.reverse();
|
||||
var blue = cc.RepeatForever.create(cc.Sequence.create( tintBlue, tintBlueBack ) );
|
||||
|
||||
sprite5.runAction(red);
|
||||
sprite6.runAction(green);
|
||||
sprite7.runAction(blue);
|
||||
sprite8.runAction(fade);
|
||||
|
||||
// late add: test dirtyColor and dirtyPosition
|
||||
this.addChild(sprite1);
|
||||
this.addChild(sprite2);
|
||||
this.addChild(sprite3);
|
||||
this.addChild(sprite4);
|
||||
this.addChild(sprite5);
|
||||
this.addChild(sprite6);
|
||||
this.addChild(sprite7);
|
||||
this.addChild(sprite8);
|
||||
}
|
||||
|
||||
//
|
||||
// Instance methods
|
||||
//
|
||||
this.title = function () {
|
||||
return "Sprite: Color & Opacity";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "testing opacity and color";
|
||||
}
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
goog.inherits(SpriteColorOpacity, BaseLayer );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteBatchColorOpacity
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteBatchColorOpacity = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.initialize = function() {
|
||||
var batch = cc.SpriteBatchNode.create('grossini_dance_atlas.png', 10);
|
||||
var sprite1 = cc.Sprite.create('grossini_dance_atlas.png', cc.rect(85 * 0, 121 * 1, 85, 121));
|
||||
var sprite2 = cc.Sprite.create('grossini_dance_atlas.png', cc.rect(85 * 1, 121 * 1, 85, 121));
|
||||
var sprite3 = cc.Sprite.create('grossini_dance_atlas.png', cc.rect(85 * 2, 121 * 1, 85, 121));
|
||||
var sprite4 = cc.Sprite.create('grossini_dance_atlas.png', cc.rect(85 * 3, 121 * 1, 85, 121));
|
||||
var sprite5 = cc.Sprite.create('grossini_dance_atlas.png', cc.rect(85 * 0, 121 * 1, 85, 121));
|
||||
var sprite6 = cc.Sprite.create('grossini_dance_atlas.png', cc.rect(85 * 1, 121 * 1, 85, 121));
|
||||
var sprite7 = cc.Sprite.create('grossini_dance_atlas.png', cc.rect(85 * 2, 121 * 1, 85, 121));
|
||||
var sprite8 = cc.Sprite.create('grossini_dance_atlas.png', cc.rect(85 * 3, 121 * 1, 85, 121));
|
||||
|
||||
sprite1.setPosition(cc.p((winSize.width / 5) * 1, (winSize.height / 3) * 1));
|
||||
sprite2.setPosition(cc.p((winSize.width / 5) * 2, (winSize.height / 3) * 1));
|
||||
sprite3.setPosition(cc.p((winSize.width / 5) * 3, (winSize.height / 3) * 1));
|
||||
sprite4.setPosition(cc.p((winSize.width / 5) * 4, (winSize.height / 3) * 1));
|
||||
sprite5.setPosition(cc.p((winSize.width / 5) * 1, (winSize.height / 3) * 2));
|
||||
sprite6.setPosition(cc.p((winSize.width / 5) * 2, (winSize.height / 3) * 2));
|
||||
sprite7.setPosition(cc.p((winSize.width / 5) * 3, (winSize.height / 3) * 2));
|
||||
sprite8.setPosition(cc.p((winSize.width / 5) * 4, (winSize.height / 3) * 2));
|
||||
|
||||
var action = cc.FadeIn.create(2);
|
||||
var action_back = action.reverse();
|
||||
var fade = cc.RepeatForever.create( cc.Sequence.create( action, action_back ) );
|
||||
|
||||
var tintRed = cc.TintBy.create(2, 0, -255, -255);
|
||||
// var tintRed = cc.RotateBy.create(2, 360 );
|
||||
var tintRedBack = tintRed.reverse();
|
||||
var red = cc.RepeatForever.create(cc.Sequence.create( tintRed, tintRedBack ) );
|
||||
|
||||
var tintGreen = cc.TintBy.create(2, -255, 0, -255);
|
||||
var tintGreenBack = tintGreen.reverse();
|
||||
var green = cc.RepeatForever.create(cc.Sequence.create( tintGreen, tintGreenBack ) );
|
||||
|
||||
var tintBlue = cc.TintBy.create(2, -255, -255, 0);
|
||||
var tintBlueBack = tintBlue.reverse();
|
||||
var blue = cc.RepeatForever.create(cc.Sequence.create( tintBlue, tintBlueBack ) );
|
||||
|
||||
sprite5.runAction(red);
|
||||
sprite6.runAction(green);
|
||||
sprite7.runAction(blue);
|
||||
sprite8.runAction(fade);
|
||||
|
||||
// late add: test dirtyColor and dirtyPosition
|
||||
this.addChild(batch);
|
||||
batch.addChild(sprite1);
|
||||
batch.addChild(sprite2);
|
||||
batch.addChild(sprite3);
|
||||
batch.addChild(sprite4);
|
||||
batch.addChild(sprite5);
|
||||
batch.addChild(sprite6);
|
||||
batch.addChild(sprite7);
|
||||
batch.addChild(sprite8);
|
||||
}
|
||||
|
||||
//
|
||||
// Instance methods
|
||||
//
|
||||
this.title = function () {
|
||||
return "Sprite Batch: Color & Opacity";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "testing opacity and color with batches";
|
||||
}
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
goog.inherits(SpriteBatchColorOpacity, BaseLayer );
|
||||
|
||||
//
|
||||
// Order of tests
|
||||
//
|
||||
scenes.push( SpriteTouchTest ); scenes.push( SpriteBatchTouchTest );
|
||||
|
||||
scenes.push( SpriteFrameTest );
|
||||
|
||||
scenes.push( SpriteAnchorPoint ); scenes.push( SpriteBatchAnchorPoint );
|
||||
|
||||
scenes.push( SpriteOffsetAnchorFlip ); scenes.push( SpriteBatchOffsetAnchorFlip );
|
||||
|
||||
scenes.push( SpriteColorOpacity ); scenes.push( SpriteBatchColorOpacity );
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Main entry point
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
function run()
|
||||
{
|
||||
var scene = cc.Scene.create();
|
||||
var layer = new scenes[currentScene]();
|
||||
scene.addChild( layer );
|
||||
|
||||
var runningScene = director.getRunningScene();
|
||||
if( runningScene == null ) {
|
||||
director.runWithScene( scene );
|
||||
} else {
|
||||
director.replaceScene( cc.TransitionFade.create(0.5, scene, cc.c3(0, 0, 0) ) );
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
|
@ -1,313 +0,0 @@
|
|||
//
|
||||
// http://www.cocos2d-iphone.org
|
||||
// http://www.cocos2d-html5.org
|
||||
// http://www.cocos2d-x.org
|
||||
//
|
||||
// Javascript + CocosDenshion tests
|
||||
//
|
||||
//
|
||||
require("js/helpers.js");
|
||||
|
||||
var director = cc.Director.sharedDirector();
|
||||
var audioEngine = cc.SimpleAudioEngine.sharedEngine();
|
||||
var _winSize = director.getWinSize();
|
||||
var winSize = {width:_winSize[0], height:_winSize[1]};
|
||||
var centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var MUSIC_FILE = "bgmusic.mp3";
|
||||
var EFFECT_FILE = "cowbell.wav";
|
||||
|
||||
var DenshionTests = [
|
||||
{
|
||||
title:"playBackgroundMusic",
|
||||
playFunc:function () {
|
||||
return new playBackgroundMusic();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"stopBackgroundMusic",
|
||||
playFunc:function () {
|
||||
return new stopBackgroundMusic();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"pauseBackgroundMusic",
|
||||
playFunc:function () {
|
||||
return new pauseBackgroundMusic();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"resumeBackgroundMusic",
|
||||
playFunc:function () {
|
||||
return new resumeBackgroundMusic();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"rewindBackgroundMusic",
|
||||
playFunc:function () {
|
||||
return new rewindBackgroundMusic();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"isBackgroundMusicPlaying",
|
||||
playFunc:function () {
|
||||
return new isBackgroundMusicPlaying();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"playEffect",
|
||||
playFunc:function () {
|
||||
return new playEffect();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"playEffectRepeatly",
|
||||
playFunc:function () {
|
||||
return new playEffectRepeatly();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"stopEffect",
|
||||
playFunc:function () {
|
||||
return new stopEffect();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"unloadEffect",
|
||||
playFunc:function () {
|
||||
return new unloadEffect();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"addBackgroundMusicVolume",
|
||||
playFunc:function () {
|
||||
return new addBackgroundMusicVolume();
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
title:"subBackgroundMusicVolume",
|
||||
playFunc:function () {
|
||||
return new subBackgroundMusicVolume();
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
title:"addEffectsVolume",
|
||||
playFunc:function () {
|
||||
return new addEffectsVolume();
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
title:"subEffectsVolume",
|
||||
playFunc:function () {
|
||||
return new subEffectsVolume();
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
title:"pauseEffect",
|
||||
playFunc:function () {
|
||||
return new pauseEffect();
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
title:"resumeEffect",
|
||||
playFunc:function () {
|
||||
return new resumeEffect();
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
title:"pauseAllEffects",
|
||||
playFunc:function () {
|
||||
return new pauseAllEffects();
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
title:"resumeAllEffects",
|
||||
playFunc:function () {
|
||||
return new resumeAllEffects();
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
title:"stopAllEffects",
|
||||
playFunc:function () {
|
||||
return new stopAllEffects();
|
||||
}
|
||||
}
|
||||
|
||||
];
|
||||
|
||||
CocosDenshionTest = cc.LayerGradient.extend({
|
||||
_menu:null,
|
||||
ctor:function () {
|
||||
|
||||
var parent = new cc.LayerGradient();
|
||||
__associateObjWithNative(this, parent);
|
||||
this.init(cc.c4(0, 0, 0, 255), cc.c4(0, 128, 255, 255));
|
||||
this.setTouchEnabled(true);
|
||||
|
||||
// add menu items for tests
|
||||
this._menu = cc.Menu.create();
|
||||
var s = winSize;
|
||||
for (var i = 0; i < DenshionTests.length; i++) {
|
||||
var label = cc.LabelTTF.create(DenshionTests[i].title, "Arial", 20);
|
||||
var menuItem = cc.MenuItemLabel.create(label, this.menuCallback);
|
||||
this._menu.addChild(menuItem, i + 10000);
|
||||
}
|
||||
this._menu.setPosition(cc.p(winSize.width/2, winSize.height/2) );
|
||||
this._menu.alignItemsVertically()
|
||||
this.addChild(this._menu);
|
||||
|
||||
// set default volume
|
||||
audioEngine.setEffectsVolume(0.5);
|
||||
audioEngine.setBackgroundMusicVolume(0.5);
|
||||
|
||||
// Back button
|
||||
var itemBack = cc.MenuItemFont.create("back", function() { require("js/main.js"); } );
|
||||
itemBack.setPosition( cc.p(winSize.width - 60, winSize.height - 30 ) );
|
||||
itemBack.setFontSizeObj( 22 );
|
||||
var menuBack = cc.Menu.create();
|
||||
menuBack.addChild(itemBack);
|
||||
menuBack.setPosition( cc.p(0,0) );
|
||||
this.addChild( menuBack, 10 );
|
||||
},
|
||||
ccTouchBegan: function (touch) {
|
||||
cc.log("touch: " + touch[0] + ": " + Date.now());
|
||||
},
|
||||
ccTouchMoved: function (touch) {
|
||||
cc.log("touch moved: " + touch[0] + ": " + Date.now());
|
||||
},
|
||||
menuCallback:function (sender) {
|
||||
var idx = sender.getZOrder() - 10000;
|
||||
// create the test scene and run it
|
||||
var scene = DenshionTests[idx].playFunc();
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
var soundId = null;
|
||||
|
||||
var playBackgroundMusic = function () {
|
||||
cc.log("play background music");
|
||||
audioEngine.playBackgroundMusic(MUSIC_FILE, false);
|
||||
};
|
||||
|
||||
var stopBackgroundMusic = function () {
|
||||
cc.log("stop background music");
|
||||
audioEngine.stopBackgroundMusic();
|
||||
};
|
||||
|
||||
var pauseBackgroundMusic = function () {
|
||||
cc.log("pause background music");
|
||||
audioEngine.pauseBackgroundMusic();
|
||||
};
|
||||
|
||||
var resumeBackgroundMusic = function () {
|
||||
cc.log("resume background music");
|
||||
audioEngine.resumeBackgroundMusic();
|
||||
};
|
||||
|
||||
var rewindBackgroundMusic = function () {
|
||||
cc.log("rewind background music");
|
||||
audioEngine.rewindBackgroundMusic();
|
||||
};
|
||||
|
||||
// is background music playing
|
||||
var isBackgroundMusicPlaying = function () {
|
||||
if (audioEngine.isBackgroundMusicPlaying()) {
|
||||
cc.log("background music is playing");
|
||||
}
|
||||
else {
|
||||
cc.log("background music is not playing");
|
||||
}
|
||||
};
|
||||
|
||||
var playEffect = function () {
|
||||
cc.log("play effect");
|
||||
soundId = audioEngine.playEffect(EFFECT_FILE, false);
|
||||
};
|
||||
|
||||
var playEffectRepeatly = function () {
|
||||
cc.log("play effect repeatly");
|
||||
soundId = audioEngine.playEffect(EFFECT_FILE, true);
|
||||
};
|
||||
|
||||
var stopEffect = function () {
|
||||
cc.log("stop effect");
|
||||
audioEngine.stopEffect(soundId);
|
||||
};
|
||||
|
||||
var unloadEffect = function () {
|
||||
cc.log("unload effect");
|
||||
audioEngine.unloadEffect(EFFECT_FILE);
|
||||
};
|
||||
|
||||
var addBackgroundMusicVolume = function () {
|
||||
cc.log("add bakcground music volume");
|
||||
audioEngine.setBackgroundMusicVolume(audioEngine.getBackgroundMusicVolume() + 0.1);
|
||||
};
|
||||
|
||||
var subBackgroundMusicVolume = function () {
|
||||
cc.log("sub backgroud music volume");
|
||||
audioEngine.setBackgroundMusicVolume(audioEngine.getBackgroundMusicVolume() - 0.1);
|
||||
};
|
||||
|
||||
var addEffectsVolume = function () {
|
||||
cc.log("add effects volume");
|
||||
audioEngine.setEffectsVolume(audioEngine.getEffectsVolume() + 0.1);
|
||||
};
|
||||
|
||||
var subEffectsVolume = function () {
|
||||
cc.log("sub effects volume");
|
||||
audioEngine.setEffectsVolume(audioEngine.getEffectsVolume() - 0.1);
|
||||
};
|
||||
|
||||
var pauseEffect = function () {
|
||||
cc.log("pause effect");
|
||||
audioEngine.pauseEffect(soundId);
|
||||
};
|
||||
|
||||
var resumeEffect = function () {
|
||||
cc.log("resume effect");
|
||||
audioEngine.resumeEffect(soundId);
|
||||
};
|
||||
|
||||
var pauseAllEffects = function () {
|
||||
cc.log("pause all effects");
|
||||
audioEngine.pauseAllEffects();
|
||||
};
|
||||
var resumeAllEffects = function () {
|
||||
cc.log("resume all effects");
|
||||
audioEngine.resumeAllEffects();
|
||||
};
|
||||
var stopAllEffects = function () {
|
||||
cc.log("stop all effects");
|
||||
audioEngine.stopAllEffects();
|
||||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Main entry point
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
function run()
|
||||
{
|
||||
var scene = cc.Scene.create();
|
||||
var layer = new CocosDenshionTest();
|
||||
scene.addChild( layer );
|
||||
|
||||
var runningScene = director.getRunningScene();
|
||||
if( runningScene == null )
|
||||
director.runWithScene( scene );
|
||||
else
|
||||
director.replaceScene( cc.TransitionSplitCols.create(1, scene ) );
|
||||
}
|
||||
|
||||
run();
|
|
@ -1,232 +0,0 @@
|
|||
//
|
||||
// http://www.cocos2d-iphone.org
|
||||
// http://www.cocos2d-html5.org
|
||||
// http://www.cocos2d-x.org
|
||||
//
|
||||
// Javascript + cocos2d actions tests
|
||||
//
|
||||
|
||||
require("js/helper.js");
|
||||
|
||||
director = cc.Director.getInstance();
|
||||
_winSize = director.getWinSize();
|
||||
winSize = {width:_winSize[0], height:_winSize[1]};
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var scenes = []
|
||||
var currentScene = 0;
|
||||
|
||||
var nextScene = function () {
|
||||
currentScene = currentScene + 1;
|
||||
if( currentScene >= scenes.length )
|
||||
currentScene = 0;
|
||||
|
||||
withTransition = true;
|
||||
loadScene(currentScene);
|
||||
};
|
||||
|
||||
var previousScene = function () {
|
||||
currentScene = currentScene -1;
|
||||
if( currentScene < 0 )
|
||||
currentScene = scenes.length -1;
|
||||
|
||||
withTransition = true;
|
||||
loadScene(currentScene);
|
||||
};
|
||||
|
||||
var restartScene = function () {
|
||||
loadScene( currentScene );
|
||||
};
|
||||
|
||||
var loadScene = function (sceneIdx)
|
||||
{
|
||||
_winSize = director.getWinSize();
|
||||
winSize = {width:_winSize[0], height:_winSize[1]};
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var scene = new cc.Scene();
|
||||
scene.init();
|
||||
var layer = new scenes[ sceneIdx ]();
|
||||
|
||||
scene.addChild( layer );
|
||||
|
||||
// scene.walkSceneGraph(0);
|
||||
|
||||
director.replaceScene( scene );
|
||||
__jsc__.dumpRoot();
|
||||
__jsc__.garbageCollect();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Base Layer
|
||||
//
|
||||
|
||||
var MyMenuItemFont = cc.MenuItemFont.extend({
|
||||
|
||||
ctor:function () {
|
||||
var parent = new cc.MenuItemFont();
|
||||
__associateObjWithNative(this, parent);
|
||||
this.init( "hello", this, this.callback );
|
||||
},
|
||||
|
||||
callback:function(sender) {
|
||||
cc.log("Button clicked");
|
||||
},
|
||||
});
|
||||
|
||||
var BaseLayer = cc.LayerGradient.extend({
|
||||
|
||||
ctor:function () {
|
||||
|
||||
var parent = new cc.LayerGradient();
|
||||
__associateObjWithNative(this, parent);
|
||||
this.init(cc.c4b(0, 0, 0, 255), cc.c4b(0, 128, 255, 255));
|
||||
|
||||
|
||||
var item = new MyMenuItemFont();
|
||||
var menu = cc.Menu.create( item );
|
||||
this.addChild( menu );
|
||||
menu.setPosition( centerPos );
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "No Title";
|
||||
},
|
||||
|
||||
subtitle:function () {
|
||||
return "";
|
||||
},
|
||||
|
||||
code:function () {
|
||||
return "";
|
||||
},
|
||||
|
||||
restartCallback:function (sender) {
|
||||
restartScene();
|
||||
},
|
||||
|
||||
nextCallback:function (sender) {
|
||||
nextScene();
|
||||
},
|
||||
|
||||
backCallback:function (sender) {
|
||||
// previousScene();
|
||||
cc.log("3");
|
||||
__jsc__.dumpRoot();
|
||||
__jsc__.garbageCollect();
|
||||
},
|
||||
|
||||
onEnter:function () {
|
||||
// DO NOT CALL this._super()
|
||||
// this._super();
|
||||
|
||||
// add title and subtitle
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 28);
|
||||
this.addChild(label, 1);
|
||||
label.setPosition( cc.p(winSize.width / 2, winSize.height - 40));
|
||||
|
||||
var strSubtitle = this.subtitle();
|
||||
if (strSubtitle != "") {
|
||||
var l = cc.LabelTTF.create(strSubtitle, "Thonburi", 16);
|
||||
this.addChild(l, 1);
|
||||
l.setPosition( cc.p(winSize.width / 2, winSize.height - 70));
|
||||
}
|
||||
|
||||
var strCode = this.code();
|
||||
if( strCode !="" ) {
|
||||
var label = cc.LabelTTF.create(strCode, 'CourierNewPSMT', 16);
|
||||
label.setPosition( cc.p( winSize.width/2, winSize.height-120) );
|
||||
this.addChild( label,10 );
|
||||
|
||||
var labelbg = cc.LabelTTF.create(strCode, 'CourierNewPSMT', 16);
|
||||
labelbg.setColor( cc.c3b(10,10,255) );
|
||||
labelbg.setPosition( cc.p( winSize.width/2 +1, winSize.height-120 -1) );
|
||||
this.addChild( labelbg,9);
|
||||
}
|
||||
|
||||
// Menu
|
||||
var item1 = cc.MenuItemImage.create("b1.png", "b2.png", this, this.backCallback);
|
||||
var item2 = cc.MenuItemImage.create("r1.png", "r2.png", this, this.restartCallback);
|
||||
var item3 = cc.MenuItemImage.create("f1.png", "f2.png", this, this.nextCallback);
|
||||
// var item4 = cc.MenuItemFont.create("back", this, function() { require("js/main.js"); } );
|
||||
// item4.setFontSize( 22 );
|
||||
|
||||
// var menu = cc.Menu.create(item1, item2, item3, item4 );
|
||||
var menu = cc.Menu.create(item1, item2, item3 );
|
||||
|
||||
menu.setPosition( cc.p(0,0) );
|
||||
item1.setPosition( cc.p(winSize.width / 2 - 100, 30));
|
||||
item2.setPosition( cc.p(winSize.width / 2, 30));
|
||||
item3.setPosition( cc.p(winSize.width / 2 + 100, 30));
|
||||
// item4.setPosition( cc.p(winSize.width - 60, winSize.height - 30 ) );
|
||||
|
||||
this.addChild(menu, 1);
|
||||
|
||||
cc.log("2");
|
||||
__jsc__.dumpRoot();
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Playground
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var Playground = BaseLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var platform = __getPlatform();
|
||||
if( platform.substring(0,6) == 'mobile' ) {
|
||||
var accel = cc.Accelerometer.getInstance();
|
||||
accel.setCallback( this, this.onAccelerometer );
|
||||
|
||||
// 2 times per second
|
||||
accel.setUpdateInterval( 1/2 );
|
||||
}
|
||||
},
|
||||
|
||||
onAccelerometer:function(x,y,z,timestamp) {
|
||||
cc.log('Accel: '+ x + ' ' + y + ' ' + z );
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "Testing Accelerometer";
|
||||
},
|
||||
|
||||
subtitle:function () {
|
||||
return "See console on device";
|
||||
},
|
||||
code:function () {
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// Order of tests
|
||||
//
|
||||
|
||||
scenes.push( Playground );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Main entry point
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
function run()
|
||||
{
|
||||
var scene = cc.Scene.create();
|
||||
var layer = new scenes[currentScene]();
|
||||
scene.addChild( layer );
|
||||
|
||||
var runningScene = director.getRunningScene();
|
||||
if( runningScene == null )
|
||||
director.runWithScene( scene );
|
||||
else
|
||||
director.replaceScene( cc.TransitionFade.create(0.5, scene ) );
|
||||
}
|
||||
|
||||
run();
|
||||
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
|
||||
director = cc.Director.getInstance();
|
||||
|
||||
cc.log("**** 1 ****");
|
||||
__jsc__.dumpRoot();
|
||||
__jsc__.garbageCollect();
|
||||
|
||||
scene = cc.Scene.create();
|
||||
layer = cc.LayerGradient.create( cc.c4b(0, 0, 0, 255), cc.c4b(0, 128, 255, 255) );
|
||||
|
||||
layer.onEnter = function() {
|
||||
cc.log("On Enter!!");
|
||||
|
||||
cc.log("**** 2 ****");
|
||||
__jsc__.dumpRoot();
|
||||
// __jsc__.garbageCollect();
|
||||
};
|
||||
|
||||
scene.addChild( layer );
|
||||
director.runWithScene( scene );
|
||||
|
||||
cc.log("**** 5 ****");
|
||||
__jsc__.dumpRoot();
|
||||
__jsc__.garbageCollect();
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -1,461 +0,0 @@
|
|||
//
|
||||
// http://www.cocos2d-iphone.org
|
||||
// http://www.cocos2d-html5.org
|
||||
// http://www.cocos2d-x.org
|
||||
//
|
||||
// Javascript + cocos2d actions tests
|
||||
//
|
||||
|
||||
require("js/helper.js");
|
||||
|
||||
director = cc.Director.getInstance();
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
spriteFrameCache = cc.SpriteFrameCache.getInstance();
|
||||
|
||||
var scenes = [];
|
||||
var currentScene = 0;
|
||||
|
||||
var nextScene = function () {
|
||||
currentScene = currentScene + 1;
|
||||
if( currentScene >= scenes.length )
|
||||
currentScene = 0;
|
||||
|
||||
withTransition = true;
|
||||
loadScene(currentScene);
|
||||
};
|
||||
|
||||
var previousScene = function () {
|
||||
currentScene = currentScene -1;
|
||||
if( currentScene < 0 )
|
||||
currentScene = scenes.length -1;
|
||||
|
||||
withTransition = true;
|
||||
loadScene(currentScene);
|
||||
};
|
||||
|
||||
var restartScene = function () {
|
||||
loadScene( currentScene );
|
||||
};
|
||||
|
||||
var loadScene = function (sceneIdx)
|
||||
{
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var scene = new cc.Scene();
|
||||
scene.init();
|
||||
var layer = new scenes[ sceneIdx ]();
|
||||
|
||||
scene.addChild( layer );
|
||||
|
||||
// scene.walkSceneGraph(0);
|
||||
|
||||
director.replaceScene( scene );
|
||||
// __jsc__.garbageCollect();
|
||||
}
|
||||
|
||||
var s_pathSister1 = "Images/grossinis_sister1.png";
|
||||
var s_pathSister2 = "Images/grossinis_sister2.png";
|
||||
var s_pathBlock = "Images/blocks.png";
|
||||
var s_grossiniPlist = "animations/grossini.plist";
|
||||
|
||||
//
|
||||
// Base Layer
|
||||
//
|
||||
|
||||
var BaseLayer = cc.LayerGradient.extend({
|
||||
|
||||
ctor:function () {
|
||||
|
||||
var parent = new cc.LayerGradient();
|
||||
__associateObjWithNative(this, parent);
|
||||
this.init(cc.c4b(0, 0, 0, 255), cc.c4b(0, 128, 255, 255));
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "Progress Actions";
|
||||
},
|
||||
|
||||
subtitle:function () {
|
||||
return "";
|
||||
},
|
||||
|
||||
code:function () {
|
||||
return "";
|
||||
},
|
||||
|
||||
restartCallback:function (sender) {
|
||||
restartScene();
|
||||
},
|
||||
|
||||
nextCallback:function (sender) {
|
||||
nextScene();
|
||||
},
|
||||
|
||||
backCallback:function (sender) {
|
||||
previousScene();
|
||||
},
|
||||
|
||||
onEnter:function () {
|
||||
// DO NOT CALL this._super()
|
||||
// this._super();
|
||||
|
||||
// add title and subtitle
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 28);
|
||||
this.addChild(label, 1);
|
||||
label.setPosition( cc.p(winSize.width / 2, winSize.height - 40));
|
||||
|
||||
var strSubtitle = this.subtitle();
|
||||
if (strSubtitle != "") {
|
||||
var l = cc.LabelTTF.create(strSubtitle, "Thonburi", 16);
|
||||
this.addChild(l, 1);
|
||||
l.setPosition( cc.p(winSize.width / 2, winSize.height - 70));
|
||||
}
|
||||
|
||||
var strCode = this.code();
|
||||
if( strCode !="" ) {
|
||||
var label = cc.LabelTTF.create(strCode, 'CourierNewPSMT', 16);
|
||||
label.setPosition( cc.p( winSize.width/2, winSize.height-120) );
|
||||
this.addChild( label,10 );
|
||||
|
||||
var labelbg = cc.LabelTTF.create(strCode, 'CourierNewPSMT', 16);
|
||||
labelbg.setColor( cc.c3b(10,10,255) );
|
||||
labelbg.setPosition( cc.p( winSize.width/2 +1, winSize.height-120 -1) );
|
||||
this.addChild( labelbg,9);
|
||||
}
|
||||
|
||||
// Menu
|
||||
var item1 = cc.MenuItemImage.create("Images/b1.png", "Images/b2.png", this, this.backCallback);
|
||||
var item2 = cc.MenuItemImage.create("Images/r1.png", "Images/r2.png", this, this.restartCallback);
|
||||
var item3 = cc.MenuItemImage.create("Images/f1.png", "Images/f2.png", this, this.nextCallback);
|
||||
var item4 = cc.MenuItemFont.create("back", this, function() { require("js/main.js"); } );
|
||||
item4.setFontSize( 22 );
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3, item4 );
|
||||
|
||||
menu.setPosition( cc.p(0,0) );
|
||||
item1.setPosition( cc.p(winSize.width / 2 - 100, 30));
|
||||
item2.setPosition( cc.p(winSize.width / 2, 30));
|
||||
item3.setPosition( cc.p(winSize.width / 2 + 100, 30));
|
||||
item4.setPosition( cc.p(winSize.width - 60, winSize.height - 30 ) );
|
||||
|
||||
this.addChild(menu, 1);
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Tests
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteProgressToRadial = BaseLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var to1 = cc.ProgressTo.create(2, 100);
|
||||
var to2 = cc.ProgressTo.create(2, 100);
|
||||
|
||||
var left = cc.ProgressTimer.create(cc.Sprite.create(s_pathSister1));
|
||||
left.setType(cc.PROGRESS_TIMER_TYPE_RADIAL);
|
||||
this.addChild(left);
|
||||
left.setPosition(cc.p(200, winSize.height / 2));
|
||||
left.runAction(cc.RepeatForever.create(to1));
|
||||
|
||||
var right = cc.ProgressTimer.create(cc.Sprite.create(s_pathBlock));
|
||||
right.setType(cc.PROGRESS_TIMER_TYPE_RADIAL);
|
||||
|
||||
right.setReverseDirection(true);
|
||||
|
||||
this.addChild(right);
|
||||
right.setPosition(cc.p(winSize.width - 200, winSize.height / 2));
|
||||
right.runAction(cc.RepeatForever.create(to2));
|
||||
},
|
||||
|
||||
subtitle:function () {
|
||||
return "ProgressTo Radial";
|
||||
}
|
||||
});
|
||||
|
||||
var SpriteProgressToHorizontal = BaseLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var to1 = cc.ProgressTo.create(2, 100);
|
||||
var to2 = cc.ProgressTo.create(2, 100);
|
||||
|
||||
var left = cc.ProgressTimer.create(cc.Sprite.create(s_pathSister1));
|
||||
left.setType(cc.PROGRESS_TIMER_TYPE_BAR);
|
||||
// Setup for a bar starting from the left since the midpoint is 0 for the x
|
||||
left.setMidpoint(cc.p(0, 0));
|
||||
// Setup for a horizontal bar since the bar change rate is 0 for y meaning no vertical change
|
||||
left.setBarChangeRate(cc.p(1, 0));
|
||||
this.addChild(left);
|
||||
left.setPosition(cc.p(200, winSize.height / 2));
|
||||
left.runAction(cc.RepeatForever.create(to1));
|
||||
|
||||
var right = cc.ProgressTimer.create(cc.Sprite.create(s_pathSister2));
|
||||
right.setType(cc.PROGRESS_TIMER_TYPE_BAR);
|
||||
// Setup for a bar starting from the left since the midpoint is 1 for the x
|
||||
right.setMidpoint(cc.p(1, 0));
|
||||
// Setup for a horizontal bar since the bar change rate is 0 for y meaning no vertical change
|
||||
right.setBarChangeRate(cc.p(1, 0));
|
||||
this.addChild(right);
|
||||
right.setPosition(cc.p(winSize.width - 200, winSize.height / 2));
|
||||
right.runAction(cc.RepeatForever.create(to2));
|
||||
},
|
||||
subtitle:function () {
|
||||
return "ProgressTo Horizontal";
|
||||
}
|
||||
});
|
||||
|
||||
var SpriteProgressToVertical = BaseLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var to1 = cc.ProgressTo.create(2, 100);
|
||||
var to2 = cc.ProgressTo.create(2, 100);
|
||||
|
||||
var left = cc.ProgressTimer.create(cc.Sprite.create(s_pathSister1));
|
||||
left.setType(cc.PROGRESS_TIMER_TYPE_BAR);
|
||||
// Setup for a bar starting from the bottom since the midpoint is 0 for the y
|
||||
left.setMidpoint(cc.p(0, 0));
|
||||
// Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
|
||||
left.setBarChangeRate(cc.p(0, 1));
|
||||
this.addChild(left);
|
||||
left.setPosition(cc.p(200, winSize.height / 2));
|
||||
left.runAction(cc.RepeatForever.create(to1));
|
||||
|
||||
var right = cc.ProgressTimer.create(cc.Sprite.create(s_pathSister2));
|
||||
right.setType(cc.PROGRESS_TIMER_TYPE_BAR);
|
||||
// Setup for a bar starting from the bottom since the midpoint is 0 for the y
|
||||
right.setMidpoint(cc.p(0, 1));
|
||||
// Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
|
||||
right.setBarChangeRate(cc.p(0, 1));
|
||||
this.addChild(right);
|
||||
right.setPosition(cc.p(winSize.width - 200, winSize.height / 2));
|
||||
right.runAction(cc.RepeatForever.create(to2));
|
||||
},
|
||||
subtitle:function () {
|
||||
return "ProgressTo Vertical";
|
||||
}
|
||||
});
|
||||
|
||||
var SpriteProgressToRadialMidpointChanged = BaseLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var action = cc.ProgressTo.create(2, 100);
|
||||
|
||||
/**
|
||||
* Our image on the left should be a radial progress indicator, clockwise
|
||||
*/
|
||||
var left = cc.ProgressTimer.create(cc.Sprite.create(s_pathBlock));
|
||||
left.setType(cc.PROGRESS_TIMER_TYPE_RADIAL);
|
||||
this.addChild(left);
|
||||
left.setMidpoint(cc.p(0.25, 0.75));
|
||||
left.setPosition(cc.p(200, winSize.height / 2));
|
||||
left.runAction(cc.RepeatForever.create(action.copy()));
|
||||
|
||||
/**
|
||||
* Our image on the left should be a radial progress indicator, counter clockwise
|
||||
*/
|
||||
var right = cc.ProgressTimer.create(cc.Sprite.create(s_pathBlock));
|
||||
right.setType(cc.PROGRESS_TIMER_TYPE_RADIAL);
|
||||
right.setMidpoint(cc.p(0.75, 0.25));
|
||||
/**
|
||||
* Note the reverse property (default=NO) is only added to the right image. That's how
|
||||
* we get a counter clockwise progress.
|
||||
*/
|
||||
this.addChild(right);
|
||||
right.setPosition(cc.p(winSize.width - 200, winSize.height / 2));
|
||||
right.runAction(cc.RepeatForever.create(action.copy()));
|
||||
},
|
||||
|
||||
subtitle:function () {
|
||||
return "Radial w/ Different Midpoints";
|
||||
}
|
||||
});
|
||||
|
||||
var SpriteProgressBarVarious = BaseLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var to = cc.ProgressTo.create(2, 100);
|
||||
|
||||
var left = cc.ProgressTimer.create(cc.Sprite.create(s_pathSister1));
|
||||
left.setType(cc.PROGRESS_TIMER_TYPE_BAR);
|
||||
|
||||
// Setup for a bar starting from the bottom since the midpoint is 0 for the y
|
||||
left.setMidpoint(cc.p(0.5, 0.5));
|
||||
// Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
|
||||
left.setBarChangeRate(cc.p(1, 0));
|
||||
this.addChild(left);
|
||||
left.setPosition(cc.p(150, winSize.height / 2));
|
||||
left.runAction(cc.RepeatForever.create(to.copy()));
|
||||
|
||||
var middle = cc.ProgressTimer.create(cc.Sprite.create(s_pathSister2));
|
||||
middle.setType(cc.PROGRESS_TIMER_TYPE_BAR);
|
||||
// Setup for a bar starting from the bottom since the midpoint is 0 for the y
|
||||
middle.setMidpoint(cc.p(0.5, 0.5));
|
||||
// Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
|
||||
middle.setBarChangeRate(cc.p(1, 1));
|
||||
this.addChild(middle);
|
||||
middle.setPosition(cc.p(winSize.width / 2, winSize.height / 2));
|
||||
middle.runAction(cc.RepeatForever.create(to.copy()));
|
||||
|
||||
var right = cc.ProgressTimer.create(cc.Sprite.create(s_pathSister2));
|
||||
right.setType(cc.PROGRESS_TIMER_TYPE_BAR);
|
||||
// Setup for a bar starting from the bottom since the midpoint is 0 for the y
|
||||
right.setMidpoint(cc.p(0.5, 0.5));
|
||||
// Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
|
||||
right.setBarChangeRate(cc.p(0, 1));
|
||||
this.addChild(right);
|
||||
right.setPosition(cc.p(winSize.width - 150, winSize.height / 2));
|
||||
right.runAction(cc.RepeatForever.create(to.copy()));
|
||||
},
|
||||
|
||||
subtitle:function () {
|
||||
return "ProgressTo Bar Mid";
|
||||
}
|
||||
});
|
||||
|
||||
var SpriteProgressBarTintAndFade = BaseLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var to = cc.ProgressTo.create(6, 100);
|
||||
var tint = cc.Sequence.create(cc.TintTo.create(1, 255, 0, 0),
|
||||
cc.TintTo.create(1, 0, 255, 0),
|
||||
cc.TintTo.create(1, 0, 0, 255));
|
||||
|
||||
var fade = cc.Sequence.create(cc.FadeTo.create(1.0, 0), cc.FadeTo.create(1.0, 255));
|
||||
|
||||
var left = cc.ProgressTimer.create(cc.Sprite.create(s_pathSister1));
|
||||
left.setType(cc.PROGRESS_TIMER_TYPE_BAR);
|
||||
|
||||
// Setup for a bar starting from the bottom since the midpoint is 0 for the y
|
||||
left.setMidpoint(cc.p(0.5, 0.5));
|
||||
// Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
|
||||
left.setBarChangeRate(cc.p(1, 0));
|
||||
this.addChild(left);
|
||||
left.setPosition(cc.p(150, winSize.height / 2));
|
||||
left.runAction(cc.RepeatForever.create(to.copy()));
|
||||
left.runAction(cc.RepeatForever.create(tint.copy()));
|
||||
|
||||
left.addChild(cc.LabelTTF.create("Tint", "Marker Felt", 20.0));
|
||||
|
||||
var middle = cc.ProgressTimer.create(cc.Sprite.create(s_pathSister2));
|
||||
middle.setType(cc.PROGRESS_TIMER_TYPE_BAR);
|
||||
// Setup for a bar starting from the bottom since the midpoint is 0 for the y
|
||||
middle.setMidpoint(cc.p(0.5, 0.5));
|
||||
// Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
|
||||
middle.setBarChangeRate(cc.p(1, 1));
|
||||
this.addChild(middle);
|
||||
middle.setPosition(cc.p(winSize.width / 2, winSize.height / 2));
|
||||
middle.runAction(cc.RepeatForever.create(to.copy()));
|
||||
middle.runAction(cc.RepeatForever.create(fade.copy()));
|
||||
|
||||
middle.addChild(cc.LabelTTF.create("Fade", "Marker Felt", 20.0));
|
||||
|
||||
var right = cc.ProgressTimer.create(cc.Sprite.create(s_pathSister2));
|
||||
right.setType(cc.PROGRESS_TIMER_TYPE_BAR);
|
||||
// Setup for a bar starting from the bottom since the midpoint is 0 for the y
|
||||
right.setMidpoint(cc.p(0.5, 0.5));
|
||||
// Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
|
||||
right.setBarChangeRate(cc.p(0, 1));
|
||||
this.addChild(right);
|
||||
right.setPosition(cc.p(winSize.width - 150, winSize.height / 2));
|
||||
right.runAction(cc.RepeatForever.create(to.copy()));
|
||||
right.runAction(cc.RepeatForever.create(tint.copy()));
|
||||
right.runAction(cc.RepeatForever.create(fade.copy()));
|
||||
|
||||
right.addChild(cc.LabelTTF.create("Tint and Fade", "Marker Felt", 20.0));
|
||||
},
|
||||
|
||||
subtitle:function () {
|
||||
return "ProgressTo Bar Mid";
|
||||
}
|
||||
});
|
||||
|
||||
var SpriteProgressWithSpriteFrame = BaseLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var to = cc.ProgressTo.create(6, 100);
|
||||
|
||||
// XXX-riq: We should simplify the API in this case.
|
||||
// spriteFrameCache.addSpriteFramesWithFile(s_grossiniPlist);
|
||||
spriteFrameCache.addSpriteFrames(s_grossiniPlist);
|
||||
|
||||
// XXX-riq: This is incorrect. It is creating the Sprite with a FrameName, not a Frame
|
||||
// var left = cc.ProgressTimer.create(cc.Sprite.createWithSpriteFrame("grossini_dance_01.png"));
|
||||
var left = cc.ProgressTimer.create(cc.Sprite.createWithSpriteFrameName("grossini_dance_01.png"));
|
||||
|
||||
left.setType(cc.PROGRESS_TIMER_TYPE_BAR);
|
||||
// Setup for a bar starting from the bottom since the midpoint is 0 for the y
|
||||
left.setMidpoint(cc.p(0.5, 0.5));
|
||||
// Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
|
||||
left.setBarChangeRate(cc.p(1, 0));
|
||||
this.addChild(left);
|
||||
left.setPosition(cc.p(150, winSize.height / 2));
|
||||
left.runAction(cc.RepeatForever.create(to.copy()));
|
||||
|
||||
var middle = cc.ProgressTimer.create(cc.Sprite.createWithSpriteFrameName("grossini_dance_02.png"));
|
||||
middle.setType(cc.PROGRESS_TIMER_TYPE_BAR);
|
||||
// Setup for a bar starting from the bottom since the midpoint is 0 for the y
|
||||
middle.setMidpoint(cc.p(0.5, 0.5));
|
||||
// Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
|
||||
middle.setBarChangeRate(cc.p(1, 1));
|
||||
this.addChild(middle);
|
||||
middle.setPosition(cc.p(winSize.width / 2, winSize.height / 2));
|
||||
middle.runAction(cc.RepeatForever.create(to.copy()));
|
||||
|
||||
var right = cc.ProgressTimer.create(cc.Sprite.createWithSpriteFrameName("grossini_dance_03.png"));
|
||||
right.setType(cc.PROGRESS_TIMER_TYPE_RADIAL);
|
||||
// Setup for a bar starting from the bottom since the midpoint is 0 for the y
|
||||
right.setMidpoint(cc.p(0.5, 0.5));
|
||||
// Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
|
||||
right.setBarChangeRate(cc.p(0, 1));
|
||||
this.addChild(right);
|
||||
right.setPosition(cc.p(winSize.width - 150, winSize.height / 2));
|
||||
right.runAction(cc.RepeatForever.create(to.copy()));
|
||||
},
|
||||
|
||||
subtitle:function () {
|
||||
return "Progress With Sprite Frame";
|
||||
}
|
||||
});
|
||||
//
|
||||
// Order of tests
|
||||
//
|
||||
|
||||
scenes.push( SpriteProgressToRadial );
|
||||
scenes.push( SpriteProgressToHorizontal );
|
||||
scenes.push( SpriteProgressToVertical );
|
||||
scenes.push( SpriteProgressToRadialMidpointChanged );
|
||||
scenes.push( SpriteProgressBarVarious );
|
||||
scenes.push( SpriteProgressBarTintAndFade );
|
||||
scenes.push( SpriteProgressWithSpriteFrame );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Main entry point
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
function run()
|
||||
{
|
||||
var scene = cc.Scene.create();
|
||||
var layer = new scenes[currentScene]();
|
||||
scene.addChild( layer );
|
||||
|
||||
var runningScene = director.getRunningScene();
|
||||
if( runningScene == null )
|
||||
director.runWithScene( scene );
|
||||
else
|
||||
director.replaceScene( cc.TransitionFade.create(0.5, scene ) );
|
||||
}
|
||||
|
||||
run();
|
||||
|
||||
|
|
@ -1,455 +0,0 @@
|
|||
//
|
||||
// http://www.cocos2d-iphone.org
|
||||
//
|
||||
// Javascript + chipmunk tests
|
||||
//
|
||||
|
||||
require("js/helper.js");
|
||||
|
||||
director = cc.Director.getInstance();
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var scenes = []
|
||||
var currentScene = 0;
|
||||
|
||||
var nextSpriteTestAction = function () {
|
||||
currentScene = currentScene + 1;
|
||||
if( currentScene >= scenes.length )
|
||||
currentScene = 0;
|
||||
|
||||
loadScene(currentScene);
|
||||
};
|
||||
var backSpriteTestAction = function () {
|
||||
currentScene = currentScene -1;
|
||||
if( currentScene < 0 )
|
||||
currentScene = scenes.length -1;
|
||||
|
||||
loadScene(currentScene);
|
||||
};
|
||||
var restartSpriteTestAction = function () {
|
||||
loadScene( currentScene );
|
||||
};
|
||||
|
||||
var loadScene = function (sceneIdx)
|
||||
{
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var scene = new cc.Scene();
|
||||
scene.init();
|
||||
var layer = new scenes[ sceneIdx ]();
|
||||
|
||||
scene.addChild( layer );
|
||||
|
||||
// scene.walkSceneGraph(0);
|
||||
|
||||
director.replaceScene( scene );
|
||||
// __jsc__.garbageCollect();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// BaseLayer
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var BaseLayer = function() {
|
||||
|
||||
//
|
||||
// VERY IMPORTANT
|
||||
//
|
||||
// Only subclasses of a native classes MUST call __associateObjectWithNative
|
||||
// Failure to do so, it will crash.
|
||||
//
|
||||
var parent = goog.base(this);
|
||||
__associateObjWithNative( this, parent );
|
||||
this.init();
|
||||
|
||||
this.title = function () {
|
||||
return "No title";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "No Subtitle";
|
||||
}
|
||||
|
||||
}
|
||||
goog.inherits(BaseLayer, cc.Layer );
|
||||
|
||||
//
|
||||
// Instance 'base' methods
|
||||
// XXX: Should be defined after "goog.inherits"
|
||||
//
|
||||
BaseLayer.prototype.onEnter = function() {
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 28);
|
||||
this.addChild(label, 1);
|
||||
label.setPosition( cc.p(winSize.width / 2, winSize.height - 50));
|
||||
|
||||
var strSubtitle = this.subtitle();
|
||||
if (strSubtitle != "") {
|
||||
var l = cc.LabelTTF.create(strSubtitle, "Thonburi", 16);
|
||||
this.addChild(l, 1);
|
||||
l.setPosition( cc.p(winSize.width / 2, winSize.height - 80));
|
||||
}
|
||||
|
||||
// Menu
|
||||
var item1 = cc.MenuItemImage.create("Images/b1.png", "Images/b2.png", this, this.backCallback);
|
||||
var item2 = cc.MenuItemImage.create("Images/r1.png", "Images/r2.png", this, this.restartCallback);
|
||||
var item3 = cc.MenuItemImage.create("Images/f1.png", "Images/f2.png", this, this.nextCallback);
|
||||
var item4 = cc.MenuItemFont.create("back", this, function() { require("js/main.js"); } );
|
||||
item4.setFontSize( 22 );
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3, item4 );
|
||||
|
||||
menu.setPosition( cc.p(0,0) );
|
||||
item1.setPosition( cc.p(winSize.width / 2 - 100, 30));
|
||||
item2.setPosition( cc.p(winSize.width / 2, 30));
|
||||
item3.setPosition( cc.p(winSize.width / 2 + 100, 30));
|
||||
item4.setPosition( cc.p(winSize.width - 60, winSize.height - 30 ) );
|
||||
|
||||
this.addChild(menu, 1);
|
||||
}
|
||||
|
||||
BaseLayer.prototype.restartCallback = function (sender) {
|
||||
cc.log("restart called");
|
||||
restartSpriteTestAction();
|
||||
}
|
||||
|
||||
BaseLayer.prototype.nextCallback = function (sender) {
|
||||
cc.log("next called");
|
||||
nextSpriteTestAction();
|
||||
}
|
||||
|
||||
BaseLayer.prototype.backCallback = function (sender) {
|
||||
cc.log("back called");
|
||||
backSpriteTestAction();
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Chipmunk + Sprite
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var ChipmunkSpriteTest = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.addSprite = function( pos ) {
|
||||
var sprite = this.createPhysicsSprite( pos );
|
||||
this.addChild( sprite );
|
||||
}
|
||||
|
||||
this.title = function() {
|
||||
return 'Chipmunk Sprite Test';
|
||||
}
|
||||
|
||||
this.subtitle = function() {
|
||||
return 'Chipmunk + cocos2d sprites tests. Tap screen.';
|
||||
}
|
||||
|
||||
this.initPhysics();
|
||||
}
|
||||
goog.inherits( ChipmunkSpriteTest, BaseLayer );
|
||||
|
||||
//
|
||||
// Instance 'base' methods
|
||||
// XXX: Should be defined after "goog.inherits"
|
||||
//
|
||||
|
||||
// init physics
|
||||
ChipmunkSpriteTest.prototype.initPhysics = function() {
|
||||
this.space = cp.spaceNew();
|
||||
var staticBody = cp.spaceGetStaticBody( this.space );
|
||||
|
||||
// Walls
|
||||
var walls = [cp.segmentShapeNew( staticBody, cp.v(0,0), cp.v(winSize.width,0), 0 ), // bottom
|
||||
cp.segmentShapeNew( staticBody, cp.v(0,winSize.height), cp.v(winSize.width,winSize.height), 0), // top
|
||||
cp.segmentShapeNew( staticBody, cp.v(0,0), cp.v(0,winSize.height), 0), // left
|
||||
cp.segmentShapeNew( staticBody, cp.v(winSize.width,0), cp.v(winSize.width,winSize.height), 0) // right
|
||||
];
|
||||
for( var i=0; i < walls.length; i++ ) {
|
||||
var wall = walls[i];
|
||||
cp.shapeSetElasticity(wall, 1);
|
||||
cp.shapeSetFriction(wall, 1);
|
||||
cp.spaceAddStaticShape( this.space, wall );
|
||||
}
|
||||
|
||||
// Gravity
|
||||
cp.spaceSetGravity( this.space, cp.v(0, -100) );
|
||||
}
|
||||
|
||||
ChipmunkSpriteTest.prototype.createPhysicsSprite = function( pos ) {
|
||||
var body = cp.bodyNew(1, cp.momentForBox(1, 48, 108) );
|
||||
cp.bodySetPos( body, pos );
|
||||
cp.spaceAddBody( this.space, body );
|
||||
var shape = cp.boxShapeNew( body, 48, 108);
|
||||
cp.shapeSetElasticity( shape, 0.5 );
|
||||
cp.shapeSetFriction( shape, 0.5 );
|
||||
cp.spaceAddShape( this.space, shape );
|
||||
|
||||
var sprite = cc.PhysicsSprite.create("Images/grossini.png");
|
||||
sprite.setBody( body );
|
||||
return sprite;
|
||||
}
|
||||
|
||||
ChipmunkSpriteTest.prototype.onEnter = function () {
|
||||
|
||||
goog.base(this, 'onEnter');
|
||||
|
||||
this.scheduleUpdate();
|
||||
for(var i=0; i<10; i++) {
|
||||
this.addSprite( cp.v(winSize.width/2, winSize.height/2) );
|
||||
}
|
||||
|
||||
var platform = __getPlatform();
|
||||
if( platform.substring(0,7) == 'desktop' ) {
|
||||
this.setMouseEnabled( true );
|
||||
} else if( platform.substring(0,6) == 'mobile' ) {
|
||||
this.setTouchEnabled( true );
|
||||
}
|
||||
}
|
||||
|
||||
ChipmunkSpriteTest.prototype.update = function( delta ) {
|
||||
cp.spaceStep( this.space, delta );
|
||||
}
|
||||
|
||||
ChipmunkSpriteTest.prototype.onMouseDown = function( event ) {
|
||||
this.addSprite( event.getLocation() );
|
||||
}
|
||||
|
||||
ChipmunkSpriteTest.prototype.onTouchesEnded = function( touches, event ) {
|
||||
var l = touches.length;
|
||||
for( var i=0; i < l; i++) {
|
||||
this.addSprite( touches[i].getLocation() );
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Chipmunk + Sprite + Batch
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var ChipmunkSpriteBatchTest = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
// batch node
|
||||
this.batch = cc.SpriteBatchNode.create('Images/grossini.png', 50 );
|
||||
this.addChild( this.batch );
|
||||
|
||||
this.addSprite = function( pos ) {
|
||||
var sprite = this.createPhysicsSprite( pos );
|
||||
this.batch.addChild( sprite );
|
||||
}
|
||||
|
||||
this.title = function() {
|
||||
return 'Chipmunk SpriteBatch Test';
|
||||
}
|
||||
|
||||
this.subtitle = function() {
|
||||
return 'Chipmunk + cocos2d sprite batch tests. Tap screen.';
|
||||
}
|
||||
}
|
||||
goog.inherits( ChipmunkSpriteBatchTest, ChipmunkSpriteTest );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Chipmunk Collision Test
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var ChipmunkCollisionTest = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.messageDisplayed = false;
|
||||
|
||||
this.title = function() {
|
||||
return 'Chipmunk Collision Test';
|
||||
}
|
||||
|
||||
this.subtitle = function() {
|
||||
return 'Testing collision callback';
|
||||
}
|
||||
|
||||
// init physics
|
||||
this.initPhysics = function() {
|
||||
this.space = cp.spaceNew();
|
||||
var staticBody = cp.spaceGetStaticBody( this.space );
|
||||
|
||||
// Walls
|
||||
var walls = [cp.segmentShapeNew( staticBody, cp.v(0,0), cp.v(winSize.width,0), 0 ), // bottom
|
||||
cp.segmentShapeNew( staticBody, cp.v(0,winSize.height), cp.v(winSize.width,winSize.height), 0), // top
|
||||
cp.segmentShapeNew( staticBody, cp.v(0,0), cp.v(0,winSize.height), 0), // left
|
||||
cp.segmentShapeNew( staticBody, cp.v(winSize.width,0), cp.v(winSize.width,winSize.height), 0) // right
|
||||
];
|
||||
for( var i=0; i < walls.length; i++ ) {
|
||||
var wall = walls[i];
|
||||
cp.shapeSetElasticity(wall, 1);
|
||||
cp.shapeSetFriction(wall, 1);
|
||||
cp.spaceAddStaticShape( this.space, wall );
|
||||
}
|
||||
|
||||
// Gravity
|
||||
cp.spaceSetGravity( this.space, cp.v(0, -30) );
|
||||
}
|
||||
|
||||
this.createPhysicsSprite = function( pos, file, collision_type ) {
|
||||
var body = cp.bodyNew(1, cp.momentForBox(1, 48, 108) );
|
||||
cp.bodySetPos( body, pos );
|
||||
cp.spaceAddBody( this.space, body );
|
||||
var shape = cp.boxShapeNew( body, 48, 108);
|
||||
cp.shapeSetElasticity( shape, 0.5 );
|
||||
cp.shapeSetFriction( shape, 0.5 );
|
||||
cp.shapeSetCollisionType( shape, collision_type );
|
||||
cp.spaceAddShape( this.space, shape );
|
||||
|
||||
var sprite = cc.PhysicsSprite.create(file);
|
||||
sprite.setBody( body );
|
||||
return sprite;
|
||||
}
|
||||
|
||||
this.onEnter = function () {
|
||||
goog.base(this, 'onEnter');
|
||||
|
||||
this.initPhysics();
|
||||
this.scheduleUpdate();
|
||||
|
||||
var sprite1 = this.createPhysicsSprite( cc.p(winSize.width/2, winSize.height-20), "Images/grossini.png", 1);
|
||||
var sprite2 = this.createPhysicsSprite( cc.p(winSize.width/2, 50), "Images/grossinis_sister1.png", 2);
|
||||
|
||||
this.addChild( sprite1 );
|
||||
this.addChild( sprite2 );
|
||||
|
||||
cp.spaceAddCollisionHandler( this.space, 1, 2, this, this.collisionBegin, this.collisionPre, this.collisionPost, this.collisionSeparate );
|
||||
}
|
||||
|
||||
this.onExit = function() {
|
||||
cp.spaceRemoveCollisionHandler( this.space, 1, 2 );
|
||||
cp.spaceFree( this.space );
|
||||
}
|
||||
|
||||
this.update = function( delta ) {
|
||||
cp.spaceStep( this.space, delta );
|
||||
}
|
||||
|
||||
this.collisionBegin = function ( arbiter, space ) {
|
||||
|
||||
if( ! this.messageDisplayed ) {
|
||||
var label = cc.LabelBMFont.create("Collision Detected", "Fonts/bitmapFontTest5.fnt");
|
||||
this.addChild( label );
|
||||
label.setPosition( centerPos );
|
||||
this.messageDisplayed = true;
|
||||
}
|
||||
cc.log('collision begin');
|
||||
var bodies = cp.arbiterGetBodies( arbiter );
|
||||
var shapes = cp.arbiterGetShapes( arbiter );
|
||||
var collTypeA = cp.shapeGetCollisionType( shapes[0] );
|
||||
var collTypeB = cp.shapeGetCollisionType( shapes[1] );
|
||||
cc.log( 'Collision Type A:' + collTypeA );
|
||||
cc.log( 'Collision Type B:' + collTypeB );
|
||||
return true
|
||||
}
|
||||
|
||||
this.collisionPre = function ( arbiter, space ) {
|
||||
cc.log('collision pre');
|
||||
return true;
|
||||
}
|
||||
|
||||
this.collisionPost = function ( arbiter, space ) {
|
||||
cc.log('collision post');
|
||||
}
|
||||
|
||||
this.collisionSeparate = function ( arbiter, space ) {
|
||||
cc.log('collision separate');
|
||||
}
|
||||
|
||||
}
|
||||
goog.inherits( ChipmunkCollisionTest, BaseLayer );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Chipmunk Collision Memory Leak Test
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var ChipmunkCollisionMemoryLeakTest = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.title = function() {
|
||||
return 'Chipmunk Memory Leak Test';
|
||||
}
|
||||
|
||||
this.subtitle = function() {
|
||||
return 'Testing possible memory leak on the collision handler. No visual feedback';
|
||||
}
|
||||
|
||||
this.collisionBegin = function ( arbiter, space ) {
|
||||
return true
|
||||
}
|
||||
|
||||
this.collisionPre = function ( arbiter, space ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
this.collisionPost = function ( arbiter, space ) {
|
||||
cc.log('collision post');
|
||||
}
|
||||
|
||||
this.collisionSeparate = function ( arbiter, space ) {
|
||||
cc.log('collision separate');
|
||||
}
|
||||
|
||||
this.onEnter = function() {
|
||||
goog.base(this, 'onEnter');
|
||||
this.space = cp.spaceNew();
|
||||
|
||||
for( var i=1 ; i < 100 ; i++ )
|
||||
cp.spaceAddCollisionHandler( this.space, i, i+1, this, this.collisionBegin, this.collisionPre, this.collisionPost, this.collisionSeparate );
|
||||
|
||||
}
|
||||
|
||||
this.onExit = function() {
|
||||
|
||||
for( var i=1 ; i < 100 ; i++ )
|
||||
cp.spaceRemoveCollisionHandler( this.space, i, i+1 );
|
||||
|
||||
cp.spaceFree( this.space );
|
||||
}
|
||||
}
|
||||
goog.inherits( ChipmunkCollisionMemoryLeakTest, BaseLayer );
|
||||
//
|
||||
// Instance 'base' methods
|
||||
// XXX: Should be defined after "goog.inherits"
|
||||
//
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Order of tests
|
||||
//
|
||||
|
||||
scenes.push( ChipmunkSpriteTest ); scenes.push( ChipmunkSpriteBatchTest );
|
||||
scenes.push( ChipmunkCollisionTest );
|
||||
scenes.push( ChipmunkCollisionMemoryLeakTest );
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Main entry point
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
function run()
|
||||
{
|
||||
var scene = cc.Scene.create();
|
||||
var layer = new scenes[currentScene]();
|
||||
scene.addChild( layer );
|
||||
|
||||
var runningScene = director.getRunningScene();
|
||||
if( runningScene == null )
|
||||
director.runWithScene( scene );
|
||||
else
|
||||
director.replaceScene( cc.TransitionFade.create(0.5, scene ) );
|
||||
}
|
||||
|
||||
run();
|
|
@ -1,749 +0,0 @@
|
|||
//
|
||||
// http://www.cocos2d-iphone.org
|
||||
//
|
||||
// Javascript + chipmunk tests
|
||||
//
|
||||
|
||||
require("js/helper.js");
|
||||
|
||||
director = cc.Director.getInstance();
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var scenes = []
|
||||
var currentScene = 0;
|
||||
var withTransition = false;
|
||||
|
||||
var nextScene = function () {
|
||||
currentScene = currentScene + 1;
|
||||
if( currentScene >= scenes.length )
|
||||
currentScene = 0;
|
||||
|
||||
withTransition = true;
|
||||
loadScene(currentScene);
|
||||
};
|
||||
var previousScene = function () {
|
||||
currentScene = currentScene -1;
|
||||
if( currentScene < 0 )
|
||||
currentScene = scenes.length -1;
|
||||
|
||||
withTransition = true;
|
||||
loadScene(currentScene);
|
||||
};
|
||||
var restartScene = function () {
|
||||
loadScene( currentScene );
|
||||
};
|
||||
|
||||
var loadScene = function (sceneIdx)
|
||||
{
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var scene = new cc.Scene();
|
||||
scene.init();
|
||||
var layer = new scenes[ sceneIdx ]();
|
||||
|
||||
scene.addChild( layer );
|
||||
|
||||
// scene.walkSceneGraph(0);
|
||||
|
||||
var transitions = [ cc.TransitionSplitCols, cc.TransitionSplitRows,
|
||||
cc.TransitionSlideInL, cc.TransitionSlideInR, cc.TransitionSlideInT, cc.TransitionSlideInB,
|
||||
cc.TransitionFade, cc.TransitionCrossFade,
|
||||
cc.TransitionFlipX, cc.TransitionFlipY,
|
||||
cc.TransitionProgressRadialCCW, cc.TransitionProgressRadialCW, cc.TransitionProgressVertical, cc.TransitionProgressHorizontal,
|
||||
cc.TransitionShrinkGrow,
|
||||
];
|
||||
var idx = Math.floor( Math.random() * transitions.length );
|
||||
var transition = transitions[ idx ];
|
||||
|
||||
if( withTransition == true )
|
||||
director.replaceScene( transition.create( 0.9, scene ) );
|
||||
else
|
||||
director.replaceScene( scene );
|
||||
|
||||
withTransition = false;
|
||||
// __jsc__.garbageCollect();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// BaseLayer
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var BaseLayer = function() {
|
||||
|
||||
//
|
||||
// VERY IMPORTANT
|
||||
//
|
||||
// Only subclasses of a native classes MUST call __associateObjectWithNative
|
||||
// Failure to do so, it will crash.
|
||||
//
|
||||
var parent = goog.base(this);
|
||||
__associateObjWithNative( this, parent );
|
||||
this.init( cc.c4b(0,0,0,255), cc.c4b(0,128,255,255));
|
||||
|
||||
this.title = "No title";
|
||||
this.subtitle = "No Subtitle";
|
||||
this.isMainTitle = false;
|
||||
|
||||
}
|
||||
goog.inherits(BaseLayer, cc.LayerGradient );
|
||||
|
||||
//
|
||||
// Instance 'base' methods
|
||||
// XXX: Should be defined after "goog.inherits"
|
||||
//
|
||||
BaseLayer.prototype.onEnter = function() {
|
||||
|
||||
var fontSize = 36;
|
||||
var tl = this.title.length;
|
||||
fontSize = (winSize.width / tl) * 1.60;
|
||||
if( fontSize/winSize.width > 0.09 ) {
|
||||
fontSize = winSize.width * 0.09;
|
||||
}
|
||||
|
||||
this.label = cc.LabelTTF.create(this.title, "Gill Sans", fontSize);
|
||||
this.addChild(this.label, 100);
|
||||
|
||||
var isMain = this.isMainTitle;
|
||||
|
||||
if( isMain == true )
|
||||
this.label.setPosition( centerPos );
|
||||
else
|
||||
this.label.setPosition( cc.p(winSize.width / 2, winSize.height*11/12) );
|
||||
|
||||
var subStr = this.subtitle;
|
||||
if (subStr != "") {
|
||||
tl = this.subtitle.length;
|
||||
var subfontSize = (winSize.width / tl) * 1.3;
|
||||
if( subfontSize > fontSize *0.6 ) {
|
||||
subfontSize = fontSize *0.6;
|
||||
}
|
||||
|
||||
this.sublabel = cc.LabelTTF.create(subStr, "Thonburi", subfontSize);
|
||||
this.addChild(this.sublabel, 90);
|
||||
if( isMain )
|
||||
this.sublabel.setPosition( cc.p(winSize.width / 2, winSize.height*3/8 ));
|
||||
else
|
||||
this.sublabel.setPosition( cc.p(winSize.width / 2, winSize.height*5/6 ));
|
||||
} else
|
||||
this.sublabel = null;
|
||||
|
||||
// Menu
|
||||
var item1 = cc.MenuItemImage.create("b1.png", "b2.png", this, this.backCallback);
|
||||
var item2 = cc.MenuItemImage.create("r1.png", "r2.png", this, this.restartCallback);
|
||||
var item3 = cc.MenuItemImage.create("f1.png", "f2.png", this, this.nextCallback);
|
||||
var item4 = cc.MenuItemFont.create("back", this, function() { require("js/main.js"); } );
|
||||
item4.setFontSize( 22 );
|
||||
|
||||
[item1, item2, item3 ].forEach( function(item) {
|
||||
item.normalImage().setOpacity(45);
|
||||
item.selectedImage().setOpacity(45);
|
||||
} );
|
||||
|
||||
var menu = cc.Menu.create( item1, item2, item3, item4 );
|
||||
|
||||
menu.setPosition( cc.p(0,0) );
|
||||
item1.setPosition( cc.p(winSize.width / 2 - 100, 30));
|
||||
item2.setPosition( cc.p(winSize.width / 2, 30));
|
||||
item3.setPosition( cc.p(winSize.width / 2 + 100, 30));
|
||||
item4.setPosition( cc.p(winSize.width - 60, winSize.height - 30 ) );
|
||||
|
||||
this.addChild(menu, 80);
|
||||
}
|
||||
|
||||
BaseLayer.prototype.createBulletList = function () {
|
||||
var str = "";
|
||||
for(var i=0; i<arguments.length; i++)
|
||||
{
|
||||
if(i != 0)
|
||||
str += "\n";
|
||||
str += '- ' + arguments[i];
|
||||
}
|
||||
|
||||
cc.log( str );
|
||||
|
||||
var fontSize = winSize.height*0.07;
|
||||
var bullets = cc.LabelTTF.create( str, "Gill Sans", fontSize );
|
||||
bullets.setPosition( centerPos );
|
||||
this.addChild( bullets, 80 );
|
||||
}
|
||||
|
||||
BaseLayer.prototype.createImage = function( file ) {
|
||||
var sprite = cc.Sprite.create( file );
|
||||
sprite.setPosition( centerPos );
|
||||
this.addChild( sprite, 70 );
|
||||
|
||||
return sprite;
|
||||
}
|
||||
|
||||
|
||||
BaseLayer.prototype.restartCallback = function (sender) {
|
||||
restartScene();
|
||||
}
|
||||
|
||||
BaseLayer.prototype.nextCallback = function (sender) {
|
||||
nextScene();
|
||||
}
|
||||
|
||||
BaseLayer.prototype.backCallback = function (sender) {
|
||||
previousScene();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Intro Page
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var IntroPage = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.background1 = this.createImage( 'Official-cocos2d-Icon-Angry.png');
|
||||
this.background2 = this.createImage( 'Official-cocos2d-Icon-Happy.png');
|
||||
|
||||
this.background2.setOpacity( 0 );
|
||||
|
||||
// Not working setZOrder() ??
|
||||
// sprite.setZOrder( -200 );
|
||||
|
||||
this.title = 'cocos2d + JS'
|
||||
this.subtitle = 'Javascript bindings for cocos2d';
|
||||
this.isMainTitle = true;
|
||||
|
||||
this.onEnterTransitionDidFinish = function() {
|
||||
var fade_out1 = cc.FadeOut.create( 2 );
|
||||
var fade_in1 = fade_out1.reverse();
|
||||
var delay1 = cc.DelayTime.create(4);
|
||||
|
||||
var seq1 = cc.Sequence.create( fade_out1, fade_in1, delay1 );
|
||||
this.background1.runAction( cc.RepeatForever.create( seq1 ) );
|
||||
|
||||
var delay2 = cc.DelayTime.create(4);
|
||||
var fade_out2 = cc.FadeOut.create( 2 );
|
||||
var fade_in2 = fade_out2.reverse();
|
||||
|
||||
var seq2 = cc.Sequence.create( delay2, fade_in2, fade_out2 );
|
||||
this.background2.runAction( cc.RepeatForever.create( seq2 ) );
|
||||
}
|
||||
}
|
||||
goog.inherits( IntroPage, BaseLayer );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// About Page
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var AboutPage = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.title = 'About';
|
||||
this.subtitle = 'What is cocos2d + JS ?';
|
||||
this.isMainTitle = false;
|
||||
|
||||
this.createBulletList( 'Javascript bindings for cocos2d',
|
||||
'Same JS API as cocos2d-html5',
|
||||
'Works on iOS and Mac',
|
||||
'Faster development',
|
||||
'Great prototyping tool');
|
||||
}
|
||||
goog.inherits( AboutPage, BaseLayer );
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Sprites Page
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpritesPage = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.title = 'Sprites';
|
||||
this.subtitle = ''
|
||||
|
||||
var fontSize = winSize.height * 0.05;
|
||||
|
||||
var label = cc.LabelTTF.create('cc.Sprite.create("grossini.png");', 'CourierNewPSMT', fontSize );
|
||||
label.setPosition( cc.p( winSize.width/2, winSize.height*1/5) );
|
||||
this.addChild( label );
|
||||
|
||||
var sprite1 = cc.Sprite.create("grossinis_sister1.png");
|
||||
sprite1.setPosition( cc.p( winSize.width*1/4, winSize.height/2) );
|
||||
|
||||
var sprite2 = cc.Sprite.create("grossini.png");
|
||||
sprite2.setPosition( cc.p( winSize.width*2/4, winSize.height/2) );
|
||||
|
||||
var sprite3 = cc.Sprite.create("grossinis_sister2.png");
|
||||
sprite3.setPosition( cc.p( winSize.width*3/4, winSize.height/2) );
|
||||
|
||||
this.addChild( sprite1 );
|
||||
this.addChild( sprite2 );
|
||||
this.addChild( sprite3 );
|
||||
}
|
||||
goog.inherits( SpritesPage, BaseLayer );
|
||||
|
||||
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Labels Page
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var LabelsPage = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.title = 'Labels';
|
||||
this.subtitle = ''
|
||||
|
||||
var fontSize = winSize.height * 0.03;
|
||||
|
||||
var label = cc.LabelTTF.create('cc.LabelTTF.create("Hello JS World", "Marker Felt", 32);\ncc.LabelBMFont.create("Hello World", "font.fnt")', 'CourierNewPSMT', fontSize );
|
||||
label.setPosition( cc.p( winSize.width/2, winSize.height*1/5) );
|
||||
this.addChild( label );
|
||||
|
||||
|
||||
var labelTTF = cc.LabelTTF.create('Label TTF', 'Marker Felt', 48 );
|
||||
labelTTF.setPosition( cc.p( winSize.width*1/4, winSize.height/2) );
|
||||
this.addChild( labelTTF );
|
||||
|
||||
var labelBM = cc.LabelBMFont.create('Label BMFont', 'futura-48.fnt');
|
||||
labelBM.setPosition( cc.p( winSize.width*3/4, winSize.height/2) );
|
||||
this.addChild( labelBM );
|
||||
|
||||
// var labelAtlas = cc.LabelAtlas.create('Atlas', 'tuffy_bold_italic-charmap.plist');
|
||||
// labelAtlas.setPosition( cc.p( winSize.width*3/5, winSize.height/2) );
|
||||
// this.addChild( labelAtlas );
|
||||
|
||||
}
|
||||
goog.inherits( LabelsPage, BaseLayer );
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Actions Page
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var ActionsPage = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.title = 'Actions';
|
||||
this.subtitle = ''
|
||||
|
||||
var fontSize = winSize.height * 0.05;
|
||||
|
||||
var label = cc.LabelTTF.create('cc.RotateBy.create(8, 360);', 'CourierNewPSMT', fontSize );
|
||||
label.setPosition( cc.p( winSize.width/2, winSize.height*1/5) );
|
||||
this.addChild( label );
|
||||
|
||||
this.sprite = cc.Sprite.create("grossini.png");
|
||||
this.sprite.setPosition( cc.p( winSize.width*2/4, winSize.height/2) );
|
||||
this.addChild( this.sprite );
|
||||
|
||||
this.onEnterTransitionDidFinish = function() {
|
||||
var action = cc.RotateBy.create(8, 360);
|
||||
this.sprite.runAction( action );
|
||||
}
|
||||
}
|
||||
goog.inherits( ActionsPage, BaseLayer );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Actions Complex Page
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var ActionsComplexPage = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.title = 'Complex Actions';
|
||||
this.subtitle = ''
|
||||
|
||||
var fontSize = winSize.height * 0.05;
|
||||
|
||||
var label = cc.LabelTTF.create('cc.Sequence.create(action1, action2,...);', 'CourierNewPSMT', fontSize );
|
||||
label.setPosition( cc.p( winSize.width/2, winSize.height*1/5) );
|
||||
this.addChild( label );
|
||||
|
||||
this.sprite = cc.Sprite.create("grossini.png");
|
||||
this.sprite.setPosition( cc.p( winSize.width*2/4, winSize.height/2) );
|
||||
this.addChild( this.sprite );
|
||||
|
||||
// This function is not portable to cocos2d-html5
|
||||
this.sprite.getTexture().setAliasTexParameters();
|
||||
|
||||
this.onEnterTransitionDidFinish = function() {
|
||||
var rot = cc.RotateBy.create(1, 360);
|
||||
var rot_back = rot.reverse();
|
||||
var scale = cc.ScaleBy.create(1, 7);
|
||||
var scale_back = scale.reverse();
|
||||
var seq = cc.Sequence.create( rot, scale, rot_back, scale_back );
|
||||
|
||||
this.sprite.runAction( cc.RepeatForever.create( seq ) );
|
||||
}
|
||||
}
|
||||
goog.inherits( ActionsComplexPage, BaseLayer );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Actions Ease Page
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var ActionsEasePage = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.title = 'Ease Actions';
|
||||
this.subtitle = ''
|
||||
|
||||
var fontSize = winSize.height * 0.05;
|
||||
|
||||
var label = cc.LabelTTF.create('cc.EaseIn.create(action1, rate);', 'CourierNewPSMT', fontSize );
|
||||
label.setPosition( cc.p( winSize.width/2, winSize.height*1/5) );
|
||||
this.addChild( label );
|
||||
|
||||
this.sprite1 = cc.Sprite.create("grossini.png");
|
||||
this.sprite2 = cc.Sprite.create("grossinis_sister1.png");
|
||||
this.sprite3 = cc.Sprite.create("grossinis_sister2.png");
|
||||
|
||||
this.addChild( this.sprite1 );
|
||||
this.addChild( this.sprite2 );
|
||||
this.addChild( this.sprite3 );
|
||||
|
||||
this.sprite1.setPosition( cc.p(60, winSize.height*1/5) );
|
||||
this.sprite2.setPosition( cc.p(60, winSize.height*2.5/5) );
|
||||
this.sprite3.setPosition( cc.p(60, winSize.height*4/5) );
|
||||
|
||||
this.onEnterTransitionDidFinish = function() {
|
||||
var move = cc.MoveBy.create( 3, cc.p(winSize.width-130,0) );
|
||||
var move_back = move.reverse();
|
||||
|
||||
var move_ease_in = cc.EaseIn.create( move.copy(), 2.5 );
|
||||
var move_ease_in_back = move_ease_in.reverse();
|
||||
|
||||
var move_ease_out = cc.EaseOut.create( move.copy(), 2.5 );
|
||||
var move_ease_out_back = move_ease_out.reverse();
|
||||
|
||||
var delay = cc.DelayTime.create( 0.25 );
|
||||
|
||||
var seq1 = cc.Sequence.create( move, delay, move_back, delay.copy());
|
||||
var seq2 = cc.Sequence.create( move_ease_in, delay.copy(), move_ease_in_back, delay.copy() );
|
||||
var seq3 = cc.Sequence.create( move_ease_out, delay.copy(), move_ease_out_back, delay.copy() );
|
||||
|
||||
this.sprite1.runAction( cc.RepeatForever.create( seq1 ) );
|
||||
this.sprite2.runAction( cc.RepeatForever.create( seq2 ) );
|
||||
this.sprite3.runAction( cc.RepeatForever.create( seq3 ) );
|
||||
}
|
||||
}
|
||||
goog.inherits( ActionsEasePage, BaseLayer );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Particles Page
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var ParticlesPage = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.title = 'Particles';
|
||||
this.subtitle = ''
|
||||
|
||||
var fontSize = winSize.height * 0.05;
|
||||
|
||||
var label = cc.LabelTTF.create('cc.ParticleSystem.create("myparticle.plist");', 'CourierNewPSMT', fontSize );
|
||||
label.setPosition( cc.p( winSize.width/2, winSize.height*1/5) );
|
||||
this.addChild( label );
|
||||
|
||||
this.particle = cc.ParticleSystem.create("Particles/Flower.plist");
|
||||
this.addChild( this.particle );
|
||||
this.particle.setPosition( centerPos );
|
||||
|
||||
var platform = __getPlatform();
|
||||
if( platform.substring(0,7) == 'desktop' )
|
||||
this.setMouseEnabled( true );
|
||||
else if( platform.substring(0,6) == 'mobile' )
|
||||
this.setTouchEnabled( true );
|
||||
|
||||
this.onMouseDown = function( event ) {
|
||||
this.particle.setPosition( event.getLocation() );
|
||||
}
|
||||
|
||||
this.onMouseDragged = function( event ) {
|
||||
return this.onMouseDown( event );
|
||||
}
|
||||
|
||||
this.onTouchesEnded = function( touches, event ) {
|
||||
var l = touches.length;
|
||||
for( var i=0; i < l; i++) {
|
||||
this.particle.setPosition( touches[i].getLocation() );
|
||||
}
|
||||
}
|
||||
|
||||
this.onTouchesMoved = function( touches, event ) {
|
||||
return this.onTouchesEnded( touches, event );
|
||||
}
|
||||
|
||||
}
|
||||
goog.inherits( ParticlesPage, BaseLayer );
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Chipmunk Page
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var ChipmunkPage = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
// batch node
|
||||
this.batch = cc.SpriteBatchNode.create('grossini.png', 50 );
|
||||
this.addChild( this.batch );
|
||||
|
||||
this.addSprite = function( pos ) {
|
||||
var sprite = this.createPhysicsSprite( pos );
|
||||
this.batch.addChild( sprite );
|
||||
}
|
||||
|
||||
this.title = 'Physics Integration';
|
||||
this.subtitle = 'Integration with Chipmunk Physics Engine';
|
||||
|
||||
this.initPhysics();
|
||||
}
|
||||
goog.inherits( ChipmunkPage, BaseLayer );
|
||||
|
||||
//
|
||||
// Instance 'base' methods
|
||||
// XXX: Should be defined after "goog.inherits"
|
||||
//
|
||||
|
||||
// init physics
|
||||
ChipmunkPage.prototype.initPhysics = function() {
|
||||
this.space = cp.spaceNew();
|
||||
var staticBody = cp.spaceGetStaticBody( this.space );
|
||||
|
||||
// Walls
|
||||
var walls = [cp.segmentShapeNew( staticBody, cp.v(0,0), cp.v(winSize.width,0), 0 ), // bottom
|
||||
cp.segmentShapeNew( staticBody, cp.v(0,winSize.height), cp.v(winSize.width,winSize.height), 0), // top
|
||||
cp.segmentShapeNew( staticBody, cp.v(0,0), cp.v(0,winSize.height), 0), // left
|
||||
cp.segmentShapeNew( staticBody, cp.v(winSize.width,0), cp.v(winSize.width,winSize.height), 0) // right
|
||||
];
|
||||
for( var i=0; i < walls.length; i++ ) {
|
||||
var wall = walls[i];
|
||||
cp.shapeSetElasticity(wall, 1);
|
||||
cp.shapeSetFriction(wall, 1);
|
||||
cp.spaceAddStaticShape( this.space, wall );
|
||||
}
|
||||
|
||||
// Gravity
|
||||
cp.spaceSetGravity( this.space, cp.v(0, -100) );
|
||||
}
|
||||
|
||||
ChipmunkPage.prototype.createPhysicsSprite = function( pos ) {
|
||||
var body = cp.bodyNew(1, cp.momentForBox(1, 48, 108) );
|
||||
cp.bodySetPos( body, pos );
|
||||
cp.spaceAddBody( this.space, body );
|
||||
var shape = cp.boxShapeNew( body, 48, 108);
|
||||
cp.shapeSetElasticity( shape, 0.5 );
|
||||
cp.shapeSetFriction( shape, 0.5 );
|
||||
cp.spaceAddShape( this.space, shape );
|
||||
|
||||
var sprite = cc.ChipmunkSprite.create("grossini.png");
|
||||
sprite.setBody( body );
|
||||
return sprite;
|
||||
}
|
||||
|
||||
ChipmunkPage.prototype.onEnter = function () {
|
||||
|
||||
goog.base(this, 'onEnter');
|
||||
|
||||
for(var i=0; i<20; i++) {
|
||||
var x = 40 + Math.random() * (winSize.width-80);
|
||||
var y = winSize.height/2 + Math.random() * 80;
|
||||
this.addSprite( cp.v(x, y) );
|
||||
}
|
||||
|
||||
var platform = __getPlatform();
|
||||
if( platform.substring(0,7) == 'desktop' )
|
||||
this.setMouseEnabled( true );
|
||||
else if( platform.substring(0,6) == 'mobile' )
|
||||
this.setTouchEnabled( true );
|
||||
}
|
||||
|
||||
ChipmunkPage.prototype.onEnterTransitionDidFinish = function () {
|
||||
this.scheduleUpdate();
|
||||
}
|
||||
|
||||
|
||||
ChipmunkPage.prototype.update = function( delta ) {
|
||||
cp.spaceStep( this.space, delta );
|
||||
}
|
||||
|
||||
ChipmunkPage.prototype.onMouseDown = function( event ) {
|
||||
this.addSprite( event.getLocation() );
|
||||
}
|
||||
|
||||
ChipmunkPage.prototype.onTouchesEnded = function( touches, event ) {
|
||||
var l = touches.length;
|
||||
for( var i=0; i < l; i++) {
|
||||
this.addSprite( touches[i].getLocation() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Behind The Scenes Page
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var BehindTheScenesPage = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.title = 'Behind The Scenes';
|
||||
this.subtitle = '';
|
||||
this.isMainTitle = true;
|
||||
|
||||
}
|
||||
goog.inherits( BehindTheScenesPage, BaseLayer );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// ParserFeaturesPage Page
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var ParserFeaturesPage = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.title = 'Parser Features';
|
||||
this.subtitle = '';
|
||||
this.isMainTitle = false;
|
||||
|
||||
this.createBulletList( 'Any Objective-C / C library',
|
||||
'No need to modify generated code',
|
||||
'No need to modify parsed library',
|
||||
'Easy to maintain and extend',
|
||||
'Powerful config file' );
|
||||
}
|
||||
goog.inherits( ParserFeaturesPage, BaseLayer );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Internals
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var InternalsPage = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.title = 'Internals';
|
||||
this.subtitle = 'Solid internal design';
|
||||
this.isMainTitle = false;
|
||||
|
||||
this.onEnterTransitionDidFinish = function() {
|
||||
// super onEnter
|
||||
// goog.base( this, 'onEnterTransitionDidFinish' );
|
||||
|
||||
var spr = this.createImage( 'Presentation/proxy_model.png' );
|
||||
spr.setScale( 0.1 );
|
||||
var scaleAction = cc.ScaleTo.create( 0.7, 1);
|
||||
spr.runAction( scaleAction );
|
||||
}
|
||||
}
|
||||
goog.inherits( InternalsPage, BaseLayer );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// DemoPage
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var DemoPage = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.title = 'Demo';
|
||||
this.subtitle = '';
|
||||
this.isMainTitle = true;
|
||||
}
|
||||
goog.inherits( DemoPage, BaseLayer );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// OneMoreThing
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var OneMoreThingPage = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.title = 'One More Thing';
|
||||
this.subtitle = '';
|
||||
this.isMainTitle = true;
|
||||
}
|
||||
goog.inherits( OneMoreThingPage, BaseLayer );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Thanks
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var ThanksPage = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.title = 'Thanks';
|
||||
this.subtitle = '';
|
||||
this.isMainTitle = true;
|
||||
}
|
||||
goog.inherits( ThanksPage, BaseLayer );
|
||||
|
||||
|
||||
//
|
||||
// Order of tests
|
||||
//
|
||||
scenes.push( IntroPage );
|
||||
scenes.push( AboutPage );
|
||||
scenes.push( SpritesPage );
|
||||
scenes.push( LabelsPage );
|
||||
scenes.push( ActionsPage );
|
||||
scenes.push( ActionsComplexPage );
|
||||
scenes.push( ActionsEasePage );
|
||||
scenes.push( ParticlesPage );
|
||||
scenes.push( ChipmunkPage );
|
||||
scenes.push( BehindTheScenesPage );
|
||||
scenes.push( ParserFeaturesPage );
|
||||
scenes.push( InternalsPage );
|
||||
scenes.push( DemoPage );
|
||||
scenes.push( OneMoreThingPage );
|
||||
scenes.push( ThanksPage );
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Main entry point
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
function run()
|
||||
{
|
||||
var scene = cc.Scene.create();
|
||||
var layer = new scenes[currentScene]();
|
||||
scene.addChild( layer );
|
||||
|
||||
director.setDisplayStats( false );
|
||||
|
||||
var runningScene = director.getRunningScene();
|
||||
if( runningScene == null )
|
||||
director.runWithScene( scene );
|
||||
else
|
||||
director.replaceScene( cc.TransitionFade.create(0.5, scene ) );
|
||||
}
|
||||
|
||||
run();
|
||||
|
|
@ -1,306 +0,0 @@
|
|||
//
|
||||
// http://www.cocos2d-iphone.org
|
||||
// http://www.cocos2d-html5.org
|
||||
// http://www.cocos2d-x.org
|
||||
//
|
||||
// Javascript + CocosDenshion tests
|
||||
//
|
||||
//
|
||||
require("js/helper.js");
|
||||
|
||||
director = cc.Director.getInstance();
|
||||
audioEngine = cc.AudioEngine.getInstance();
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var MUSIC_FILE = "Cyber Advance!.mp3";
|
||||
var EFFECT_FILE = "cowbell.wav";
|
||||
|
||||
var DenshionTests = [
|
||||
{
|
||||
title:"playBackgroundMusic",
|
||||
playFunc:function () {
|
||||
return new playBackgroundMusic();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"stopBackgroundMusic",
|
||||
playFunc:function () {
|
||||
return new stopBackgroundMusic();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"pauseBackgroundMusic",
|
||||
playFunc:function () {
|
||||
return new pauseBackgroundMusic();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"resumeBackgroundMusic",
|
||||
playFunc:function () {
|
||||
return new resumeBackgroundMusic();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"rewindBackgroundMusic",
|
||||
playFunc:function () {
|
||||
return new rewindBackgroundMusic();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"isBackgroundMusicPlaying",
|
||||
playFunc:function () {
|
||||
return new isBackgroundMusicPlaying();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"playEffect",
|
||||
playFunc:function () {
|
||||
return new playEffect();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"playEffectRepeatly",
|
||||
playFunc:function () {
|
||||
return new playEffectRepeatly();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"stopEffect",
|
||||
playFunc:function () {
|
||||
return new stopEffect();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"unloadEffect",
|
||||
playFunc:function () {
|
||||
return new unloadEffect();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"addBackgroundMusicVolume",
|
||||
playFunc:function () {
|
||||
return new addBackgroundMusicVolume();
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
title:"subBackgroundMusicVolume",
|
||||
playFunc:function () {
|
||||
return new subBackgroundMusicVolume();
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
title:"addEffectsVolume",
|
||||
playFunc:function () {
|
||||
return new addEffectsVolume();
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
title:"subEffectsVolume",
|
||||
playFunc:function () {
|
||||
return new subEffectsVolume();
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
title:"pauseEffect",
|
||||
playFunc:function () {
|
||||
return new pauseEffect();
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
title:"resumeEffect",
|
||||
playFunc:function () {
|
||||
return new resumeEffect();
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
title:"pauseAllEffects",
|
||||
playFunc:function () {
|
||||
return new pauseAllEffects();
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
title:"resumeAllEffects",
|
||||
playFunc:function () {
|
||||
return new resumeAllEffects();
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
title:"stopAllEffects",
|
||||
playFunc:function () {
|
||||
return new stopAllEffects();
|
||||
}
|
||||
}
|
||||
|
||||
];
|
||||
|
||||
CocosDenshionTest = cc.LayerGradient.extend({
|
||||
_menu:null,
|
||||
ctor:function () {
|
||||
|
||||
var parent = new cc.LayerGradient();
|
||||
__associateObjWithNative(this, parent);
|
||||
this.init(cc.c4b(0, 0, 0, 255), cc.c4b(0, 128, 255, 255));
|
||||
|
||||
// add menu items for tests
|
||||
this._menu = cc.Menu.create();
|
||||
var s = winSize;
|
||||
for (var i = 0; i < DenshionTests.length; i++) {
|
||||
var label = cc.LabelTTF.create(DenshionTests[i].title, "Arial", 20);
|
||||
var menuItem = cc.MenuItemLabel.create(label, this, this.menuCallback);
|
||||
this._menu.addChild(menuItem, i + 10000);
|
||||
}
|
||||
this._menu.setPosition(cc.p(winSize.width/2, winSize.height/2) );
|
||||
this._menu.alignItemsVertically()
|
||||
this.addChild(this._menu);
|
||||
|
||||
// set default volume
|
||||
audioEngine.setEffectsVolume(0.5);
|
||||
audioEngine.setBackgroundMusicVolume(0.5);
|
||||
|
||||
// Back button
|
||||
var itemBack = cc.MenuItemFont.create("back", this, function() { require("js/main.js"); } );
|
||||
itemBack.setPosition( cc.p(winSize.width - 60, winSize.height - 30 ) );
|
||||
itemBack.setFontSize( 22 );
|
||||
var menuBack = cc.Menu.create( itemBack );
|
||||
menuBack.setPosition( cc.p(0,0) );
|
||||
this.addChild( menuBack, 10 );
|
||||
|
||||
},
|
||||
menuCallback:function (sender) {
|
||||
var idx = sender.getZOrder() - 10000;
|
||||
// create the test scene and run it
|
||||
var scene = DenshionTests[idx].playFunc();
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
var soundId = null;
|
||||
|
||||
var playBackgroundMusic = function () {
|
||||
cc.log("play background music");
|
||||
audioEngine.playBackgroundMusic(MUSIC_FILE, false);
|
||||
};
|
||||
|
||||
var stopBackgroundMusic = function () {
|
||||
cc.log("stop background music");
|
||||
audioEngine.stopBackgroundMusic();
|
||||
};
|
||||
|
||||
var pauseBackgroundMusic = function () {
|
||||
cc.log("pause background music");
|
||||
audioEngine.pauseBackgroundMusic();
|
||||
};
|
||||
|
||||
var resumeBackgroundMusic = function () {
|
||||
cc.log("resume background music");
|
||||
audioEngine.resumeBackgroundMusic();
|
||||
};
|
||||
|
||||
var rewindBackgroundMusic = function () {
|
||||
cc.log("rewind background music");
|
||||
audioEngine.rewindBackgroundMusic();
|
||||
};
|
||||
|
||||
// is background music playing
|
||||
var isBackgroundMusicPlaying = function () {
|
||||
if (audioEngine.isBackgroundMusicPlaying()) {
|
||||
cc.log("background music is playing");
|
||||
}
|
||||
else {
|
||||
cc.log("background music is not playing");
|
||||
}
|
||||
};
|
||||
|
||||
var playEffect = function () {
|
||||
cc.log("play effect");
|
||||
soundId = audioEngine.playEffect(EFFECT_FILE);
|
||||
};
|
||||
|
||||
var playEffectRepeatly = function () {
|
||||
cc.log("play effect repeatly");
|
||||
soundId = audioEngine.playEffect(EFFECT_FILE, true);
|
||||
};
|
||||
|
||||
var stopEffect = function () {
|
||||
cc.log("stop effect");
|
||||
audioEngine.stopEffect(soundId);
|
||||
};
|
||||
|
||||
var unloadEffect = function () {
|
||||
cc.log("unload effect");
|
||||
audioEngine.unloadEffect(EFFECT_FILE);
|
||||
};
|
||||
|
||||
var addBackgroundMusicVolume = function () {
|
||||
cc.log("add bakcground music volume");
|
||||
audioEngine.setBackgroundMusicVolume(audioEngine.getBackgroundMusicVolume() + 0.1);
|
||||
};
|
||||
|
||||
var subBackgroundMusicVolume = function () {
|
||||
cc.log("sub backgroud music volume");
|
||||
audioEngine.setBackgroundMusicVolume(audioEngine.getBackgroundMusicVolume() - 0.1);
|
||||
};
|
||||
|
||||
var addEffectsVolume = function () {
|
||||
cc.log("add effects volume");
|
||||
audioEngine.setEffectsVolume(audioEngine.getEffectsVolume() + 0.1);
|
||||
};
|
||||
|
||||
var subEffectsVolume = function () {
|
||||
cc.log("sub effects volume");
|
||||
audioEngine.setEffectsVolume(audioEngine.getEffectsVolume() - 0.1);
|
||||
};
|
||||
|
||||
var pauseEffect = function () {
|
||||
cc.log("pause effect");
|
||||
audioEngine.pauseEffect(soundId);
|
||||
};
|
||||
|
||||
var resumeEffect = function () {
|
||||
cc.log("resume effect");
|
||||
audioEngine.resumeEffect(soundId);
|
||||
};
|
||||
|
||||
var pauseAllEffects = function () {
|
||||
cc.log("pause all effects");
|
||||
audioEngine.pauseAllEffects();
|
||||
};
|
||||
var resumeAllEffects = function () {
|
||||
cc.log("resume all effects");
|
||||
audioEngine.resumeAllEffects();
|
||||
};
|
||||
var stopAllEffects = function () {
|
||||
cc.log("stop all effects");
|
||||
audioEngine.stopAllEffects();
|
||||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Main entry point
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
function run()
|
||||
{
|
||||
var scene = cc.Scene.create();
|
||||
var layer = new CocosDenshionTest();
|
||||
scene.addChild( layer );
|
||||
|
||||
var runningScene = director.getRunningScene();
|
||||
if( runningScene == null )
|
||||
director.runWithScene( scene );
|
||||
else
|
||||
director.replaceScene( cc.TransitionSplitCols.create(1, scene ) );
|
||||
}
|
||||
|
||||
run();
|
||||
|
|
@ -1,656 +0,0 @@
|
|||
//
|
||||
// http://www.cocos2d-iphone.org
|
||||
// http://www.cocos2d-html5.org
|
||||
// http://www.cocos2d-x.org
|
||||
//
|
||||
// Javascript + cocos2d actions tests
|
||||
//
|
||||
|
||||
require("js/helper.js");
|
||||
|
||||
director = cc.Director.getInstance();
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var TAG_ACTION1_EASE_ACTIONS = 1001;
|
||||
|
||||
var scenes = []
|
||||
var currentScene = 0;
|
||||
|
||||
var nextScene = function () {
|
||||
currentScene = currentScene + 1;
|
||||
if( currentScene >= scenes.length )
|
||||
currentScene = 0;
|
||||
|
||||
withTransition = true;
|
||||
loadScene(currentScene);
|
||||
};
|
||||
|
||||
var previousScene = function () {
|
||||
currentScene = currentScene -1;
|
||||
if( currentScene < 0 )
|
||||
currentScene = scenes.length -1;
|
||||
|
||||
withTransition = true;
|
||||
loadScene(currentScene);
|
||||
};
|
||||
|
||||
var restartScene = function () {
|
||||
loadScene( currentScene );
|
||||
};
|
||||
|
||||
var loadScene = function (sceneIdx)
|
||||
{
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var scene = new cc.Scene();
|
||||
scene.init();
|
||||
var layer = new scenes[ sceneIdx ]();
|
||||
|
||||
scene.addChild( layer );
|
||||
|
||||
// scene.walkSceneGraph(0);
|
||||
|
||||
director.replaceScene( scene );
|
||||
// __jsc__.garbageCollect();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Base Layer
|
||||
//
|
||||
|
||||
var BaseLayer = cc.LayerGradient.extend({
|
||||
|
||||
ctor:function () {
|
||||
|
||||
var parent = new cc.LayerGradient();
|
||||
__associateObjWithNative(this, parent);
|
||||
this.init(cc.c4b(0, 0, 0, 255), cc.c4b(0, 128, 255, 255));
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "No Title";
|
||||
},
|
||||
|
||||
subtitle:function () {
|
||||
return "";
|
||||
},
|
||||
|
||||
code:function () {
|
||||
return "";
|
||||
},
|
||||
|
||||
restartCallback:function (sender) {
|
||||
restartScene();
|
||||
},
|
||||
|
||||
nextCallback:function (sender) {
|
||||
nextScene();
|
||||
},
|
||||
|
||||
backCallback:function (sender) {
|
||||
previousScene();
|
||||
},
|
||||
|
||||
positionForTwo:function () {
|
||||
this._grossini.setPosition(cc.p(60, winSize.height*2/3));
|
||||
this._tamara.setPosition(cc.p(60, winSize.height*1/3));
|
||||
this._kathia.setVisible(false);
|
||||
},
|
||||
|
||||
onEnter:function () {
|
||||
// DO NOT CALL this._super()
|
||||
// this._super();
|
||||
|
||||
// add title and subtitle
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 28);
|
||||
this.addChild(label, 1);
|
||||
label.setPosition( cc.p(winSize.width / 2, winSize.height - 50));
|
||||
|
||||
var strSubtitle = this.subtitle();
|
||||
if (strSubtitle != "") {
|
||||
var l = cc.LabelTTF.create(strSubtitle, "Thonburi", 16);
|
||||
this.addChild(l, 1);
|
||||
l.setPosition( cc.p(winSize.width / 2, winSize.height - 80));
|
||||
}
|
||||
|
||||
var strCode = this.code();
|
||||
if( strCode !="" ) {
|
||||
var label = cc.LabelTTF.create(strCode, 'CourierNewPSMT', 16);
|
||||
label.setPosition( cc.p( winSize.width/2, winSize.height-100) );
|
||||
this.addChild( label,10 );
|
||||
|
||||
var labelbg = cc.LabelTTF.create(strCode, 'CourierNewPSMT', 16);
|
||||
labelbg.setColor( cc.c3b(10,10,255) );
|
||||
labelbg.setPosition( cc.p( winSize.width/2 +1, winSize.height-100 -1) );
|
||||
this.addChild( labelbg,9);
|
||||
}
|
||||
// Menu
|
||||
var item1 = cc.MenuItemImage.create("Images/b1.png", "Images/b2.png", this, this.backCallback);
|
||||
var item2 = cc.MenuItemImage.create("Images/r1.png", "Images/r2.png", this, this.restartCallback);
|
||||
var item3 = cc.MenuItemImage.create("Images/f1.png", "Images/f2.png", this, this.nextCallback);
|
||||
var item4 = cc.MenuItemFont.create("back", this, function() { require("js/main.js"); } );
|
||||
item4.setFontSize( 22 );
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3, item4 );
|
||||
|
||||
menu.setPosition( cc.p(0,0) );
|
||||
item1.setPosition( cc.p(winSize.width / 2 - 100, 30));
|
||||
item2.setPosition( cc.p(winSize.width / 2, 30));
|
||||
item3.setPosition( cc.p(winSize.width / 2 + 100, 30));
|
||||
item4.setPosition( cc.p(winSize.width - 60, winSize.height - 30 ) );
|
||||
|
||||
|
||||
this.addChild(menu, 1);
|
||||
|
||||
// Setup Sprites for this:w
|
||||
this._grossini = cc.Sprite.create("Images/grossini.png");
|
||||
this._tamara = cc.Sprite.create("Images/grossinis_sister1.png");
|
||||
this._kathia = cc.Sprite.create("Images/grossinis_sister2.png");
|
||||
this.addChild(this._grossini, 1);
|
||||
this.addChild(this._tamara, 2);
|
||||
this.addChild(this._kathia, 3);
|
||||
this._grossini.setPosition(cc.p(60, winSize.height*3/4));
|
||||
this._kathia.setPosition(cc.p(60, winSize.height*2/4));
|
||||
this._tamara.setPosition(cc.p(60, winSize.height*1/4));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteEase
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteEase = BaseLayer.extend({
|
||||
|
||||
elapsedTime: 0,
|
||||
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var move = cc.MoveBy.create(3, cc.p(winSize.width-80, 0));
|
||||
var move_back = move.reverse();
|
||||
|
||||
var move_ease_in = cc.EaseIn.create(move.copy(), 3.0);
|
||||
var move_ease_in_back = move_ease_in.reverse();
|
||||
|
||||
var move_ease_out = cc.EaseOut.create(move.copy(), 3.0);
|
||||
var move_ease_out_back = move_ease_out.reverse();
|
||||
|
||||
|
||||
var seq1 = cc.Sequence.create(move, move_back );
|
||||
var seq2 = cc.Sequence.create(move_ease_in, move_ease_in_back );
|
||||
var seq3 = cc.Sequence.create(move_ease_out, move_ease_out_back );
|
||||
|
||||
|
||||
var a2 = this._grossini.runAction(cc.RepeatForever.create(seq1));
|
||||
a2.setTag(1);
|
||||
|
||||
var a1 = this._tamara.runAction(cc.RepeatForever.create(seq2));
|
||||
a1.setTag(1);
|
||||
|
||||
var a = this._kathia.runAction(cc.RepeatForever.create(seq3));
|
||||
a.setTag(1);
|
||||
|
||||
this.scheduleUpdate();
|
||||
},
|
||||
title:function () {
|
||||
return "EaseIn - EaseOut - Stop";
|
||||
},
|
||||
|
||||
code:function () {
|
||||
return "var actionIn = cc.EaseIn.create( action, rate );\n" +
|
||||
"var actionOut = cc.EaseOut.create( action, rate );";
|
||||
},
|
||||
|
||||
testStopAction:function (dt) {
|
||||
elapsedTime += dt;
|
||||
|
||||
if( dt > 6 ) {
|
||||
this.unscheduleUpdate();
|
||||
this._tamara.stopActionByTag(1);
|
||||
this._kathia.stopActionByTag(1);
|
||||
this._grossini.stopActionByTag(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteEaseInOut
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteEaseInOut = BaseLayer.extend({
|
||||
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var move = cc.MoveBy.create(3, cc.p(winSize.width-80, 0));
|
||||
// id move_back = move.reverse();
|
||||
|
||||
var move_ease_inout1 = cc.EaseInOut.create(move.copy(), 2.0);
|
||||
var move_ease_inout_back1 = move_ease_inout1.reverse();
|
||||
|
||||
var move_ease_inout2 = cc.EaseInOut.create(move.copy(), 3.0);
|
||||
var move_ease_inout_back2 = move_ease_inout2.reverse();
|
||||
|
||||
var move_ease_inout3 = cc.EaseInOut.create(move.copy(), 4.0);
|
||||
var move_ease_inout_back3 = move_ease_inout3.reverse();
|
||||
|
||||
|
||||
var seq1 = cc.Sequence.create(move_ease_inout1, move_ease_inout_back1 );
|
||||
var seq2 = cc.Sequence.create(move_ease_inout2, move_ease_inout_back2 );
|
||||
var seq3 = cc.Sequence.create(move_ease_inout3, move_ease_inout_back3 );
|
||||
|
||||
this._tamara.runAction(cc.RepeatForever.create(seq1));
|
||||
this._kathia.runAction(cc.RepeatForever.create(seq2));
|
||||
this._grossini.runAction(cc.RepeatForever.create(seq3));
|
||||
},
|
||||
title:function () {
|
||||
return "EaseInOut and rates";
|
||||
},
|
||||
|
||||
code:function () {
|
||||
return "var actionInOut = cc.EaseInOut.create( action, rate );";
|
||||
},
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteEaseExponential
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteEaseExponential = BaseLayer.extend({
|
||||
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var move = cc.MoveBy.create(3, cc.p(winSize.width-80, 0));
|
||||
var move_back = move.reverse();
|
||||
|
||||
var move_ease_in = cc.EaseExponentialIn.create(move.copy());
|
||||
var move_ease_in_back = move_ease_in.reverse();
|
||||
|
||||
var move_ease_out = cc.EaseExponentialOut.create(move.copy());
|
||||
var move_ease_out_back = move_ease_out.reverse();
|
||||
|
||||
|
||||
var seq1 = cc.Sequence.create(move, move_back );
|
||||
var seq2 = cc.Sequence.create(move_ease_in, move_ease_in_back );
|
||||
var seq3 = cc.Sequence.create(move_ease_out, move_ease_out_back );
|
||||
|
||||
|
||||
this._grossini.runAction(cc.RepeatForever.create(seq1));
|
||||
this._tamara.runAction(cc.RepeatForever.create(seq2));
|
||||
this._kathia.runAction(cc.RepeatForever.create(seq3));
|
||||
},
|
||||
title:function () {
|
||||
return "ExpIn - ExpOut actions";
|
||||
},
|
||||
|
||||
code:function () {
|
||||
return "var actionIn = cc.EaseExponentialIn.create( action );\n" +
|
||||
"var actionOut = cc.EaseExponentialOut.create( action );";
|
||||
},
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteEaseExponentialInOut
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteEaseExponentialInOut = BaseLayer.extend({
|
||||
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var move = cc.MoveBy.create(3, cc.p(winSize.width-80, 0));
|
||||
var move_back = move.reverse();
|
||||
|
||||
var move_ease = cc.EaseExponentialInOut.create(move.copy());
|
||||
var move_ease_back = move_ease.reverse(); //-. reverse()
|
||||
|
||||
var seq1 = cc.Sequence.create(move, move_back );
|
||||
var seq2 = cc.Sequence.create(move_ease, move_ease_back );
|
||||
|
||||
this.positionForTwo();
|
||||
|
||||
this._grossini.runAction(cc.RepeatForever.create(seq1));
|
||||
this._tamara.runAction(cc.RepeatForever.create(seq2));
|
||||
},
|
||||
title:function () {
|
||||
return "EaseExponentialInOut action";
|
||||
},
|
||||
code:function () {
|
||||
return "var actionIn = cc.EaseExponentialInOut.create( action );";
|
||||
},
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteEaseSine
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteEaseSine = BaseLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var move = cc.MoveBy.create(3, cc.p(winSize.width-80, 0));
|
||||
var move_back = move.reverse();
|
||||
|
||||
var move_ease_in = cc.EaseSineIn.create(move.copy());
|
||||
var move_ease_in_back = move_ease_in.reverse();
|
||||
|
||||
var move_ease_out = cc.EaseSineOut.create(move.copy());
|
||||
var move_ease_out_back = move_ease_out.reverse();
|
||||
|
||||
|
||||
var seq1 = cc.Sequence.create(move, move_back );
|
||||
var seq2 = cc.Sequence.create(move_ease_in, move_ease_in_back );
|
||||
var seq3 = cc.Sequence.create(move_ease_out, move_ease_out_back );
|
||||
|
||||
|
||||
this._grossini.runAction(cc.RepeatForever.create(seq1));
|
||||
this._tamara.runAction(cc.RepeatForever.create(seq2));
|
||||
this._kathia.runAction(cc.RepeatForever.create(seq3));
|
||||
|
||||
},
|
||||
title:function () {
|
||||
return "EaseSineIn - EaseSineOut";
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteEaseSineInOut
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteEaseSineInOut = BaseLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var move = cc.MoveBy.create(3, cc.p(winSize.width-80, 0));
|
||||
var move_back = move.reverse();
|
||||
|
||||
var move_ease = cc.EaseSineInOut.create(move.copy());
|
||||
var move_ease_back = move_ease.reverse();
|
||||
|
||||
var seq1 = cc.Sequence.create(move, move_back );
|
||||
var seq2 = cc.Sequence.create(move_ease, move_ease_back );
|
||||
|
||||
this.positionForTwo();
|
||||
|
||||
this._grossini.runAction(cc.RepeatForever.create(seq1));
|
||||
this._tamara.runAction(cc.RepeatForever.create(seq2));
|
||||
},
|
||||
title:function () {
|
||||
return "EaseSineInOut action";
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteEaseElastic
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteEaseElastic = BaseLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var move = cc.MoveBy.create(3, cc.p(winSize.width-80, 0));
|
||||
var move_back = move.reverse();
|
||||
|
||||
var move_ease_in = cc.EaseElasticIn.create(move.copy());
|
||||
var move_ease_in_back = move_ease_in.reverse();
|
||||
|
||||
var move_ease_out = cc.EaseElasticOut.create(move.copy());
|
||||
var move_ease_out_back = move_ease_out.reverse();
|
||||
|
||||
var seq1 = cc.Sequence.create(move, move_back );
|
||||
var seq2 = cc.Sequence.create(move_ease_in, move_ease_in_back );
|
||||
var seq3 = cc.Sequence.create(move_ease_out, move_ease_out_back );
|
||||
|
||||
this._grossini.runAction(cc.RepeatForever.create(seq1));
|
||||
this._tamara.runAction(cc.RepeatForever.create(seq2));
|
||||
this._kathia.runAction(cc.RepeatForever.create(seq3));
|
||||
},
|
||||
title:function () {
|
||||
return "Elastic In - Out actions";
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteEaseElasticInOut
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteEaseElasticInOut = BaseLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var move = cc.MoveBy.create(3, cc.p(winSize.width-80, 0));
|
||||
|
||||
var move_ease_inout1 = cc.EaseElasticInOut.create(move.copy(), 0.3);
|
||||
var move_ease_inout_back1 = move_ease_inout1.reverse();
|
||||
|
||||
var move_ease_inout2 = cc.EaseElasticInOut.create(move.copy(), 0.45);
|
||||
var move_ease_inout_back2 = move_ease_inout2.reverse();
|
||||
|
||||
var move_ease_inout3 = cc.EaseElasticInOut.create(move.copy(), 0.6);
|
||||
var move_ease_inout_back3 = move_ease_inout3.reverse();
|
||||
|
||||
|
||||
var seq1 = cc.Sequence.create(move_ease_inout1, move_ease_inout_back1 );
|
||||
var seq2 = cc.Sequence.create(move_ease_inout2, move_ease_inout_back2 );
|
||||
var seq3 = cc.Sequence.create(move_ease_inout3, move_ease_inout_back3 );
|
||||
|
||||
this._tamara.runAction(cc.RepeatForever.create(seq1));
|
||||
this._kathia.runAction(cc.RepeatForever.create(seq2));
|
||||
this._grossini.runAction(cc.RepeatForever.create(seq3));
|
||||
},
|
||||
title:function () {
|
||||
return "EaseElasticInOut action";
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteEaseBounce
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteEaseBounce = BaseLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var move = cc.MoveBy.create(3, cc.p(winSize.width-80, 0));
|
||||
var move_back = move.reverse();
|
||||
|
||||
var move_ease_in = cc.EaseBounceIn.create(move.copy());
|
||||
var move_ease_in_back = move_ease_in.reverse();
|
||||
|
||||
var move_ease_out = cc.EaseBounceOut.create(move.copy());
|
||||
var move_ease_out_back = move_ease_out.reverse();
|
||||
|
||||
var seq1 = cc.Sequence.create(move, move_back );
|
||||
var seq2 = cc.Sequence.create(move_ease_in, move_ease_in_back );
|
||||
var seq3 = cc.Sequence.create(move_ease_out, move_ease_out_back );
|
||||
|
||||
this._grossini.runAction(cc.RepeatForever.create(seq1));
|
||||
this._tamara.runAction(cc.RepeatForever.create(seq2));
|
||||
this._kathia.runAction(cc.RepeatForever.create(seq3));
|
||||
},
|
||||
title:function () {
|
||||
return "Bounce In - Out actions";
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteEaseBounceInOut
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteEaseBounceInOut = BaseLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var move = cc.MoveBy.create(3, cc.p(winSize.width-80, 0));
|
||||
var move_back = move.reverse();
|
||||
|
||||
var move_ease = cc.EaseBounceInOut.create(move.copy());
|
||||
var move_ease_back = move_ease.reverse();
|
||||
|
||||
var seq1 = cc.Sequence.create(move, move_back );
|
||||
var seq2 = cc.Sequence.create(move_ease, move_ease_back );
|
||||
|
||||
this.positionForTwo();
|
||||
|
||||
this._grossini.runAction(cc.RepeatForever.create(seq1));
|
||||
this._tamara.runAction(cc.RepeatForever.create(seq2));
|
||||
},
|
||||
title:function () {
|
||||
return "EaseBounceInOut action";
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteEaseBack
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteEaseBack = BaseLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var move = cc.MoveBy.create(3, cc.p(winSize.width-80, 0));
|
||||
var move_back = move.reverse();
|
||||
|
||||
var move_ease_in = cc.EaseBackIn.create(move.copy());
|
||||
var move_ease_in_back = move_ease_in.reverse();
|
||||
|
||||
var move_ease_out = cc.EaseBackOut.create(move.copy());
|
||||
var move_ease_out_back = move_ease_out.reverse();
|
||||
|
||||
var seq1 = cc.Sequence.create(move, move_back );
|
||||
var seq2 = cc.Sequence.create(move_ease_in, move_ease_in_back );
|
||||
var seq3 = cc.Sequence.create(move_ease_out, move_ease_out_back );
|
||||
|
||||
this._grossini.runAction(cc.RepeatForever.create(seq1));
|
||||
this._tamara.runAction(cc.RepeatForever.create(seq2));
|
||||
this._kathia.runAction(cc.RepeatForever.create(seq3));
|
||||
},
|
||||
title:function () {
|
||||
return "Back In - Out actions";
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteEaseBackInOut
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteEaseBackInOut = BaseLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var move = cc.MoveBy.create(3, cc.p(winSize.width-80, 0));
|
||||
var move_back = move.reverse();
|
||||
|
||||
var move_ease = cc.EaseBackInOut.create(move.copy());
|
||||
var move_ease_back = move_ease.reverse();
|
||||
|
||||
var seq1 = cc.Sequence.create(move, move_back );
|
||||
var seq2 = cc.Sequence.create(move_ease, move_ease_back );
|
||||
|
||||
this.positionForTwo();
|
||||
|
||||
this._grossini.runAction(cc.RepeatForever.create(seq1));
|
||||
this._tamara.runAction(cc.RepeatForever.create(seq2));
|
||||
},
|
||||
title:function () {
|
||||
return "EaseBackInOut action";
|
||||
}
|
||||
});
|
||||
|
||||
var SpeedTest = BaseLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
// rotate and jump
|
||||
var jump1 = cc.JumpBy.create(4, cc.p(-400, 0), 100, 4);
|
||||
var jump2 = jump1.reverse();
|
||||
var rot1 = cc.RotateBy.create(4, 360 * 2);
|
||||
var rot2 = rot1.reverse();
|
||||
|
||||
var seq3_1 = cc.Sequence.create(jump2, jump1 );
|
||||
var seq3_2 = cc.Sequence.create(rot1, rot2 );
|
||||
var spawn = cc.Spawn.create(seq3_1, seq3_2 );
|
||||
var action = cc.Speed.create(cc.RepeatForever.create(spawn), 1.0);
|
||||
action.setTag(TAG_ACTION1_EASE_ACTIONS);
|
||||
|
||||
var action2 = action.copy();
|
||||
var action3 = action.copy();
|
||||
|
||||
action2.setTag(TAG_ACTION1_EASE_ACTIONS);
|
||||
action3.setTag(TAG_ACTION1_EASE_ACTIONS);
|
||||
|
||||
this._grossini.runAction(action2);
|
||||
this._tamara.runAction(action3);
|
||||
this._kathia.runAction(action);
|
||||
|
||||
this.schedule(this.altertime, 1.0);//:@selector(altertime:) interval:1.0];
|
||||
},
|
||||
title:function () {
|
||||
return "Speed action";
|
||||
},
|
||||
|
||||
altertime:function (dt) {
|
||||
var action1 = this._grossini.getActionByTag(TAG_ACTION1_EASE_ACTIONS);
|
||||
var action2 = this._tamara.getActionByTag(TAG_ACTION1_EASE_ACTIONS);
|
||||
var action3 = this._kathia.getActionByTag(TAG_ACTION1_EASE_ACTIONS);
|
||||
|
||||
action1.setSpeed(cc.RANDOM_0_1() * 2);
|
||||
action2.setSpeed(cc.RANDOM_0_1() * 2);
|
||||
action3.setSpeed(cc.RANDOM_0_1() * 2);
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// Order of tests
|
||||
//
|
||||
scenes.push( SpriteEase );
|
||||
scenes.push( SpriteEaseInOut );
|
||||
scenes.push( SpriteEaseExponential );
|
||||
scenes.push( SpriteEaseExponentialInOut );
|
||||
scenes.push( SpriteEaseSine );
|
||||
scenes.push( SpriteEaseSineInOut );
|
||||
scenes.push( SpriteEaseElastic );
|
||||
scenes.push( SpriteEaseElasticInOut );
|
||||
scenes.push( SpriteEaseBounce );
|
||||
scenes.push( SpriteEaseBounceInOut );
|
||||
scenes.push( SpriteEaseBack );
|
||||
scenes.push( SpriteEaseBackInOut );
|
||||
scenes.push( SpeedTest );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Main entry point
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
function run()
|
||||
{
|
||||
var scene = cc.Scene.create();
|
||||
var layer = new scenes[currentScene]();
|
||||
scene.addChild( layer );
|
||||
|
||||
var runningScene = director.getRunningScene();
|
||||
if( runningScene == null )
|
||||
director.runWithScene( scene );
|
||||
else
|
||||
director.replaceScene( cc.TransitionFade.create(0.5, scene ) );
|
||||
}
|
||||
|
||||
run();
|
||||
|
|
@ -1,266 +0,0 @@
|
|||
//
|
||||
// http://www.cocos2d-iphone.org
|
||||
// http://www.cocos2d-html5.org
|
||||
// http://www.cocos2d-x.org
|
||||
//
|
||||
// Javascript + cocos2d actions tests
|
||||
//
|
||||
|
||||
require("js/helper.js");
|
||||
|
||||
director = cc.Director.getInstance();
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
spriteFrameCache = cc.SpriteFrameCache.getInstance();
|
||||
|
||||
var scenes = [];
|
||||
var currentScene = 0;
|
||||
|
||||
var nextScene = function () {
|
||||
currentScene = currentScene + 1;
|
||||
if( currentScene >= scenes.length )
|
||||
currentScene = 0;
|
||||
|
||||
withTransition = true;
|
||||
loadScene(currentScene);
|
||||
};
|
||||
|
||||
var previousScene = function () {
|
||||
currentScene = currentScene -1;
|
||||
if( currentScene < 0 )
|
||||
currentScene = scenes.length -1;
|
||||
|
||||
withTransition = true;
|
||||
loadScene(currentScene);
|
||||
};
|
||||
|
||||
var restartScene = function () {
|
||||
loadScene( currentScene );
|
||||
};
|
||||
|
||||
var loadScene = function (sceneIdx)
|
||||
{
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var scene = new cc.Scene();
|
||||
scene.init();
|
||||
var layer = new scenes[ sceneIdx ]();
|
||||
|
||||
scene.addChild( layer );
|
||||
|
||||
// scene.walkSceneGraph(0);
|
||||
|
||||
director.replaceScene( scene );
|
||||
// __jsc__.garbageCollect();
|
||||
}
|
||||
|
||||
var s_pathSister1 = "Images/grossinis_sister1.png";
|
||||
var s_pathSister2 = "Images/grossinis_sister2.png";
|
||||
var s_pathBlock = "Images/blocks.png";
|
||||
var s_grossiniPlist = "animations/grossini.plist";
|
||||
|
||||
//
|
||||
// Base Layer
|
||||
//
|
||||
|
||||
var BaseLayer = cc.LayerGradient.extend({
|
||||
|
||||
ctor:function () {
|
||||
|
||||
var parent = new cc.LayerGradient();
|
||||
__associateObjWithNative(this, parent);
|
||||
this.init(cc.c4b(0, 0, 0, 255), cc.c4b(0, 128, 255, 255));
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "Effects Test";
|
||||
},
|
||||
|
||||
subtitle:function () {
|
||||
return "";
|
||||
},
|
||||
|
||||
code:function () {
|
||||
return "";
|
||||
},
|
||||
|
||||
restartCallback:function (sender) {
|
||||
restartScene();
|
||||
},
|
||||
|
||||
nextCallback:function (sender) {
|
||||
nextScene();
|
||||
},
|
||||
|
||||
backCallback:function (sender) {
|
||||
previousScene();
|
||||
},
|
||||
|
||||
onEnter:function () {
|
||||
// DO NOT CALL this._super()
|
||||
// this._super();
|
||||
|
||||
// add title and subtitle
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 28);
|
||||
this.addChild(label, 10);
|
||||
label.setPosition( cc.p(winSize.width / 2, winSize.height - 40));
|
||||
|
||||
var strSubtitle = this.subtitle();
|
||||
if (strSubtitle != "") {
|
||||
var l = cc.LabelTTF.create(strSubtitle, "Thonburi", 16);
|
||||
this.addChild(l, 10);
|
||||
l.setPosition( cc.p(winSize.width / 2, winSize.height - 70));
|
||||
}
|
||||
|
||||
var strCode = this.code();
|
||||
if( strCode !="" ) {
|
||||
var label = cc.LabelTTF.create(strCode, 'CourierNewPSMT', 16);
|
||||
label.setPosition( cc.p( winSize.width/2, winSize.height-120) );
|
||||
this.addChild( label,10 );
|
||||
|
||||
var labelbg = cc.LabelTTF.create(strCode, 'CourierNewPSMT', 16);
|
||||
labelbg.setColor( cc.c3b(10,10,255) );
|
||||
labelbg.setPosition( cc.p( winSize.width/2 +1, winSize.height-120 -1) );
|
||||
this.addChild( labelbg,9);
|
||||
}
|
||||
|
||||
// Menu
|
||||
var item1 = cc.MenuItemImage.create("Images/b1.png", "Images/b2.png", this, this.backCallback);
|
||||
var item2 = cc.MenuItemImage.create("Images/r1.png", "Images/r2.png", this, this.restartCallback);
|
||||
var item3 = cc.MenuItemImage.create("Images/f1.png", "Images/f2.png", this, this.nextCallback);
|
||||
var item4 = cc.MenuItemFont.create("back", this, function() { require("js/main.js"); } );
|
||||
item4.setFontSize( 22 );
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3, item4 );
|
||||
|
||||
menu.setPosition( cc.p(0,0) );
|
||||
item1.setPosition( cc.p(winSize.width / 2 - 100, 30));
|
||||
item2.setPosition( cc.p(winSize.width / 2, 30));
|
||||
item3.setPosition( cc.p(winSize.width / 2 + 100, 30));
|
||||
item4.setPosition( cc.p(winSize.width - 60, winSize.height - 30 ) );
|
||||
|
||||
this.addChild(menu, 10);
|
||||
|
||||
|
||||
// Specific to Effects
|
||||
|
||||
var node = cc.Node.create();
|
||||
node.runAction( this.getEffect(3) );
|
||||
this.addChild( node );
|
||||
|
||||
var bg = cc.Sprite.create("Images/background3.png");
|
||||
bg.setPosition( cc._p( winSize.width/2, winSize.height/2) );
|
||||
node.addChild( bg );
|
||||
|
||||
var sister1 = cc.Sprite.create("Images/grossinis_sister1.png");
|
||||
sister1.setPosition( cc._p( winSize.width/3, winSize.height/2 ) );
|
||||
node.addChild( sister1, 1 );
|
||||
|
||||
var sister2 = cc.Sprite.create("Images/grossinis_sister2.png");
|
||||
sister2.setPosition( cc._p( winSize.width*2/3, winSize.height/2 ) );
|
||||
node.addChild( sister2, 1 );
|
||||
|
||||
var sc = cc.ScaleBy.create(2, 5);
|
||||
var sc_back = sc.reverse();
|
||||
var seq = cc.Sequence.create( sc, sc_back );
|
||||
var repeat = cc.RepeatForever.create( seq );
|
||||
|
||||
sister1.runAction( repeat );
|
||||
sister2.runAction( repeat.copy() );
|
||||
},
|
||||
|
||||
getEffect:function(duration) {
|
||||
// override me
|
||||
return cc.MoveBy.create(2, cc._p(10,10) );
|
||||
},
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Tests
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var Shaky3DTest = BaseLayer.extend({
|
||||
subtitle:function () {
|
||||
return "Shaky 3D";
|
||||
},
|
||||
code:function () {
|
||||
return "a = cc.Shaky3D.create(range, shakeZ, gridSize, duration )";
|
||||
},
|
||||
getEffect:function(duration) {
|
||||
return cc.Shaky3D.create(5, false, cc.g(15,10), duration );
|
||||
},
|
||||
});
|
||||
|
||||
var Waves3DTest = BaseLayer.extend({
|
||||
subtitle:function () {
|
||||
return "Waves 3D";
|
||||
},
|
||||
code:function () {
|
||||
return "a = cc.Waves3D.create(range, shakeZ, gridSize, duration )";
|
||||
},
|
||||
getEffect:function(duration) {
|
||||
return cc.Waves3D.create(5, 40, cc.g(15,10), duration );
|
||||
},
|
||||
});
|
||||
|
||||
var FlipXTest = BaseLayer.extend({
|
||||
subtitle:function () {
|
||||
return "FlipX3D";
|
||||
},
|
||||
code:function () {
|
||||
return "a = cc.FlipX3D.create(duration )";
|
||||
},
|
||||
getEffect:function(duration) {
|
||||
var a = cc.FlipX3D.create(duration );
|
||||
var delay = cc.DelayTime.create(2);
|
||||
var r = a.reverse();
|
||||
return cc.Sequence.create( a, delay, r );
|
||||
},
|
||||
});
|
||||
|
||||
var FlipYTest = BaseLayer.extend({
|
||||
subtitle:function () {
|
||||
return "FlipY3D";
|
||||
},
|
||||
code:function () {
|
||||
return "a = cc.FlipY3D.create(duration )";
|
||||
},
|
||||
getEffect:function(duration) {
|
||||
var a = cc.FlipY3D.create(duration );
|
||||
var delay = cc.DelayTime.create(2);
|
||||
var r = a.reverse();
|
||||
return cc.Sequence.create( a, delay, r );
|
||||
},
|
||||
});
|
||||
|
||||
//
|
||||
// Order of tests
|
||||
//
|
||||
scenes.push( Shaky3DTest );
|
||||
scenes.push( Waves3DTest );
|
||||
scenes.push( FlipXTest );
|
||||
scenes.push( FlipYTest );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Main entry point
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
function run()
|
||||
{
|
||||
var scene = cc.Scene.create();
|
||||
var layer = new scenes[currentScene]();
|
||||
scene.addChild( layer );
|
||||
|
||||
var runningScene = director.getRunningScene();
|
||||
if( runningScene == null )
|
||||
director.runWithScene( scene );
|
||||
else
|
||||
director.replaceScene( cc.TransitionFade.create(0.5, scene ) );
|
||||
}
|
||||
|
||||
run();
|
||||
|
||||
|
|
@ -1,245 +0,0 @@
|
|||
//
|
||||
// http://www.cocos2d-iphone.org
|
||||
//
|
||||
// Javascript + cocos2d label tests
|
||||
//
|
||||
|
||||
require("js/helper.js");
|
||||
|
||||
director = cc.Director.getInstance();
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var scenes = []
|
||||
var currentScene = 0;
|
||||
|
||||
var nextSpriteTestAction = function () {
|
||||
currentScene = currentScene + 1;
|
||||
if( currentScene >= scenes.length )
|
||||
currentScene = 0;
|
||||
|
||||
loadScene(currentScene);
|
||||
};
|
||||
var backSpriteTestAction = function () {
|
||||
currentScene = currentScene -1;
|
||||
if( currentScene < 0 )
|
||||
currentScene = scenes.length -1;
|
||||
|
||||
loadScene(currentScene);
|
||||
};
|
||||
var restartSpriteTestAction = function () {
|
||||
loadScene( currentScene );
|
||||
};
|
||||
|
||||
var loadScene = function (sceneIdx)
|
||||
{
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var scene = new cc.Scene();
|
||||
scene.init();
|
||||
var layer = new scenes[ sceneIdx ]();
|
||||
|
||||
scene.addChild( layer );
|
||||
|
||||
// scene.walkSceneGraph(0);
|
||||
|
||||
director.replaceScene( scene );
|
||||
// __jsc__.garbageCollect();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// BaseLayer
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var BaseLayer = function() {
|
||||
|
||||
//
|
||||
// VERY IMPORTANT
|
||||
//
|
||||
// Only subclasses of a native classes MUST call __associateObjectWithNative
|
||||
// Failure to do so, it will crash.
|
||||
//
|
||||
var parent = goog.base(this);
|
||||
__associateObjWithNative( this, parent );
|
||||
this.init();
|
||||
|
||||
this.title = function () {
|
||||
return "No title";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "No Subtitle";
|
||||
}
|
||||
|
||||
}
|
||||
goog.inherits(BaseLayer, cc.Layer );
|
||||
|
||||
//
|
||||
// Instance 'base' methods
|
||||
// XXX: Should be defined after "goog.inherits"
|
||||
//
|
||||
BaseLayer.prototype.onEnter = function() {
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 28);
|
||||
this.addChild(label, 1);
|
||||
label.setPosition( cc.p(winSize.width / 2, winSize.height - 50));
|
||||
|
||||
var strSubtitle = this.subtitle();
|
||||
if (strSubtitle != "") {
|
||||
var l = cc.LabelTTF.create(strSubtitle, "Thonburi", 16);
|
||||
this.addChild(l, 1);
|
||||
l.setPosition( cc.p(winSize.width / 2, winSize.height - 80));
|
||||
}
|
||||
|
||||
// Menu
|
||||
var item1 = cc.MenuItemImage.create("Images/b1.png", "Images/b2.png", this, this.backCallback);
|
||||
var item2 = cc.MenuItemImage.create("Images/r1.png", "Images/r2.png", this, this.restartCallback);
|
||||
var item3 = cc.MenuItemImage.create("Images/f1.png", "Images/f2.png", this, this.nextCallback);
|
||||
var item4 = cc.MenuItemFont.create("back", this, function() { require("js/main.js"); } );
|
||||
cc.MenuItemFont.setFontSize( 22 );
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3, item4 );
|
||||
|
||||
menu.setPosition( cc.p(0,0) );
|
||||
item1.setPosition( cc.p(winSize.width / 2 - 100, 30));
|
||||
item2.setPosition( cc.p(winSize.width / 2, 30));
|
||||
item3.setPosition( cc.p(winSize.width / 2 + 100, 30));
|
||||
item4.setPosition( cc.p(winSize.width - 60, winSize.height - 30 ) );
|
||||
|
||||
this.addChild(menu, 1);
|
||||
}
|
||||
|
||||
BaseLayer.prototype.restartCallback = function (sender) {
|
||||
cc.log("restart called");
|
||||
restartSpriteTestAction();
|
||||
}
|
||||
|
||||
BaseLayer.prototype.nextCallback = function (sender) {
|
||||
cc.log("next called");
|
||||
nextSpriteTestAction();
|
||||
}
|
||||
|
||||
BaseLayer.prototype.backCallback = function (sender) {
|
||||
cc.log("back called");
|
||||
backSpriteTestAction();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Label Atlas Test
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var LabelAtlasTest = function(file) {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.initialize = function() {
|
||||
|
||||
this.label1 = cc.LabelAtlas.create("123 Test", "Fonts/tuffy_bold_italic-charmap.plist");
|
||||
this.addChild( this.label1 );
|
||||
this.label1.setPosition( cc.p(10,100) );
|
||||
this.label1.setOpacity( 200 );
|
||||
|
||||
this.label2 = cc.LabelAtlas.create( "0123456789", "Fonts/tuffy_bold_italic-charmap.plist" );
|
||||
this.addChild( this.label2 );
|
||||
this.label2.setPosition( cc.p(10,200) );
|
||||
this.label2.setOpacity( 32 );
|
||||
|
||||
this.scheduleUpdate();
|
||||
|
||||
|
||||
this.time = 0;
|
||||
}
|
||||
|
||||
this.title = function () {
|
||||
return "LabelAtlas";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "Updating label should be fast";
|
||||
}
|
||||
|
||||
this.update = function( delta ) {
|
||||
this.time += delta;
|
||||
var num = this.time.toFixed(2);
|
||||
var string = '' + num + ' test'
|
||||
this.label1.setString( string );
|
||||
|
||||
string = '' + Math.floor( this.time);
|
||||
this.label2.setString( string );
|
||||
}
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
goog.inherits(LabelAtlasTest, BaseLayer );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// BMFontColorTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var BMFontColorTest = function(file) {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.initialize = function() {
|
||||
|
||||
var label = cc.LabelBMFont.create("Blue", "Fonts/bitmapFontTest5.fnt");
|
||||
this.addChild( label );
|
||||
label.setColor( cc.c3b(0,0,255) );
|
||||
label.setPosition( cc.p( winSize.width/2, 1*winSize.height/4) );
|
||||
label.setAnchorPoint( cc.p(0.5, 0.5) );
|
||||
|
||||
label = cc.LabelBMFont.create("Red", "Fonts/bitmapFontTest5.fnt");
|
||||
this.addChild( label );
|
||||
label.setColor( cc.c3b(255,0,0) );
|
||||
label.setPosition( cc.p( winSize.width/2, 2*winSize.height/4) );
|
||||
label.setAnchorPoint( cc.p(0.5, 0.5) );
|
||||
|
||||
label = cc.LabelBMFont.create("Red", "Fonts/bitmapFontTest5.fnt");
|
||||
this.addChild( label );
|
||||
label.setColor( cc.c3b(0,255,0) );
|
||||
label.setPosition( cc.p( winSize.width/2, 3*winSize.height/4) );
|
||||
label.setAnchorPoint( cc.p(0.5, 0.5) );
|
||||
}
|
||||
|
||||
this.title = function () {
|
||||
return "LabelBMFont";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "Testing color";
|
||||
}
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
goog.inherits(BMFontColorTest, BaseLayer );
|
||||
|
||||
|
||||
//
|
||||
// Order of tests
|
||||
//
|
||||
scenes.push( LabelAtlasTest );
|
||||
scenes.push( BMFontColorTest );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Main entry point
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
function run()
|
||||
{
|
||||
var scene = cc.Scene.create();
|
||||
var layer = new scenes[currentScene]();
|
||||
scene.addChild( layer );
|
||||
|
||||
var runningScene = director.getRunningScene();
|
||||
if( runningScene == null )
|
||||
director.runWithScene( scene );
|
||||
else
|
||||
director.replaceScene( cc.TransitionFade.create(0.5, scene ) );
|
||||
}
|
||||
|
||||
run();
|
||||
|
|
@ -1,510 +0,0 @@
|
|||
//
|
||||
// http://www.cocos2d-iphone.org
|
||||
// http://www.cocos2d-html5.org
|
||||
// http://www.cocos2d-x.org
|
||||
//
|
||||
// Javascript + cocos2d actions tests
|
||||
//
|
||||
|
||||
require("js/helper.js");
|
||||
|
||||
director = cc.Director.getInstance();
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var scenes = []
|
||||
var currentScene = 0;
|
||||
|
||||
var nextScene = function () {
|
||||
currentScene = currentScene + 1;
|
||||
if( currentScene >= scenes.length )
|
||||
currentScene = 0;
|
||||
|
||||
withTransition = true;
|
||||
loadScene(currentScene);
|
||||
};
|
||||
|
||||
var previousScene = function () {
|
||||
currentScene = currentScene -1;
|
||||
if( currentScene < 0 )
|
||||
currentScene = scenes.length -1;
|
||||
|
||||
withTransition = true;
|
||||
loadScene(currentScene);
|
||||
};
|
||||
|
||||
var restartScene = function () {
|
||||
loadScene( currentScene );
|
||||
};
|
||||
|
||||
var loadScene = function (sceneIdx)
|
||||
{
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var scene = new cc.Scene();
|
||||
scene.init();
|
||||
var layer = new scenes[ sceneIdx ]();
|
||||
|
||||
scene.addChild( layer );
|
||||
|
||||
// scene.walkSceneGraph(0);
|
||||
|
||||
director.replaceScene( scene );
|
||||
// __jsc__.garbageCollect();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Base Layer
|
||||
//
|
||||
|
||||
var BaseLayer = cc.LayerGradient.extend({
|
||||
|
||||
ctor:function () {
|
||||
|
||||
var parent = new cc.LayerGradient();
|
||||
__associateObjWithNative(this, parent);
|
||||
this.init(cc.c4b(0, 0, 0, 255), cc.c4b(0, 128, 255, 255));
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "No Title";
|
||||
},
|
||||
|
||||
subtitle:function () {
|
||||
return "";
|
||||
},
|
||||
|
||||
code:function () {
|
||||
return "";
|
||||
},
|
||||
|
||||
restartCallback:function (sender) {
|
||||
restartScene();
|
||||
},
|
||||
|
||||
nextCallback:function (sender) {
|
||||
nextScene();
|
||||
},
|
||||
|
||||
backCallback:function (sender) {
|
||||
previousScene();
|
||||
},
|
||||
|
||||
onEnter:function () {
|
||||
// DO NOT CALL this._super()
|
||||
// this._super();
|
||||
|
||||
// add title and subtitle
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 28);
|
||||
this.addChild(label, 1);
|
||||
label.setPosition( cc.p(winSize.width / 2, winSize.height - 40));
|
||||
|
||||
var strSubtitle = this.subtitle();
|
||||
if (strSubtitle != "") {
|
||||
var l = cc.LabelTTF.create(strSubtitle, "Thonburi", 16);
|
||||
this.addChild(l, 1);
|
||||
l.setPosition( cc.p(winSize.width / 2, winSize.height - 70));
|
||||
}
|
||||
|
||||
var strCode = this.code();
|
||||
if( strCode !="" ) {
|
||||
var label = cc.LabelTTF.create(strCode, 'CourierNewPSMT', 16);
|
||||
label.setPosition( cc.p( winSize.width/2, winSize.height-120) );
|
||||
this.addChild( label,10 );
|
||||
|
||||
var labelbg = cc.LabelTTF.create(strCode, 'CourierNewPSMT', 16);
|
||||
labelbg.setColor( cc.c3b(10,10,255) );
|
||||
labelbg.setPosition( cc.p( winSize.width/2 +1, winSize.height-120 -1) );
|
||||
this.addChild( labelbg,9);
|
||||
}
|
||||
|
||||
// Menu
|
||||
var item1 = cc.MenuItemImage.create("Images/b1.png", "Images/b2.png", this, this.backCallback);
|
||||
var item2 = cc.MenuItemImage.create("Images/r1.png", "Images/r2.png", this, this.restartCallback);
|
||||
var item3 = cc.MenuItemImage.create("Images/f1.png", "Images/f2.png", this, this.nextCallback);
|
||||
var item4 = cc.MenuItemFont.create("back", this, function() { require("js/main.js"); } );
|
||||
item4.setFontSize( 22 );
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3, item4 );
|
||||
|
||||
menu.setPosition( cc.p(0,0) );
|
||||
item1.setPosition( cc.p(winSize.width / 2 - 100, 30));
|
||||
item2.setPosition( cc.p(winSize.width / 2, 30));
|
||||
item3.setPosition( cc.p(winSize.width / 2 + 100, 30));
|
||||
item4.setPosition( cc.p(winSize.width - 60, winSize.height - 30 ) );
|
||||
|
||||
this.addChild(menu, 1);
|
||||
|
||||
|
||||
// back menu
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// MenuItemFontTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var MenuItemFontTest = BaseLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var item1 = cc.MenuItemFont.create("Item 1. Should be RED");
|
||||
var item2 = cc.MenuItemFont.create("This item is bigger", this, this.item_cb);
|
||||
var item3 = cc.MenuItemFont.create("This item should be disabled", this, this.item_cb);
|
||||
|
||||
// callback function can be modified in runtime
|
||||
item1.setCallback( this, this.item_cb );
|
||||
|
||||
// font color can be changed in runtime
|
||||
item1.setColor( cc.c3b(255,0,0) );
|
||||
|
||||
// font size can be changed in runtime (it is faster to do it before creating the item)
|
||||
item2.setFontSize( 48 );
|
||||
|
||||
// font name can be changed in runtime (it is faster to do it before creating the item)
|
||||
item3.setFontName( "Courier New");
|
||||
|
||||
// item could be enabled / disabled in runtime
|
||||
item3.setEnabled( false );
|
||||
|
||||
var menu = cc.Menu.create( item1, item2, item3 );
|
||||
menu.alignItemsVertically();
|
||||
|
||||
menu.setPosition( cc.p( winSize.width/2, winSize.height/2) );
|
||||
|
||||
this.addChild( menu );
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "Menu Item Font";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "3 items. 3rd should be disabled. Smaller font";
|
||||
},
|
||||
code:function () {
|
||||
return "item = cc.MenuItemFont.create('Press me', this, this.callback)";
|
||||
},
|
||||
|
||||
// callback
|
||||
item_cb:function(sender) {
|
||||
cc.log("Item " + sender + " pressed");
|
||||
},
|
||||
|
||||
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// MenuItemImage
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var MenuItemImageTest = BaseLayer.extend({
|
||||
|
||||
_vertically : true,
|
||||
|
||||
_menu : null,
|
||||
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var item1 = cc.MenuItemImage.create("Images/btn-play-normal.png", "Images/btn-play-selected.png" );
|
||||
var item2 = cc.MenuItemImage.create("Images/btn-highscores-normal.png", "Images/btn-highscores-selected.png", this, this.item_cb );
|
||||
var item3 = cc.MenuItemImage.create("Images/btn-about-normal.png", "Images/btn-about-selected.png", this, this.item_cb );
|
||||
|
||||
// callback function can be modified in runtime
|
||||
item1.setCallback( this, this.item_cb );
|
||||
|
||||
// item could be enabled / disabled in runtime
|
||||
item3.setEnabled( false );
|
||||
|
||||
this._menu = cc.Menu.create( item1, item2, item3 );
|
||||
this._menu.alignItemsVertically();
|
||||
|
||||
this._menu.setPosition( cc.p( winSize.width/2, winSize.height/2) );
|
||||
|
||||
this.addChild( this._menu );
|
||||
},
|
||||
|
||||
|
||||
title:function () {
|
||||
return "Menu Item Image";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "3 items. 3rd should be disabled.";
|
||||
},
|
||||
code:function () {
|
||||
return "item = cc.MenuItemImage.create('Images/normal.png', 'Images/selected.png' , 'Images/disabled.png', this, this.cb )";
|
||||
},
|
||||
|
||||
// callback
|
||||
item_cb:function(sender) {
|
||||
cc.log("Item " + sender + " pressed");
|
||||
if( this._vertically )
|
||||
this._menu.alignItemsHorizontally();
|
||||
else
|
||||
this._menu.alignItemsVertically();
|
||||
|
||||
this._vertically = ! this._vertically;
|
||||
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// MenuItemSpriteTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var MenuItemSpriteTest = BaseLayer.extend({
|
||||
|
||||
_vertically : true,
|
||||
_menu : null,
|
||||
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
// Sprites can't be reused since they are children of MenuItem
|
||||
// If you want to reuse them, use "MenuItemImage" instead
|
||||
var sprite1_1 = cc.Sprite.create("Images/menuitemsprite.png", cc.rect(0, 23*2, 115, 23) );
|
||||
var sprite2_1 = cc.Sprite.create("Images/menuitemsprite.png", cc.rect(0, 23*1, 115, 23) );
|
||||
var sprite1_2 = cc.Sprite.create("Images/menuitemsprite.png", cc.rect(0, 23*2, 115, 23) );
|
||||
var sprite2_2 = cc.Sprite.create("Images/menuitemsprite.png", cc.rect(0, 23*1, 115, 23) );
|
||||
var sprite3_2 = cc.Sprite.create("Images/menuitemsprite.png", cc.rect(0, 23*0, 115, 23) );
|
||||
var sprite1_3 = cc.Sprite.create("Images/menuitemsprite.png", cc.rect(0, 23*2, 115, 23) );
|
||||
var sprite2_3 = cc.Sprite.create("Images/menuitemsprite.png", cc.rect(0, 23*1, 115, 23) );
|
||||
var sprite3_3 = cc.Sprite.create("Images/menuitemsprite.png", cc.rect(0, 23*0, 115, 23) );
|
||||
|
||||
var item1 = cc.MenuItemSprite.create(sprite1_1, sprite2_1);
|
||||
var item2 = cc.MenuItemSprite.create(sprite1_2, sprite2_2, sprite3_2, this, this.item_cb);
|
||||
var item3 = cc.MenuItemSprite.create(sprite1_3, sprite2_3, sprite3_3, this, this.item_cb);
|
||||
|
||||
// callback function can be modified in runtime
|
||||
item1.setCallback( this, this.item_cb );
|
||||
|
||||
// item could be enabled / disabled in runtime
|
||||
item3.setEnabled( false );
|
||||
|
||||
this._menu = cc.Menu.create( item1, item2, item3 );
|
||||
this._menu.alignItemsVertically();
|
||||
|
||||
this._menu.setPosition( cc.p( winSize.width/2, winSize.height/2) );
|
||||
|
||||
this.addChild( this._menu );
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "Menu Item Sprite";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "3 items. 3rd should be disabled.";
|
||||
},
|
||||
code:function () {
|
||||
return "item = cc.MenuItemSprite.create(spr_normal, spr_selected, spr_disabled, this, this.cb )";
|
||||
},
|
||||
|
||||
// callback
|
||||
item_cb:function(sender) {
|
||||
cc.log("Item " + sender + " pressed");
|
||||
if( this._vertically )
|
||||
this._menu.alignItemsHorizontally();
|
||||
else
|
||||
this._menu.alignItemsVertically();
|
||||
|
||||
this._vertically = ! this._vertically;
|
||||
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// MenuItemLabelTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var MenuItemLabelTest = BaseLayer.extend({
|
||||
|
||||
_vertically : true,
|
||||
_menu : null,
|
||||
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var label1 = cc.LabelTTF.create("This is a LabelTTF item", "Arial", 24 );
|
||||
var label2 = cc.LabelBMFont.create("And this is a LabelBMFont item", "Fonts/futura-48.fnt" );
|
||||
var label3 = cc.LabelTTF.create("Disabled Item", "Arial", 24 );
|
||||
|
||||
var item1 = cc.MenuItemLabel.create(label1);
|
||||
var item2 = cc.MenuItemLabel.create(label2, this, this.item_cb);
|
||||
var item3 = cc.MenuItemLabel.create(label3, this, this.item_cb);
|
||||
|
||||
// callback function can be modified in runtime
|
||||
item1.setCallback( this, this.item_cb );
|
||||
|
||||
// item could be enabled / disabled in runtime
|
||||
item3.setEnabled( false );
|
||||
|
||||
this._menu = cc.Menu.create( item1, item2, item3 );
|
||||
this._menu.alignItemsVertically();
|
||||
|
||||
this._menu.setPosition( cc.p( winSize.width/2, winSize.height/2) );
|
||||
|
||||
this.addChild( this._menu );
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "Menu Item Label";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "3 items. 3rd should be disabled.";
|
||||
},
|
||||
code:function () {
|
||||
return "item = cc.MenuItemLabel.create(label, this, this.cb )";
|
||||
},
|
||||
|
||||
// callback
|
||||
item_cb:function(sender) {
|
||||
cc.log("Item " + sender + " pressed");
|
||||
if( this._vertically )
|
||||
this._menu.alignItemsHorizontally();
|
||||
else
|
||||
this._menu.alignItemsVertically();
|
||||
|
||||
this._vertically = ! this._vertically;
|
||||
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// MenuItemToggleTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var MenuItemToggleTest = BaseLayer.extend({
|
||||
|
||||
_vertically : true,
|
||||
_menu : null,
|
||||
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var label1 = cc.LabelBMFont.create("Volume Off", "Fonts/futura-48.fnt" );
|
||||
var item1 = cc.MenuItemLabel.create(label1);
|
||||
var label2 = cc.LabelBMFont.create("Volume On", "Fonts/futura-48.fnt" );
|
||||
var item2 = cc.MenuItemLabel.create(label2);
|
||||
|
||||
var itema = cc.MenuItemFont.create("Sound Off");
|
||||
var itemb = cc.MenuItemFont.create("Sound 50%");
|
||||
var itemc = cc.MenuItemFont.create("Sound 100%");
|
||||
|
||||
var toggle1 = cc.MenuItemToggle.create( item1, item2 );
|
||||
var toggle2 = cc.MenuItemToggle.create( itema, itemb, itemc );
|
||||
|
||||
toggle1.setCallback( this, this.item_cb);
|
||||
toggle2.setCallback( this, this.item_cb);
|
||||
|
||||
this._menu = cc.Menu.create( toggle1, toggle2 );
|
||||
this._menu.alignItemsVertically();
|
||||
this._menu.setPosition( cc.p( winSize.width/2, winSize.height/2) );
|
||||
|
||||
this.addChild( this._menu );
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "Menu Item Toggle";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "2 Toggle Items";
|
||||
},
|
||||
code:function () {
|
||||
return "item = cc.MenuItemToggle.create( item1, item2, item3 );";
|
||||
},
|
||||
|
||||
// callback
|
||||
item_cb:function(sender) {
|
||||
cc.log("toggle pressed");
|
||||
},
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// MenuItemSubclass
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
|
||||
var MyMenuItemFont = cc.MenuItemFont.extend({
|
||||
|
||||
ctor:function( label ) {
|
||||
var parent = new cc.MenuItemFont();
|
||||
__associateObjWithNative(this, parent);
|
||||
this.init( label, this, this.callback );
|
||||
},
|
||||
|
||||
callback:function(sender) {
|
||||
cc.log("Button clicked");
|
||||
},
|
||||
});
|
||||
|
||||
var MenuItemSubclass = BaseLayer.extend({
|
||||
|
||||
_vertically : true,
|
||||
_menu : null,
|
||||
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var item1 = new MyMenuItemFont("Item 1");
|
||||
var item2 = new MyMenuItemFont("Item 2");
|
||||
|
||||
this._menu = cc.Menu.create( item1, item2 );
|
||||
this._menu.alignItemsVertically();
|
||||
this._menu.setPosition( cc.p( winSize.width/2, winSize.height/2) );
|
||||
|
||||
this.addChild( this._menu );
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "Menu Item Subclass";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "2 items should appear";
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
//
|
||||
// Order of tests
|
||||
//
|
||||
|
||||
scenes.push( MenuItemFontTest );
|
||||
scenes.push( MenuItemImageTest );
|
||||
scenes.push( MenuItemSpriteTest );
|
||||
scenes.push( MenuItemLabelTest );
|
||||
scenes.push( MenuItemToggleTest );
|
||||
scenes.push( MenuItemSubclass );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Main entry point
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
function run()
|
||||
{
|
||||
var scene = cc.Scene.create();
|
||||
var layer = new scenes[currentScene]();
|
||||
scene.addChild( layer );
|
||||
|
||||
var runningScene = director.getRunningScene();
|
||||
if( runningScene == null )
|
||||
director.runWithScene( scene );
|
||||
else
|
||||
director.replaceScene( cc.TransitionFade.create(0.5, scene ) );
|
||||
}
|
||||
|
||||
run();
|
||||
|
|
@ -1,322 +0,0 @@
|
|||
//
|
||||
// http://www.cocos2d-iphone.org
|
||||
// http://www.cocos2d-html5.org
|
||||
// http://www.cocos2d-x.org
|
||||
//
|
||||
// Javascript + cocos2d actions tests
|
||||
//
|
||||
|
||||
require("js/helper.js");
|
||||
|
||||
director = cc.Director.getInstance();
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var scenes = []
|
||||
var currentScene = 0;
|
||||
|
||||
var nextScene = function () {
|
||||
currentScene = currentScene + 1;
|
||||
if( currentScene >= scenes.length )
|
||||
currentScene = 0;
|
||||
|
||||
withTransition = true;
|
||||
loadScene(currentScene);
|
||||
};
|
||||
|
||||
var previousScene = function () {
|
||||
currentScene = currentScene -1;
|
||||
if( currentScene < 0 )
|
||||
currentScene = scenes.length -1;
|
||||
|
||||
withTransition = true;
|
||||
loadScene(currentScene);
|
||||
};
|
||||
|
||||
var restartScene = function () {
|
||||
loadScene( currentScene );
|
||||
};
|
||||
|
||||
var loadScene = function (sceneIdx)
|
||||
{
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var scene = new cc.Scene();
|
||||
scene.init();
|
||||
var layer = new scenes[ sceneIdx ]();
|
||||
|
||||
scene.addChild( layer );
|
||||
|
||||
// scene.walkSceneGraph(0);
|
||||
|
||||
director.replaceScene( scene );
|
||||
// __jsc__.garbageCollect();
|
||||
}
|
||||
|
||||
var TAG_NODE = 100;
|
||||
|
||||
|
||||
//
|
||||
// Base Layer
|
||||
//
|
||||
|
||||
var BaseLayer = cc.LayerGradient.extend({
|
||||
|
||||
ctor:function () {
|
||||
|
||||
var parent = new cc.LayerGradient();
|
||||
__associateObjWithNative(this, parent);
|
||||
this.init(cc.c4b(0, 0, 0, 255), cc.c4b(0, 128, 255, 255));
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "No Title";
|
||||
},
|
||||
|
||||
subtitle:function () {
|
||||
return "";
|
||||
},
|
||||
|
||||
code:function () {
|
||||
return "";
|
||||
},
|
||||
|
||||
restartCallback:function (sender) {
|
||||
restartScene();
|
||||
},
|
||||
|
||||
nextCallback:function (sender) {
|
||||
nextScene();
|
||||
},
|
||||
|
||||
backCallback:function (sender) {
|
||||
previousScene();
|
||||
},
|
||||
|
||||
onEnter:function () {
|
||||
// DO NOT CALL this._super()
|
||||
// this._super();
|
||||
|
||||
// add title and subtitle
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 28);
|
||||
this.addChild(label, 1);
|
||||
label.setPosition( cc.p(winSize.width / 2, winSize.height - 40));
|
||||
|
||||
var strSubtitle = this.subtitle();
|
||||
if (strSubtitle != "") {
|
||||
var l = cc.LabelTTF.create(strSubtitle, "Thonburi", 16);
|
||||
this.addChild(l, 1);
|
||||
l.setPosition( cc.p(winSize.width / 2, winSize.height - 70));
|
||||
}
|
||||
|
||||
var strCode = this.code();
|
||||
if( strCode !="" ) {
|
||||
var label = cc.LabelTTF.create(strCode, 'CourierNewPSMT', 16);
|
||||
label.setPosition( cc.p( winSize.width/2, winSize.height-120) );
|
||||
this.addChild( label,10 );
|
||||
|
||||
var labelbg = cc.LabelTTF.create(strCode, 'CourierNewPSMT', 16);
|
||||
labelbg.setColor( cc.c3b(10,10,255) );
|
||||
labelbg.setPosition( cc.p( winSize.width/2 +1, winSize.height-120 -1) );
|
||||
this.addChild( labelbg,9);
|
||||
}
|
||||
|
||||
// Menu
|
||||
var item1 = cc.MenuItemImage.create("Images/b1.png", "Images/b2.png", this, this.backCallback);
|
||||
var item2 = cc.MenuItemImage.create("Images/r1.png", "Images/r2.png", this, this.restartCallback);
|
||||
var item3 = cc.MenuItemImage.create("Images/f1.png", "Images/f2.png", this, this.nextCallback);
|
||||
var item4 = cc.MenuItemFont.create("back", this, function() { require("js/main.js"); } );
|
||||
item4.setFontSize( 22 );
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3, item4 );
|
||||
|
||||
menu.setPosition( cc.p(0,0) );
|
||||
item1.setPosition( cc.p(winSize.width / 2 - 100, 30));
|
||||
item2.setPosition( cc.p(winSize.width / 2, 30));
|
||||
item3.setPosition( cc.p(winSize.width / 2 + 100, 30));
|
||||
item4.setPosition( cc.p(winSize.width - 60, winSize.height - 30 ) );
|
||||
|
||||
this.addChild(menu, 1);
|
||||
|
||||
|
||||
// back menu
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// Parallax 1
|
||||
//
|
||||
ParallaxTest1 = BaseLayer.extend({
|
||||
|
||||
_root:null,
|
||||
_target:null,
|
||||
_streak:null,
|
||||
|
||||
|
||||
ctor:function () {
|
||||
this._super();
|
||||
|
||||
// Top Layer, a simple image
|
||||
var cocosImage = cc.Sprite.create("Images/powered.png");
|
||||
// scale the image (optional)
|
||||
cocosImage.setScale(1.5);
|
||||
// change the transform anchor point to 0,0 (optional)
|
||||
cocosImage.setAnchorPoint(cc.p(0, 0));
|
||||
|
||||
// Middle layer: a Tile map atlas
|
||||
// var tilemap = cc.TMXTiledMap.create("TileMaps/orthogonal-test2.tmx");
|
||||
var tilemap = cc.TileMapAtlas.create("TileMaps/tiles.png", "TileMaps/levelmap.tga", 16, 16);
|
||||
|
||||
// change the transform anchor to 0,0 (optional)
|
||||
tilemap.setAnchorPoint(cc.p(0, 0));
|
||||
|
||||
// Anti Aliased images
|
||||
tilemap.getTexture().setAntiAliasTexParameters();
|
||||
|
||||
// background layer: another image
|
||||
var background = cc.Sprite.create("Images/background.png");
|
||||
// scale the image (optional)
|
||||
background.setScale(1.5);
|
||||
// change the transform anchor point (optional)
|
||||
background.setAnchorPoint(cc.p(0, 0));
|
||||
|
||||
|
||||
// create a void node, a parent node
|
||||
var voidNode = cc.ParallaxNode.create();
|
||||
|
||||
// NOW add the 3 layers to the 'void' node
|
||||
|
||||
// background image is moved at a ratio of 0.4x, 0.5y
|
||||
voidNode.addChild(background, -1, cc.p(0.4, 0.5), cc.p(0,0));
|
||||
|
||||
// tiles are moved at a ratio of 2.2x, 1.0y
|
||||
voidNode.addChild(tilemap, 1, cc.p(2.2, 1.0), cc.p(0, -200));
|
||||
|
||||
// top image is moved at a ratio of 3.0x, 2.5y
|
||||
voidNode.addChild(cocosImage, 2, cc.p(3.0, 2.5), cc.p(200, 800));
|
||||
|
||||
|
||||
// now create some actions that will move the 'void' node
|
||||
// and the children of the 'void' node will move at different
|
||||
// speed, thus, simulation the 3D environment
|
||||
var goUp = cc.MoveBy.create(4, cc.p(0, -500));
|
||||
var goDown = goUp.reverse();
|
||||
var go = cc.MoveBy.create(8, cc.p(-1000, 0));
|
||||
var goBack = go.reverse();
|
||||
var seq = cc.Sequence.create(goUp, go, goDown, goBack );
|
||||
voidNode.runAction((cc.RepeatForever.create(seq) ));
|
||||
|
||||
this.addChild(voidNode);
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "Parallax: parent and 3 children";
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//
|
||||
// Parallax 2
|
||||
//
|
||||
ParallaxTest2 = BaseLayer.extend({
|
||||
|
||||
_root:null,
|
||||
_target:null,
|
||||
_streak:null,
|
||||
|
||||
|
||||
ctor:function () {
|
||||
this._super();
|
||||
|
||||
var platform = __getPlatform();
|
||||
if( platform.substring(0,7) == 'desktop' )
|
||||
this.setMouseEnabled( true );
|
||||
else if( platform.substring(0,6) == 'mobile' )
|
||||
this.setTouchEnabled( true );
|
||||
|
||||
// Top Layer, a simple image
|
||||
var cocosImage = cc.Sprite.create("Images/powered.png");
|
||||
// scale the image (optional)
|
||||
cocosImage.setScale(1.5);
|
||||
// change the transform anchor point to 0,0 (optional)
|
||||
cocosImage.setAnchorPoint(cc.p(0, 0));
|
||||
|
||||
|
||||
// Middle layer: a Tile map atlas
|
||||
var tilemap = cc.TileMapAtlas.create("TileMaps/tiles.png", "TileMaps/levelmap.tga", 16, 16);
|
||||
|
||||
// change the transform anchor to 0,0 (optional)
|
||||
tilemap.setAnchorPoint( cc.p(0, 0) );
|
||||
|
||||
// Anti Aliased images
|
||||
tilemap.getTexture().setAntiAliasTexParameters();
|
||||
|
||||
|
||||
// background layer: another image
|
||||
var background = cc.Sprite.create("Images/background.png");
|
||||
// scale the image (optional)
|
||||
background.setScale(1.5);
|
||||
// change the transform anchor point (optional)
|
||||
background.setAnchorPoint(cc.p(0, 0));
|
||||
|
||||
// create a void node, a parent node
|
||||
var voidNode = cc.ParallaxNode.create();
|
||||
|
||||
// NOW add the 3 layers to the 'void' node
|
||||
|
||||
// background image is moved at a ratio of 0.4x, 0.5y
|
||||
voidNode.addChild(background, -1, cc.p(0.4, 0.5), cc.p(0,0));
|
||||
|
||||
// tiles are moved at a ratio of 2.2x, 1.0y
|
||||
voidNode.addChild(tilemap, 1, cc.p(2.2, 1.0), cc.p(0, -200));
|
||||
|
||||
// top image is moved at a ratio of 3.0x, 2.5y
|
||||
voidNode.addChild(cocosImage, 2, cc.p(3.0, 2.5), cc.p(200, 800));
|
||||
this.addChild(voidNode, 0, TAG_NODE);
|
||||
|
||||
},
|
||||
|
||||
onTouchesMoved:function (touches, event) {
|
||||
var node = this.getChildByTag(TAG_NODE);
|
||||
var currentPos = node.getPosition();
|
||||
node.setPosition( cc.pAdd( currentPos, touches[0].getDelta() ) );
|
||||
},
|
||||
|
||||
onMouseDragged : function( event ) {
|
||||
var node = this.getChildByTag(TAG_NODE);
|
||||
var currentPos = node.getPosition();
|
||||
node.setPosition( cc.pAdd( currentPos, event.getDelta() ) );
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "Parallax: drag screen";
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// Order of tests
|
||||
//
|
||||
scenes.push( ParallaxTest1 );
|
||||
scenes.push( ParallaxTest2 );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Main entry point
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
function run()
|
||||
{
|
||||
var scene = cc.Scene.create();
|
||||
var layer = new scenes[currentScene]();
|
||||
scene.addChild( layer );
|
||||
|
||||
var runningScene = director.getRunningScene();
|
||||
if( runningScene == null )
|
||||
director.runWithScene( scene );
|
||||
else
|
||||
director.replaceScene( cc.TransitionFade.create(0.5, scene ) );
|
||||
}
|
||||
|
||||
run();
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -1,122 +0,0 @@
|
|||
//
|
||||
//
|
||||
// Performance tests
|
||||
//
|
||||
//
|
||||
|
||||
// force garbage collect before running
|
||||
__jsc__.garbageCollect();
|
||||
|
||||
// dump config info
|
||||
cc.log('----------------');
|
||||
cc.log('Config info:');
|
||||
for( i in cc.config )
|
||||
cc.log( i + " = " + cc.config[i] );
|
||||
cc.log('----------------');
|
||||
|
||||
//
|
||||
// Testing creating Points in Native
|
||||
//
|
||||
var startMSec = Date.now();
|
||||
var n=50000;
|
||||
for( var i=0; i < n; i++ )
|
||||
var p = cc._native_p(i, i);
|
||||
|
||||
var endMSec = Date.now();
|
||||
var elapsed = (endMSec - startMSec) / 1000;
|
||||
|
||||
cc.log("It took " + elapsed + " seconds to create " + n + " points in Native using cc._native_p(10,10)" );
|
||||
|
||||
//
|
||||
// Testing creating Points in JS
|
||||
//
|
||||
var startMSec = Date.now();
|
||||
var n=50000;
|
||||
for( var i=0; i < n; i++ )
|
||||
var p = {x:i,y:i};
|
||||
|
||||
var endMSec = Date.now();
|
||||
var elapsed = (endMSec - startMSec) / 1000;
|
||||
|
||||
cc.log("It took " + elapsed + " seconds to create " + n + " points in JS using {x:10, y:10}" );
|
||||
|
||||
//
|
||||
// Testing creating Points in JS Using Typed Arrays
|
||||
//
|
||||
var startMSec = Date.now();
|
||||
var n=50000;
|
||||
for( var i=0; i < n; i++ ) {
|
||||
var p = new Float32Array(2);
|
||||
p[0] = i;
|
||||
p[1] = i;
|
||||
}
|
||||
|
||||
var endMSec = Date.now();
|
||||
var elapsed = (endMSec - startMSec) / 1000;
|
||||
|
||||
cc.log("It took " + elapsed + " seconds to create " + n + " points in JS using new Float32Array()" );
|
||||
|
||||
|
||||
//
|
||||
// Testing querying properties
|
||||
// Valid only when using Typed Arrays for Point
|
||||
//
|
||||
var n=50000;
|
||||
var p = new Float32Array(2);
|
||||
p[0] = 10;
|
||||
p[1] = 20;
|
||||
var startMSec = Date.now();
|
||||
for( var i=0; i < n; i++ ) {
|
||||
var x = p[0];
|
||||
var y = p[1];
|
||||
}
|
||||
var endMSec = Date.now();
|
||||
var elapsed = (endMSec - startMSec) / 1000;
|
||||
cc.log("It took " + elapsed + " seconds to parse " + n + " points using p[0], p[1]" );
|
||||
|
||||
//
|
||||
// Testing querying properties
|
||||
// Valid only when using Object for Point
|
||||
//
|
||||
var n=50000;
|
||||
var p = {x:10,y:20};
|
||||
var startMSec = Date.now();
|
||||
for( var i=0; i < n; i++ ) {
|
||||
var x = p.x;
|
||||
var y = p.y;
|
||||
}
|
||||
var endMSec = Date.now();
|
||||
var elapsed = (endMSec - startMSec) / 1000;
|
||||
cc.log("It took " + elapsed + " seconds to parse " + n + " points using p.x, p.y" );
|
||||
|
||||
|
||||
//
|
||||
// Testing native calls
|
||||
//
|
||||
var node = cc.Node.create();
|
||||
node.setPosition( cc.p(1,1) );
|
||||
|
||||
var n=50000;
|
||||
var p = node.getPosition();
|
||||
var startMSec = Date.now();
|
||||
for( var i=0; i < n; i++ ) {
|
||||
node.cleanup();
|
||||
}
|
||||
var endMSec = Date.now();
|
||||
var elapsed = (endMSec - startMSec) / 1000;
|
||||
cc.log("It took " + elapsed + " seconds to send " + n + " calls using node.cleanup()" );
|
||||
|
||||
//
|
||||
// Testing creating nodes
|
||||
//
|
||||
var n=1000;
|
||||
var startMSec = Date.now();
|
||||
for( var i=0; i < n; i++ ) {
|
||||
var node = cc.Node.create();
|
||||
}
|
||||
var endMSec = Date.now();
|
||||
var elapsed = (endMSec - startMSec) / 1000;
|
||||
cc.log("It took " + elapsed + " seconds to create " + n + " cc.Node objects" );
|
||||
|
||||
|
||||
cc.log('----------------');
|
|
@ -1,283 +0,0 @@
|
|||
//
|
||||
// http://www.cocos2d-iphone.org
|
||||
// http://www.cocos2d-html5.org
|
||||
// http://www.cocos2d-x.org
|
||||
//
|
||||
// Javascript + cocos2d actions tests
|
||||
//
|
||||
|
||||
require("js/helper.js");
|
||||
|
||||
director = cc.Director.getInstance();
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
spriteFrameCache = cc.SpriteFrameCache.getInstance();
|
||||
|
||||
var scenes = [];
|
||||
var currentScene = 0;
|
||||
|
||||
var nextScene = function () {
|
||||
currentScene = currentScene + 1;
|
||||
if( currentScene >= scenes.length )
|
||||
currentScene = 0;
|
||||
|
||||
withTransition = true;
|
||||
loadScene(currentScene);
|
||||
};
|
||||
|
||||
var previousScene = function () {
|
||||
currentScene = currentScene -1;
|
||||
if( currentScene < 0 )
|
||||
currentScene = scenes.length -1;
|
||||
|
||||
withTransition = true;
|
||||
loadScene(currentScene);
|
||||
};
|
||||
|
||||
var restartScene = function () {
|
||||
loadScene( currentScene );
|
||||
};
|
||||
|
||||
var loadScene = function (sceneIdx)
|
||||
{
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var scene = new cc.Scene();
|
||||
scene.init();
|
||||
var layer = new scenes[ sceneIdx ]();
|
||||
|
||||
scene.addChild( layer );
|
||||
|
||||
// scene.walkSceneGraph(0);
|
||||
|
||||
director.replaceScene( scene );
|
||||
// __jsc__.garbageCollect();
|
||||
}
|
||||
|
||||
var s_pathSister1 = "Images/grossinis_sister1.png";
|
||||
var s_pathSister2 = "Images/grossinis_sister2.png";
|
||||
var s_pathBlock = "Images/blocks.png";
|
||||
var s_grossiniPlist = "animations/grossini.plist";
|
||||
|
||||
//
|
||||
// Base Layer
|
||||
//
|
||||
|
||||
var BaseLayer = cc.LayerGradient.extend({
|
||||
|
||||
ctor:function () {
|
||||
|
||||
var parent = new cc.LayerGradient();
|
||||
__associateObjWithNative(this, parent);
|
||||
this.init(cc.c4b(0, 0, 0, 255), cc.c4b(0, 128, 255, 255));
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "Render Texture";
|
||||
},
|
||||
|
||||
subtitle:function () {
|
||||
return "";
|
||||
},
|
||||
|
||||
code:function () {
|
||||
return "";
|
||||
},
|
||||
|
||||
restartCallback:function (sender) {
|
||||
restartScene();
|
||||
},
|
||||
|
||||
nextCallback:function (sender) {
|
||||
nextScene();
|
||||
},
|
||||
|
||||
backCallback:function (sender) {
|
||||
previousScene();
|
||||
},
|
||||
|
||||
onEnter:function () {
|
||||
// DO NOT CALL this._super()
|
||||
// this._super();
|
||||
|
||||
// add title and subtitle
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 28);
|
||||
this.addChild(label, 10);
|
||||
label.setPosition( cc.p(winSize.width / 2, winSize.height - 40));
|
||||
|
||||
var strSubtitle = this.subtitle();
|
||||
if (strSubtitle != "") {
|
||||
var l = cc.LabelTTF.create(strSubtitle, "Thonburi", 16);
|
||||
this.addChild(l, 10);
|
||||
l.setPosition( cc.p(winSize.width / 2, winSize.height - 70));
|
||||
}
|
||||
|
||||
var strCode = this.code();
|
||||
if( strCode !="" ) {
|
||||
var label = cc.LabelTTF.create(strCode, 'CourierNewPSMT', 16);
|
||||
label.setPosition( cc.p( winSize.width/2, winSize.height-120) );
|
||||
this.addChild( label,10 );
|
||||
|
||||
var labelbg = cc.LabelTTF.create(strCode, 'CourierNewPSMT', 16);
|
||||
labelbg.setColor( cc.c3b(10,10,255) );
|
||||
labelbg.setPosition( cc.p( winSize.width/2 +1, winSize.height-120 -1) );
|
||||
this.addChild( labelbg,9);
|
||||
}
|
||||
|
||||
// Menu
|
||||
var item1 = cc.MenuItemImage.create("Images/b1.png", "Images/b2.png", this, this.backCallback);
|
||||
var item2 = cc.MenuItemImage.create("Images/r1.png", "Images/r2.png", this, this.restartCallback);
|
||||
var item3 = cc.MenuItemImage.create("Images/f1.png", "Images/f2.png", this, this.nextCallback);
|
||||
var item4 = cc.MenuItemFont.create("back", this, function() { require("js/main.js"); } );
|
||||
item4.setFontSize( 22 );
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3, item4 );
|
||||
|
||||
menu.setPosition( cc.p(0,0) );
|
||||
item1.setPosition( cc.p(winSize.width / 2 - 100, 30));
|
||||
item2.setPosition( cc.p(winSize.width / 2, 30));
|
||||
item3.setPosition( cc.p(winSize.width / 2 + 100, 30));
|
||||
item4.setPosition( cc.p(winSize.width - 60, winSize.height - 30 ) );
|
||||
|
||||
this.addChild(menu, 10);
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Tests
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var RenderTextureSave = BaseLayer.extend({
|
||||
_brush : null,
|
||||
_target : null,
|
||||
_lastLocation : null,
|
||||
_counter :0,
|
||||
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var platform = __getPlatform();
|
||||
if( platform.substring(0,7) == 'desktop' )
|
||||
this.setMouseEnabled( true );
|
||||
else if( platform.substring(0,6) == 'mobile' )
|
||||
this.setTouchEnabled( true );
|
||||
|
||||
this._brush = cc.Sprite.create("Images/fire.png");
|
||||
this._brush.retain();
|
||||
|
||||
this._brush.setColor( cc.RED );
|
||||
this._brush.setOpacity( 20 );
|
||||
|
||||
|
||||
var save = cc.MenuItemFont.create("Save", this, this.saveCB );
|
||||
var clear = cc.MenuItemFont.create("Clear", this, this.clearCB );
|
||||
var menu = cc.Menu.create( save, clear );
|
||||
menu.alignItemsVertically();
|
||||
menu.setPosition( cc.p( winSize.width-70, winSize.height-80 ) );
|
||||
this.addChild( menu, 10 );
|
||||
|
||||
// create a render texture
|
||||
var target = cc.RenderTexture.create( winSize.width, winSize.height );
|
||||
target.setPosition( cc.p (winSize.width/2, winSize.height/2) );
|
||||
this.addChild( target, 1 );
|
||||
|
||||
this._target = target;
|
||||
|
||||
this._lastLocation = cc.p( winSize.width/2, winSize.height/2);
|
||||
|
||||
},
|
||||
|
||||
onExit:function() {
|
||||
this._brush.release();
|
||||
},
|
||||
|
||||
saveCB:function(sender) {
|
||||
var namePNG = "image-" + this._counter + ".png";
|
||||
var nameJPG = "image-" + this._counter + ".jpg";
|
||||
|
||||
this._target.saveToFile( nameJPG, cc.IMAGE_FORMAT_JPEG );
|
||||
this._target.saveToFile( namePNG, cc.IMAGE_FORMAT_PNG );
|
||||
|
||||
cc.log("images saved!");
|
||||
this._counter++;
|
||||
},
|
||||
|
||||
clearCB:function(sender) {
|
||||
this._target.clear( Math.random(), Math.random(), Math.random(), 1 );
|
||||
},
|
||||
|
||||
drawInLocation: function( location ) {
|
||||
var distance = cc.pDistance( location, this._lastLocation );
|
||||
if( distance > 1 ) {
|
||||
this._target.begin();
|
||||
for( var i=0; i < distance; i++ ) {
|
||||
var diffX = this._lastLocation.x - location.x;
|
||||
var diffY = this._lastLocation.y - location.y;
|
||||
|
||||
var delta = i / distance;
|
||||
|
||||
this._brush.setPosition( cc._p( location.x + diffX * delta, location.y + diffY * delta ) );
|
||||
this._brush.setRotation( Math.random() * 360 );
|
||||
this._brush.setScale( Math.random() * 2 );
|
||||
this._brush.setColor( cc._c3b( Math.random()*255, 255, 255) );
|
||||
this._brush.visit();
|
||||
}
|
||||
this._target.end();
|
||||
}
|
||||
this._lastLocation = location;
|
||||
},
|
||||
|
||||
onTouchesBegan:function (touches, event) {
|
||||
this._lastLocation = touches[0].getLocation();
|
||||
return true;
|
||||
},
|
||||
|
||||
onTouchesMoved:function (touches, event) {
|
||||
this.drawInLocation( touches[0].getLocation() );
|
||||
return true;
|
||||
},
|
||||
|
||||
onMouseDown : function( event ) {
|
||||
this._lastLocation = event.getLocation();
|
||||
return true;
|
||||
},
|
||||
|
||||
onMouseDragged : function( event ) {
|
||||
this.drawInLocation( event.getLocation() );
|
||||
return true;
|
||||
},
|
||||
|
||||
subtitle:function () {
|
||||
return "Testing 'save'";
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// Order of tests
|
||||
//
|
||||
|
||||
scenes.push( RenderTextureSave );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Main entry point
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
function run()
|
||||
{
|
||||
var scene = cc.Scene.create();
|
||||
var layer = new scenes[currentScene]();
|
||||
scene.addChild( layer );
|
||||
|
||||
var runningScene = director.getRunningScene();
|
||||
if( runningScene == null )
|
||||
director.runWithScene( scene );
|
||||
else
|
||||
director.replaceScene( cc.TransitionFade.create(0.5, scene ) );
|
||||
}
|
||||
|
||||
run();
|
||||
|
||||
|
|
@ -1,781 +0,0 @@
|
|||
//
|
||||
// http://www.cocos2d-iphone.org
|
||||
//
|
||||
// Javascript + cocos2d sprite tests
|
||||
//
|
||||
|
||||
require("js/helper.js");
|
||||
|
||||
director = cc.Director.getInstance();
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var scenes = []
|
||||
var currentScene = 0;
|
||||
|
||||
var nextSpriteTestAction = function () {
|
||||
currentScene = currentScene + 1;
|
||||
if( currentScene >= scenes.length )
|
||||
currentScene = 0;
|
||||
|
||||
loadScene(currentScene);
|
||||
};
|
||||
var backSpriteTestAction = function () {
|
||||
currentScene = currentScene -1;
|
||||
if( currentScene < 0 )
|
||||
currentScene = scenes.length -1;
|
||||
|
||||
loadScene(currentScene);
|
||||
};
|
||||
var restartSpriteTestAction = function () {
|
||||
loadScene( currentScene );
|
||||
};
|
||||
|
||||
var loadScene = function (sceneIdx)
|
||||
{
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var scene = new cc.Scene();
|
||||
scene.init();
|
||||
var layer = new scenes[ sceneIdx ]();
|
||||
|
||||
scene.addChild( layer );
|
||||
|
||||
// scene.walkSceneGraph(0);
|
||||
|
||||
director.replaceScene( scene );
|
||||
// __jsc__.garbageCollect();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// BaseLayer
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var BaseLayer = function() {
|
||||
|
||||
//
|
||||
// VERY IMPORTANT
|
||||
//
|
||||
// Only subclasses of a native classes MUST call __associateObjectWithNative
|
||||
// Failure to do so, it will crash.
|
||||
//
|
||||
var parent = goog.base(this);
|
||||
__associateObjWithNative( this, parent );
|
||||
this.init();
|
||||
|
||||
this.title = function () {
|
||||
return "No title";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "No Subtitle";
|
||||
}
|
||||
|
||||
}
|
||||
goog.inherits(BaseLayer, cc.Layer );
|
||||
|
||||
//
|
||||
// Instance 'base' methods
|
||||
// XXX: Should be defined after "goog.inherits"
|
||||
//
|
||||
BaseLayer.prototype.onEnter = function() {
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 28);
|
||||
this.addChild(label, 1);
|
||||
label.setPosition( cc.p(winSize.width / 2, winSize.height - 50));
|
||||
|
||||
var strSubtitle = this.subtitle();
|
||||
if (strSubtitle != "") {
|
||||
var l = cc.LabelTTF.create(strSubtitle, "Thonburi", 16);
|
||||
this.addChild(l, 1);
|
||||
l.setPosition( cc.p(winSize.width / 2, winSize.height - 80));
|
||||
}
|
||||
|
||||
// Menu
|
||||
var item1 = cc.MenuItemImage.create("Images/b1.png", "Images/b2.png", this, this.backCallback);
|
||||
var item2 = cc.MenuItemImage.create("Images/r1.png", "Images/r2.png", this, this.restartCallback);
|
||||
var item3 = cc.MenuItemImage.create("Images/f1.png", "Images/f2.png", this, this.nextCallback);
|
||||
var item4 = cc.MenuItemFont.create("back", this, function() { require("js/main.js"); } );
|
||||
cc.MenuItemFont.setFontSize( 22 );
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3, item4 );
|
||||
|
||||
menu.setPosition( cc.p(0,0) );
|
||||
item1.setPosition( cc.p(winSize.width / 2 - 100, 30));
|
||||
item2.setPosition( cc.p(winSize.width / 2, 30));
|
||||
item3.setPosition( cc.p(winSize.width / 2 + 100, 30));
|
||||
item4.setPosition( cc.p(winSize.width - 60, winSize.height - 30 ) );
|
||||
|
||||
this.addChild(menu, 1);
|
||||
}
|
||||
|
||||
BaseLayer.prototype.restartCallback = function (sender) {
|
||||
cc.log("restart called");
|
||||
restartSpriteTestAction();
|
||||
}
|
||||
|
||||
BaseLayer.prototype.nextCallback = function (sender) {
|
||||
cc.log("next called");
|
||||
nextSpriteTestAction();
|
||||
}
|
||||
|
||||
BaseLayer.prototype.backCallback = function (sender) {
|
||||
cc.log("back called");
|
||||
backSpriteTestAction();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Sprite Touch test
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteTouchTest = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.initialize = function() {
|
||||
var platform = __getPlatform();
|
||||
if( platform.substring(0,7) == 'desktop' )
|
||||
this.setMouseEnabled( true );
|
||||
else if( platform.substring(0,6) == 'mobile' )
|
||||
this.setTouchEnabled( true );
|
||||
this.addSprite( centerPos );
|
||||
}
|
||||
|
||||
this.addSprite = function(pos) {
|
||||
var sprite = this.createSprite( pos );
|
||||
this.addChild( sprite );
|
||||
}
|
||||
|
||||
this.title = function () {
|
||||
return "Sprite: Simple action test";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "Tap screen to add more sprites";
|
||||
}
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
goog.inherits(SpriteTouchTest, BaseLayer );
|
||||
|
||||
SpriteTouchTest.prototype.onMouseDown = function( event ) {
|
||||
this.addSprite( event.getLocation() );
|
||||
}
|
||||
|
||||
SpriteTouchTest.prototype.onTouchesEnded = function( touches, event ) {
|
||||
var l = touches.length;
|
||||
for( var i=0; i < l; i++) {
|
||||
this.addSprite( touches[i].getLocation() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SpriteTouchTest.prototype.createSprite = function( pos ) {
|
||||
var idx = Math.random() * 1400 / 100;
|
||||
idx = Math.floor( idx );
|
||||
var x = Math.floor(idx%5) * 85;
|
||||
var y = Math.floor(idx/5) * 121;
|
||||
|
||||
var sprite = cc.Sprite.create("Images/grossini_dance_atlas.png", cc.rect(x,y,85,121) );
|
||||
sprite.setPosition( pos );
|
||||
|
||||
var rand = Math.random();
|
||||
|
||||
if( rand < 0.20 ) {
|
||||
var action = cc.ScaleBy.create(3, 2 );
|
||||
} else if(rand < 0.40) {
|
||||
var action = cc.RotateBy.create(3, 360 );
|
||||
} else if( rand < 0.60) {
|
||||
var action = cc.Blink.create(1, 3 );
|
||||
} else if( rand < 0.8 ) {
|
||||
var action = cc.TintBy.create(2, 0, -255, -255 );
|
||||
} else {
|
||||
var action = cc.FadeOut.create( 2 );
|
||||
}
|
||||
var action_back = action.reverse();
|
||||
var seq = cc.Sequence.create(action, action_back);
|
||||
|
||||
sprite.runAction( cc.RepeatForever.create( seq ) );
|
||||
|
||||
return sprite;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Sprite Batch Touch test
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteBatchTouchTest = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.initialize = function() {
|
||||
this.batch = cc.SpriteBatchNode.create("Images/grossini_dance_atlas.png", 50 );
|
||||
this.addChild( this.batch );
|
||||
|
||||
var platform = __getPlatform();
|
||||
if( platform == 'OSX' ) {
|
||||
this.setIsMouseEnabled( true );
|
||||
} else if( platform == 'iOS' ) {
|
||||
this.setIsTouchEnabled( true );
|
||||
}
|
||||
}
|
||||
|
||||
this.addSprite = function(pos) {
|
||||
var sprite = this.createSprite( pos );
|
||||
this.batch.addChild( sprite );
|
||||
}
|
||||
|
||||
this.title = function () {
|
||||
return "SpriteBatch: Simple action test";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "Tap screen to add more sprites";
|
||||
}
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
goog.inherits( SpriteBatchTouchTest, SpriteTouchTest );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Sprite vs. SpriteBatch Animation
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteFrameTest = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.initialize = function() {
|
||||
var cache = cc.SpriteFrameCache.getInstance();
|
||||
cache.addSpriteFrames( "animations/grossini.plist" );
|
||||
cache.addSpriteFrames( "animations/grossini_gray.plist", "animations/grossini_gray.png" );
|
||||
cache.addSpriteFrames( "animations/grossini_blue.plist", "animations/grossini_blue.png" );
|
||||
|
||||
//
|
||||
// Animation using Sprite batch
|
||||
//
|
||||
// A CCSpriteBatchNode can reference one and only one texture (one .png file)
|
||||
// Sprites that are contained in that texture can be instantiatied as CCSprites and then added to the CCSpriteBatchNode
|
||||
// All CCSprites added to a CCSpriteBatchNode are drawn in one OpenGL ES draw call
|
||||
// If the CCSprites are not added to a CCSpriteBatchNode then an OpenGL ES draw call will be needed for each one, which is less efficient
|
||||
//
|
||||
// When you animate a sprite, CCAnimation changes the frame of the sprite using setDisplayFrame: (this is why the animation must be in the same texture)
|
||||
// When setDisplayFrame: is used in the CCAnimation it changes the frame to one specified by the CCSpriteFrames that were added to the animation,
|
||||
// but texture id is still the same and so the sprite is still a child of the CCSpriteBatchNode,
|
||||
// and therefore all the animation sprites are also drawn as part of the CCSpriteBatchNode
|
||||
//
|
||||
|
||||
var sprite1 = cc.Sprite.createWithSpriteFrameName("grossini_dance_01.png");
|
||||
sprite1.setPosition( cc.p( winSize.width/2-80, winSize.height/2) );
|
||||
|
||||
var spritebatch = cc.SpriteBatchNode.create("animations/grossini.pvr");
|
||||
spritebatch.addChild(sprite1);
|
||||
this.addChild( spritebatch );
|
||||
|
||||
var frames = []
|
||||
for( var i = 1; i < 15; i++) {
|
||||
|
||||
if( i < 10 ) {
|
||||
var name = "grossini_dance_0" + i + ".png";
|
||||
} else {
|
||||
var name = "grossini_dance_" + i + ".png";
|
||||
}
|
||||
|
||||
var frame = cache.getSpriteFrame( name );
|
||||
frames.push( frame );
|
||||
}
|
||||
|
||||
var animation = cc.Animation.createWithSpriteFrames( frames, 0.3 );
|
||||
// 14 frames * 1sec = 14 seconds
|
||||
sprite1.runAction( cc.RepeatForever.create( cc.Animate.create( animation ) ) );
|
||||
|
||||
|
||||
//
|
||||
// Animation using standard Sprite
|
||||
//
|
||||
//
|
||||
var sprite2 = cc.Sprite.createWithSpriteFrameName( "grossini_dance_01.png" );
|
||||
sprite2.setPosition( cc.p( winSize.width/2 + 80, winSize.height/2) );
|
||||
this.addChild( sprite2 );
|
||||
|
||||
var moreFrames = []
|
||||
for(var i = 1; i < 15; i++) {
|
||||
if( i < 10 ) {
|
||||
var name = "grossini_dance_gray_0" + i + ".png";
|
||||
} else {
|
||||
var name = "grossini_dance_gray_" + i + ".png";
|
||||
}
|
||||
var frame = cache.getSpriteFrame( name );
|
||||
moreFrames.push( frame );
|
||||
}
|
||||
for( var i = 1; i < 5; i++) {
|
||||
var name = "grossini_blue_0" + i + ".png";
|
||||
var frame = cache.getSpriteFrame( name );
|
||||
moreFrames.push( frame );
|
||||
}
|
||||
|
||||
|
||||
moreFrames.concat( frames );
|
||||
var animMixed = cc.Animation.createWithSpriteFrames( moreFrames, 0.3 );
|
||||
|
||||
// 32 frames * 1 seconds = 32 seconds
|
||||
sprite2.runAction( cc.RepeatForever.create( cc.Animate.create( animMixed ) ) );
|
||||
|
||||
// to test issue #732, uncomment the following line
|
||||
sprite2.setFlipX( false );
|
||||
sprite2.setFlipY( false );
|
||||
}
|
||||
|
||||
this.title = function () {
|
||||
return "Sprite vs. SpriteBatchNode animation";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "Testing issue #792";
|
||||
}
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
goog.inherits( SpriteFrameTest, BaseLayer );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteAnchorPoint
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteAnchorPoint = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.initialize = function() {
|
||||
for(var i=0;i<3;i++) {
|
||||
var sprite = cc.Sprite.create("Images/grossini_dance_atlas.png", cc.rect(85*i, 121*1, 85, 121) );
|
||||
sprite.setPosition( cc.p( winSize.width/4*(i+1), winSize.height/2) );
|
||||
|
||||
var point = cc.Sprite.create( "Images/r1.png" );
|
||||
point.setScale( 0.25 );
|
||||
point.setPosition( sprite.getPosition() );
|
||||
this.addChild( point, 10 );
|
||||
|
||||
if( i == 0 ) {
|
||||
sprite.setAnchorPoint( cc.p( 0, 0) );
|
||||
} else if( i == 1 ) {
|
||||
sprite.setAnchorPoint( cc.p(0.5, 0.5) );
|
||||
} else if( i == 2 ) {
|
||||
sprite.setAnchorPoint( cc.p(1,1) );
|
||||
}
|
||||
|
||||
point.setPosition( sprite.getPosition() );
|
||||
|
||||
var rotate = cc.RotateBy.create(10, 360);
|
||||
var action = cc.RepeatForever.create( rotate );
|
||||
|
||||
sprite.runAction( action );
|
||||
this.addChild( sprite, i );
|
||||
}
|
||||
}
|
||||
|
||||
this.title = function () {
|
||||
return "Sprite: anchor point";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "Testing 3 different anchor points";
|
||||
}
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
goog.inherits( SpriteAnchorPoint, BaseLayer );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteBatchAnchorPoint
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteBatchAnchorPoint = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.initialize = function() {
|
||||
var batch = cc.SpriteBatchNode.create( "Images/grossini_dance_atlas.png" );
|
||||
for(var i=0;i<3;i++) {
|
||||
var sprite = cc.Sprite.create("Images/grossini_dance_atlas.png", cc.rect(85*i, 121*1, 85, 121) );
|
||||
sprite.setPosition( cc.p( winSize.width/4*(i+1), winSize.height/2) );
|
||||
|
||||
var point = cc.Sprite.create( "Images/r1.png" );
|
||||
point.setScale( 0.25 );
|
||||
point.setPosition( sprite.getPosition() );
|
||||
this.addChild( point, 10 );
|
||||
|
||||
if( i == 0 ) {
|
||||
sprite.setAnchorPoint( cc.p( 0, 0) );
|
||||
} else if( i == 1 ) {
|
||||
sprite.setAnchorPoint( cc.p(0.5, 0.5) );
|
||||
} else if( i == 2 ) {
|
||||
sprite.setAnchorPoint( cc.p(1,1) );
|
||||
}
|
||||
|
||||
point.setPosition( sprite.getPosition() );
|
||||
|
||||
var rotate = cc.RotateBy.create(10, 360);
|
||||
var action = cc.RepeatForever.create( rotate );
|
||||
|
||||
sprite.runAction( action );
|
||||
batch.addChild( sprite, i );
|
||||
}
|
||||
this.addChild( batch );
|
||||
}
|
||||
|
||||
this.title = function () {
|
||||
return "Sprite Batch: anchor point";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "Testing 3 different anchor points";
|
||||
}
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
goog.inherits( SpriteBatchAnchorPoint, BaseLayer );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteOffsetAnchorFlip
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteOffsetAnchorFlip = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.initialize = function() {
|
||||
var cache = cc.SpriteFrameCache.getInstance();
|
||||
cache.addSpriteFrames("animations/grossini.plist");
|
||||
cache.addSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray.png");
|
||||
|
||||
for(var i=0;i<3;i++) {
|
||||
var sprite = cc.Sprite.create("Images/grossini_dance_atlas.png", cc.rect(85*i, 121*1, 85, 121) );
|
||||
sprite.setPosition( cc.p( winSize.width/4*(i+1), winSize.height/2) );
|
||||
|
||||
var point = cc.Sprite.create( "Images/r1.png" );
|
||||
point.setScale( 0.25 );
|
||||
point.setPosition( sprite.getPosition() );
|
||||
this.addChild( point, 10 );
|
||||
|
||||
if( i == 0 ) {
|
||||
sprite.setAnchorPoint( cc.p( 0, 0) );
|
||||
} else if( i == 1 ) {
|
||||
sprite.setAnchorPoint( cc.p(0.5, 0.5) );
|
||||
} else if( i == 2 ) {
|
||||
sprite.setAnchorPoint( cc.p(1,1) );
|
||||
}
|
||||
|
||||
point.setPosition( sprite.getPosition() );
|
||||
|
||||
var frames = []
|
||||
for( var j = 1; j < 15; j++) {
|
||||
|
||||
if( j < 10 ) {
|
||||
var name = "grossini_dance_0" + j + ".png";
|
||||
} else {
|
||||
var name = "grossini_dance_" + j + ".png";
|
||||
}
|
||||
|
||||
var frame = cache.getSpriteFrame( name );
|
||||
frames.push( frame );
|
||||
}
|
||||
|
||||
var animation = cc.Animation.createWithSpriteFrames( frames, 0.3 );
|
||||
sprite.runAction( cc.RepeatForever.create( cc.Animate.create( animation ) ) );
|
||||
|
||||
var flip = cc.FlipY.create( true );
|
||||
var flip_back = cc.FlipY.create( false );
|
||||
var delay = cc.DelayTime.create( 1 );
|
||||
var delay2 = cc.DelayTime.create( 1 );
|
||||
var seq = cc.Sequence.create( delay, flip, delay2, flip_back );
|
||||
sprite.runAction( cc.RepeatForever.create( seq ) );
|
||||
|
||||
this.addChild( sprite );
|
||||
}
|
||||
}
|
||||
|
||||
this.title = function () {
|
||||
return "Sprite offset + anchor + flip";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "issue #1078";
|
||||
}
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
goog.inherits( SpriteOffsetAnchorFlip, BaseLayer );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteBatchOffsetAnchorFlip
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteBatchOffsetAnchorFlip = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.initialize = function() {
|
||||
var cache = cc.SpriteFrameCache.getInstance();
|
||||
cache.addSpriteFrames("animations/grossini.plist");
|
||||
cache.addSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray.png");
|
||||
|
||||
var batch = cc.SpriteBatchNode.create("animations/grossini.pvr");
|
||||
|
||||
for(var i=0;i<3;i++) {
|
||||
var sprite = cc.Sprite.createWithSpriteFrameName("grossini_dance_01.png");
|
||||
sprite.setPosition( cc.p( winSize.width/4*(i+1), winSize.height/2) );
|
||||
|
||||
var point = cc.Sprite.create( "Images/r1.png" );
|
||||
point.setScale( 0.25 );
|
||||
point.setPosition( sprite.getPosition() );
|
||||
this.addChild( point, 10 );
|
||||
|
||||
if( i == 0 ) {
|
||||
sprite.setAnchorPoint( cc.p( 0, 0) );
|
||||
} else if( i == 1 ) {
|
||||
sprite.setAnchorPoint( cc.p(0.5, 0.5) );
|
||||
} else if( i == 2 ) {
|
||||
sprite.setAnchorPoint( cc.p(1,1) );
|
||||
}
|
||||
|
||||
point.setPosition( sprite.getPosition() );
|
||||
|
||||
var frames = []
|
||||
for( var j = 1; j < 15; j++) {
|
||||
|
||||
if( j < 10 ) {
|
||||
var name = "grossini_dance_0" + j + ".png";
|
||||
} else {
|
||||
var name = "grossini_dance_" + j + ".png";
|
||||
}
|
||||
|
||||
var frame = cache.getSpriteFrame( name );
|
||||
frames.push( frame );
|
||||
}
|
||||
|
||||
var animation = cc.Animation.createWithSpriteFrames( frames, 0.3 );
|
||||
sprite.runAction( cc.RepeatForever.create( cc.Animate.create( animation ) ) );
|
||||
|
||||
var flip = cc.FlipY.create( true );
|
||||
var flip_back = cc.FlipY.create( false );
|
||||
var delay = cc.DelayTime.create( 1 );
|
||||
var delay2 = cc.DelayTime.create( 1 );
|
||||
var seq = cc.Sequence.create( delay, flip, delay2, flip_back );
|
||||
sprite.runAction( cc.RepeatForever.create( seq ) );
|
||||
|
||||
batch.addChild( sprite );
|
||||
}
|
||||
this.addChild(batch);
|
||||
}
|
||||
|
||||
this.title = function () {
|
||||
return "SpriteBatch offset + anchor + flip";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "issue #1078";
|
||||
}
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
goog.inherits( SpriteBatchOffsetAnchorFlip, BaseLayer );
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteColorOpacity
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteColorOpacity = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.initialize = function() {
|
||||
var sprite1 = cc.Sprite.create('Images/grossini_dance_atlas.png', cc.rect(85 * 0, 121 * 1, 85, 121));
|
||||
var sprite2 = cc.Sprite.create('Images/grossini_dance_atlas.png', cc.rect(85 * 1, 121 * 1, 85, 121));
|
||||
var sprite3 = cc.Sprite.create('Images/grossini_dance_atlas.png', cc.rect(85 * 2, 121 * 1, 85, 121));
|
||||
var sprite4 = cc.Sprite.create('Images/grossini_dance_atlas.png', cc.rect(85 * 3, 121 * 1, 85, 121));
|
||||
var sprite5 = cc.Sprite.create('Images/grossini_dance_atlas.png', cc.rect(85 * 0, 121 * 1, 85, 121));
|
||||
var sprite6 = cc.Sprite.create('Images/grossini_dance_atlas.png', cc.rect(85 * 1, 121 * 1, 85, 121));
|
||||
var sprite7 = cc.Sprite.create('Images/grossini_dance_atlas.png', cc.rect(85 * 2, 121 * 1, 85, 121));
|
||||
var sprite8 = cc.Sprite.create('Images/grossini_dance_atlas.png', cc.rect(85 * 3, 121 * 1, 85, 121));
|
||||
|
||||
sprite1.setPosition(cc.p((winSize.width / 5) * 1, (winSize.height / 3) * 1));
|
||||
sprite2.setPosition(cc.p((winSize.width / 5) * 2, (winSize.height / 3) * 1));
|
||||
sprite3.setPosition(cc.p((winSize.width / 5) * 3, (winSize.height / 3) * 1));
|
||||
sprite4.setPosition(cc.p((winSize.width / 5) * 4, (winSize.height / 3) * 1));
|
||||
sprite5.setPosition(cc.p((winSize.width / 5) * 1, (winSize.height / 3) * 2));
|
||||
sprite6.setPosition(cc.p((winSize.width / 5) * 2, (winSize.height / 3) * 2));
|
||||
sprite7.setPosition(cc.p((winSize.width / 5) * 3, (winSize.height / 3) * 2));
|
||||
sprite8.setPosition(cc.p((winSize.width / 5) * 4, (winSize.height / 3) * 2));
|
||||
|
||||
var action = cc.FadeIn.create(2);
|
||||
var action_back = action.reverse();
|
||||
var fade = cc.RepeatForever.create( cc.Sequence.create( action, action_back ) );
|
||||
|
||||
var tintRed = cc.TintBy.create(2, 0, -255, -255);
|
||||
// var tintRed = cc.RotateBy.create(2, 360 );
|
||||
var tintRedBack = tintRed.reverse();
|
||||
var red = cc.RepeatForever.create(cc.Sequence.create( tintRed, tintRedBack ) );
|
||||
|
||||
var tintGreen = cc.TintBy.create(2, -255, 0, -255);
|
||||
var tintGreenBack = tintGreen.reverse();
|
||||
var green = cc.RepeatForever.create(cc.Sequence.create( tintGreen, tintGreenBack ) );
|
||||
|
||||
var tintBlue = cc.TintBy.create(2, -255, -255, 0);
|
||||
var tintBlueBack = tintBlue.reverse();
|
||||
var blue = cc.RepeatForever.create(cc.Sequence.create( tintBlue, tintBlueBack ) );
|
||||
|
||||
sprite5.runAction(red);
|
||||
sprite6.runAction(green);
|
||||
sprite7.runAction(blue);
|
||||
sprite8.runAction(fade);
|
||||
|
||||
// late add: test dirtyColor and dirtyPosition
|
||||
this.addChild(sprite1);
|
||||
this.addChild(sprite2);
|
||||
this.addChild(sprite3);
|
||||
this.addChild(sprite4);
|
||||
this.addChild(sprite5);
|
||||
this.addChild(sprite6);
|
||||
this.addChild(sprite7);
|
||||
this.addChild(sprite8);
|
||||
}
|
||||
|
||||
//
|
||||
// Instance methods
|
||||
//
|
||||
this.title = function () {
|
||||
return "Sprite: Color & Opacity";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "testing opacity and color";
|
||||
}
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
goog.inherits(SpriteColorOpacity, BaseLayer );
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteBatchColorOpacity
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteBatchColorOpacity = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
this.initialize = function() {
|
||||
var batch = cc.SpriteBatchNode.create('Images/grossini_dance_atlas.png', 10);
|
||||
var sprite1 = cc.Sprite.create('Images/grossini_dance_atlas.png', cc.rect(85 * 0, 121 * 1, 85, 121));
|
||||
var sprite2 = cc.Sprite.create('Images/grossini_dance_atlas.png', cc.rect(85 * 1, 121 * 1, 85, 121));
|
||||
var sprite3 = cc.Sprite.create('Images/grossini_dance_atlas.png', cc.rect(85 * 2, 121 * 1, 85, 121));
|
||||
var sprite4 = cc.Sprite.create('Images/grossini_dance_atlas.png', cc.rect(85 * 3, 121 * 1, 85, 121));
|
||||
var sprite5 = cc.Sprite.create('Images/grossini_dance_atlas.png', cc.rect(85 * 0, 121 * 1, 85, 121));
|
||||
var sprite6 = cc.Sprite.create('Images/grossini_dance_atlas.png', cc.rect(85 * 1, 121 * 1, 85, 121));
|
||||
var sprite7 = cc.Sprite.create('Images/grossini_dance_atlas.png', cc.rect(85 * 2, 121 * 1, 85, 121));
|
||||
var sprite8 = cc.Sprite.create('Images/grossini_dance_atlas.png', cc.rect(85 * 3, 121 * 1, 85, 121));
|
||||
|
||||
sprite1.setPosition(cc.p((winSize.width / 5) * 1, (winSize.height / 3) * 1));
|
||||
sprite2.setPosition(cc.p((winSize.width / 5) * 2, (winSize.height / 3) * 1));
|
||||
sprite3.setPosition(cc.p((winSize.width / 5) * 3, (winSize.height / 3) * 1));
|
||||
sprite4.setPosition(cc.p((winSize.width / 5) * 4, (winSize.height / 3) * 1));
|
||||
sprite5.setPosition(cc.p((winSize.width / 5) * 1, (winSize.height / 3) * 2));
|
||||
sprite6.setPosition(cc.p((winSize.width / 5) * 2, (winSize.height / 3) * 2));
|
||||
sprite7.setPosition(cc.p((winSize.width / 5) * 3, (winSize.height / 3) * 2));
|
||||
sprite8.setPosition(cc.p((winSize.width / 5) * 4, (winSize.height / 3) * 2));
|
||||
|
||||
var action = cc.FadeIn.create(2);
|
||||
var action_back = action.reverse();
|
||||
var fade = cc.RepeatForever.create( cc.Sequence.create( action, action_back ) );
|
||||
|
||||
var tintRed = cc.TintBy.create(2, 0, -255, -255);
|
||||
// var tintRed = cc.RotateBy.create(2, 360 );
|
||||
var tintRedBack = tintRed.reverse();
|
||||
var red = cc.RepeatForever.create(cc.Sequence.create( tintRed, tintRedBack ) );
|
||||
|
||||
var tintGreen = cc.TintBy.create(2, -255, 0, -255);
|
||||
var tintGreenBack = tintGreen.reverse();
|
||||
var green = cc.RepeatForever.create(cc.Sequence.create( tintGreen, tintGreenBack ) );
|
||||
|
||||
var tintBlue = cc.TintBy.create(2, -255, -255, 0);
|
||||
var tintBlueBack = tintBlue.reverse();
|
||||
var blue = cc.RepeatForever.create(cc.Sequence.create( tintBlue, tintBlueBack ) );
|
||||
|
||||
sprite5.runAction(red);
|
||||
sprite6.runAction(green);
|
||||
sprite7.runAction(blue);
|
||||
sprite8.runAction(fade);
|
||||
|
||||
// late add: test dirtyColor and dirtyPosition
|
||||
this.addChild(batch);
|
||||
batch.addChild(sprite1);
|
||||
batch.addChild(sprite2);
|
||||
batch.addChild(sprite3);
|
||||
batch.addChild(sprite4);
|
||||
batch.addChild(sprite5);
|
||||
batch.addChild(sprite6);
|
||||
batch.addChild(sprite7);
|
||||
batch.addChild(sprite8);
|
||||
}
|
||||
|
||||
//
|
||||
// Instance methods
|
||||
//
|
||||
this.title = function () {
|
||||
return "Sprite Batch: Color & Opacity";
|
||||
}
|
||||
|
||||
this.subtitle = function () {
|
||||
return "testing opacity and color with batches";
|
||||
}
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
goog.inherits(SpriteBatchColorOpacity, BaseLayer );
|
||||
|
||||
//
|
||||
// Order of tests
|
||||
//
|
||||
scenes.push( SpriteTouchTest ); scenes.push( SpriteBatchTouchTest );
|
||||
|
||||
scenes.push( SpriteFrameTest );
|
||||
|
||||
scenes.push( SpriteAnchorPoint ); scenes.push( SpriteBatchAnchorPoint );
|
||||
|
||||
scenes.push( SpriteOffsetAnchorFlip ); scenes.push( SpriteBatchOffsetAnchorFlip );
|
||||
|
||||
scenes.push( SpriteColorOpacity ); scenes.push( SpriteBatchColorOpacity );
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Main entry point
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
function run()
|
||||
{
|
||||
var scene = cc.Scene.create();
|
||||
var layer = new scenes[currentScene]();
|
||||
scene.addChild( layer );
|
||||
|
||||
var runningScene = director.getRunningScene();
|
||||
if( runningScene == null )
|
||||
director.runWithScene( scene );
|
||||
else
|
||||
director.replaceScene( cc.TransitionFade.create(0.5, scene ) );
|
||||
}
|
||||
|
||||
run();
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -1,35 +0,0 @@
|
|||
// prepare the menu and other things
|
||||
|
||||
cc.Point.create = function (x, y) {
|
||||
var pt = new cc.Point();
|
||||
pt.x = x;
|
||||
pt.y = y;
|
||||
return pt;
|
||||
};
|
||||
|
||||
var pointZero = cc.Point.create(0, 0);
|
||||
|
||||
var director = cc.Director.sharedDirector;
|
||||
var winSize = director.winSize();
|
||||
|
||||
var hudMenu = new cc.Menu();
|
||||
|
||||
(function () {
|
||||
// we add the items as members of menu to avoid GC
|
||||
// ** otherwise the GC will try to remove the itemN object **
|
||||
hudMenu.item1 = new cc.MenuItemImage();
|
||||
item1.initWithNormalImage("b1.png", "b2.png");
|
||||
hudMenu.item2 = new cc.MenuItemImage();
|
||||
item2.initWithNormalImage("r1.png", "r2.png");
|
||||
hudMenu.item3 = new cc.MenuItemImage();
|
||||
item3.initWithNormalImage("f1.png", "f2.png");
|
||||
|
||||
hudMenu.addChild(menu.item1);
|
||||
hudMenu.addChild(menu.item2);
|
||||
hudMenu.addChild(menu.item3);
|
||||
hudMenu.position = pointZero;
|
||||
|
||||
hudMenu.item1.position = cc.Point.create(winSize.width / 2 - 100, 30);
|
||||
hudMenu.item2.position = cc.Point.create(winSize.width / 2 , 30);
|
||||
hudMenu.item3.position = cc.Point.create(winSize.width / 2 + 100, 30);
|
||||
})();
|
|
@ -1,305 +0,0 @@
|
|||
/*
|
||||
* showcasing actions
|
||||
*/
|
||||
|
||||
/**
|
||||
* simple wrappers
|
||||
*/
|
||||
cc.Point.create = function (x, y) {
|
||||
var pt = new cc.Point();
|
||||
pt.x = x;
|
||||
pt.y = y;
|
||||
return pt;
|
||||
};
|
||||
|
||||
cc.Size.create = function (w, h) {
|
||||
var sz = new cc.Size();
|
||||
sz.width = w;
|
||||
sz.height = h;
|
||||
return sz;
|
||||
};
|
||||
|
||||
cc.Sprite.create = function (file) {
|
||||
var s = new cc.Sprite();
|
||||
s.initWithFile(file);
|
||||
return s;
|
||||
};
|
||||
|
||||
var pointZero = cc.Point.create(0, 0);
|
||||
var sizeZero = cc.Size.create(0, 0);
|
||||
|
||||
var director = cc.Director.sharedDirector();
|
||||
var winSize = director.winSize;
|
||||
|
||||
var scenes = {};
|
||||
scenes.currentScene = 1;
|
||||
|
||||
/**
|
||||
* tests the most basic function: moveTo and moveBy
|
||||
*/
|
||||
scenes['test_move'] = function () {
|
||||
var s1 = cc.Sprite.create("grossini_dance_05.png");
|
||||
s1.position = cc.Point.create(winSize.width / 2 + 50, winSize.height / 2);
|
||||
var s2 = cc.Sprite.create("grossinis_sister1.png");
|
||||
s2.position = cc.Point.create(winSize.width / 2 - 50, winSize.height / 2);
|
||||
|
||||
var moveTo = new cc.MoveTo();
|
||||
moveTo.initWithDuration(2.0, cc.Point.create(winSize.width, winSize.height / 2));
|
||||
var moveBy = new cc.MoveBy();
|
||||
moveBy.initWithDuration(2.0, cc.Point.create(100, 100));
|
||||
|
||||
s1.runAction(moveTo);
|
||||
s2.runAction(moveBy);
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
scene.addChild(s1);
|
||||
scene.addChild(s2);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Test Move");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
scenes['test_rotate'] = function () {
|
||||
var s1 = cc.Sprite.create("grossini_dance_05.png");
|
||||
s1.position = cc.Point.create(winSize.width / 2 + 50, winSize.height / 2);
|
||||
var s2 = cc.Sprite.create("grossinis_sister1.png");
|
||||
s2.rotation = 90;
|
||||
s2.position = cc.Point.create(winSize.width / 2 - 100, winSize.height / 2);
|
||||
|
||||
var rotateTo = new cc.RotateTo();
|
||||
rotateTo.initWithDuration(1.0, 180.0);
|
||||
var rotateBy = new cc.RotateBy();
|
||||
rotateBy.initWithDuration(2.0, 90);
|
||||
|
||||
s1.runAction(rotateTo);
|
||||
s2.runAction(rotateBy);
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
scene.addChild(s1);
|
||||
scene.addChild(s2);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Test Rotate");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
scenes['test_animation'] = function () {
|
||||
var spriteFrameCache = cc.SpriteFrameCache.sharedSpriteFrameCache();
|
||||
spriteFrameCache.addSpriteFramesWithFile("tank.plist");
|
||||
|
||||
// create a new sprite with a sprite frame
|
||||
var sprite = new cc.Sprite();
|
||||
sprite.initWithSpriteFrameName("tank1.png");
|
||||
sprite.position = cc.Point.create(winSize.width / 2, winSize.height / 2);
|
||||
|
||||
// create animation
|
||||
var frames = ["tank1.png", "tank2.png", "tank3.png", "tank4.png", "tank5.png"];
|
||||
var animation = new cc.Animation();
|
||||
animation.init();
|
||||
// set the delay
|
||||
animation.delayPerUnit = 0.1;
|
||||
// add the frames
|
||||
for (var i=0; i < frames.length; i++) {
|
||||
var frame = spriteFrameCache.spriteFrameByName(frames[i]);
|
||||
animation.addSpriteFrame(frame);
|
||||
}
|
||||
// action stored in the sprite to avoid GC
|
||||
sprite.anim = new cc.Animate();
|
||||
sprite.anim.initWithAnimation(animation);
|
||||
sprite.runAction(sprite.anim);
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
scene.addChild(sprite);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Test Animation");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
scenes['test_repeat'] = function () {
|
||||
var s1 = cc.Sprite.create("grossinis_sister1.png");
|
||||
s1.position = cc.Point.create(winSize.width / 2, winSize.height / 2);
|
||||
|
||||
var rotateBy = new cc.RotateBy();
|
||||
rotateBy.initWithDuration(1.0, 90);
|
||||
|
||||
var repeat = new cc.RepeatForever();
|
||||
repeat.initWithAction(rotateBy);
|
||||
|
||||
s1.runAction(repeat);
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
scene.addChild(s1);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Test Repeat");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
scenes['test_sequence'] = function () {
|
||||
var s1 = cc.Sprite.create("grossini_dance_05.png");
|
||||
s1.position = cc.Point.create(winSize.width / 2 + 50, winSize.height / 2);
|
||||
|
||||
var rotate1 = new cc.RotateBy();
|
||||
rotate1.initWithDuration(1.0, 90);
|
||||
var moveBy = new cc.MoveBy();
|
||||
moveBy.initWithDuration(2.0, cc.Point.create(100, 100));
|
||||
var rotate2 = rotate1.reverse();
|
||||
var delay = cc.DelayTime.actionWithDuration(1.5);
|
||||
|
||||
var seq = cc.Sequence.actions(rotate1, moveBy, delay, rotate2);
|
||||
s1.runAction(seq);
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
scene.addChild(s1);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Test Sequence");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
scenes['test_wave3d'] = function () {
|
||||
var node = new cc.Node();
|
||||
var s1 = cc.Sprite.create("grossini_dance_05.png");
|
||||
s1.position = cc.Point.create(winSize.width / 2 + 50, winSize.height / 2);
|
||||
|
||||
var rotate1 = new cc.RotateBy();
|
||||
rotate1.initWithDuration(1.0, 90);
|
||||
var moveBy = new cc.MoveBy();
|
||||
moveBy.initWithDuration(2.0, cc.Point.create(100, 100));
|
||||
var rotate2 = rotate1.reverse();
|
||||
var delay = cc.DelayTime.actionWithDuration(1.5);
|
||||
|
||||
var seq = cc.Sequence.actions(rotate1, moveBy, delay, rotate2);
|
||||
s1.runAction(seq);
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
node.addChild(s1);
|
||||
|
||||
// simple wave 3d
|
||||
var gridSize = new cc.GridSize;
|
||||
gridSize.x = 15;
|
||||
gridSize.y = 10;
|
||||
var wave = cc.Waves3D.actionWithWaves(5, 40, gridSize, 3);
|
||||
scene.runAction(wave);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Test Sequence");
|
||||
scene.addChild(node);
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* from here on there's code that can be shared between different tests
|
||||
* basically is the hud and the scene handling
|
||||
*/
|
||||
|
||||
// changes to the next scene
|
||||
var nextScene = function () {
|
||||
var l = Object.keys(scenes).length;
|
||||
scenes.currentScene = (scenes.currentScene + 1) % l;
|
||||
if (scenes.currentScene === 0) {
|
||||
scenes.currentScene = 1;
|
||||
}
|
||||
playCurrentScene();
|
||||
};
|
||||
|
||||
// changes to the previous scene
|
||||
var prevScene = function () {
|
||||
var l = Object.keys(scenes).length;
|
||||
scenes.currentScene -= 1;
|
||||
if (scenes.currentScene < 1) {
|
||||
scenes.currentScene = l - 1;
|
||||
}
|
||||
playCurrentScene();
|
||||
};
|
||||
|
||||
var playCurrentScene = function () {
|
||||
var name = Object.keys(scenes)[scenes.currentScene];
|
||||
var scene = scenes[name]();
|
||||
// cc.log("running scene: " + name + "(" + scene + ")");
|
||||
if (director.runningScene === null) {
|
||||
director.runWithScene(scene);
|
||||
} else {
|
||||
director.replaceScene(scene);
|
||||
}
|
||||
};
|
||||
|
||||
// creates the hud
|
||||
var createMenu = function (labelText) {
|
||||
var hudMenu = new cc.Menu();
|
||||
hudMenu.init();
|
||||
|
||||
var b1 = new cc.Sprite(); b1.initWithFile("b1.png");
|
||||
var b2 = new cc.Sprite(); b2.initWithFile("b2.png");
|
||||
item1 = new cc.MenuItemSprite();
|
||||
item1.initWithNormalSprite(b1, b2);
|
||||
item1.action = function () {
|
||||
prevScene();
|
||||
};
|
||||
|
||||
var r1 = new cc.Sprite(); r1.initWithFile("r1.png");
|
||||
var r2 = new cc.Sprite(); r2.initWithFile("r2.png");
|
||||
item2 = new cc.MenuItemSprite();
|
||||
item2.initWithNormalSprite(r1, r2);
|
||||
item2.action = function () {
|
||||
// cc.executeScript("JS/1to1/test_actions.js");
|
||||
playCurrentScene();
|
||||
};
|
||||
|
||||
var f1 = new cc.Sprite(); f1.initWithFile("f1.png");
|
||||
var f2 = new cc.Sprite(); f2.initWithFile("f2.png");
|
||||
item3 = new cc.MenuItemSprite();
|
||||
item3.initWithNormalSprite(f1, f2);
|
||||
item3.action = function () {
|
||||
nextScene();
|
||||
};
|
||||
|
||||
var c1 = new cc.Sprite(); c1.initWithFile("r1.png");
|
||||
var c2 = new cc.Sprite(); c2.initWithFile("r2.png");
|
||||
item4 = new cc.MenuItemSprite();
|
||||
item4.initWithNormalSprite(c1, c2);
|
||||
item4.action = function () {
|
||||
cc.executeScript("JS/1to1/test_actions.js");
|
||||
};
|
||||
|
||||
item1.position = cc.Point.create(winSize.width / 2 - 100, 30);
|
||||
item2.position = cc.Point.create(winSize.width / 2 , 30);
|
||||
item3.position = cc.Point.create(winSize.width / 2 + 100, 30);
|
||||
item4.position = cc.Point.create(30, winSize.height - 30);
|
||||
|
||||
hudMenu.addChild(item1);
|
||||
hudMenu.addChild(item2);
|
||||
hudMenu.addChild(item3);
|
||||
hudMenu.addChild(item4);
|
||||
hudMenu.position = pointZero;
|
||||
|
||||
if (labelText) {
|
||||
var label = new cc.LabelTTF();
|
||||
// initWithString: text, size, alignment, font, fontSize
|
||||
label.initWithString(labelText, sizeZero, 0, "Arial", 18.0);
|
||||
var menuLabel = new cc.MenuItemLabel();
|
||||
menuLabel.initWithLabel(label);
|
||||
menuLabel.position = cc.Point.create(winSize.width / 2, winSize.height - 30);
|
||||
hudMenu.addChild(menuLabel);
|
||||
}
|
||||
|
||||
// just to avoid GC
|
||||
hudMenu.items = [item1, item2, item3];
|
||||
return hudMenu;
|
||||
};
|
||||
|
||||
playCurrentScene();
|
|
@ -1,42 +0,0 @@
|
|||
// this is to test the test bindings :)
|
||||
|
||||
var simple1 = new SimpleNativeClass();
|
||||
|
||||
// testing the getters and the constructor (that set some fields)
|
||||
cc.log("someField: " + simple1.someField);
|
||||
cc.log("someOtherField: " + simple1.someOtherField);
|
||||
cc.log("anotherMoreComplexField: " + simple1.anotherMoreComplexField);
|
||||
|
||||
// testing the setters
|
||||
simple1.someField = 1313;
|
||||
simple1.someOtherField = 999;
|
||||
simple1.anotherMoreComplexField = "this is a js string";
|
||||
|
||||
cc.log("someField: " + simple1.someField);
|
||||
cc.log("someOtherField: " + simple1.someOtherField);
|
||||
cc.log("anotherMoreComplexField: " + simple1.anotherMoreComplexField);
|
||||
|
||||
// testing std::string conversion
|
||||
|
||||
cc.log("someProcessing: " + simple1.doSomeProcessing("this is some js string", "this is another javascript string"));
|
||||
|
||||
|
||||
var another = new AnotherClass();
|
||||
// testing the getters and the constructor (that set some fields)
|
||||
cc.log("justOneField: " + another.justOneField);
|
||||
cc.log("aPublicField: " + another.aPublicField);
|
||||
|
||||
// testing setters, the setter for justOneField should not work (since it's not defined correctly in the native class)
|
||||
another.justOneField = 8888;
|
||||
another.aPublicField = 6667;
|
||||
cc.log("justOneField: " + another.justOneField);
|
||||
cc.log("aPublicField: " + another.aPublicField);
|
||||
|
||||
// should print something in stderr
|
||||
another.doSomethingSimple();
|
||||
|
||||
//should print the enum
|
||||
cc.log("enum: " + someThingEnumerated.kValue1);
|
||||
cc.log("enum: " + someThingEnumerated.kValue2);
|
||||
cc.log("enum: " + someThingEnumerated.kValue3);
|
||||
cc.log("enum: " + someThingEnumerated.kValue4);
|
|
@ -1,572 +0,0 @@
|
|||
/*
|
||||
* showcasing actions
|
||||
*/
|
||||
|
||||
/**
|
||||
* simple wrappers
|
||||
*/
|
||||
cc.Point.create = function (x, y) {
|
||||
var pt = new cc.Point();
|
||||
pt.x = x;
|
||||
pt.y = y;
|
||||
return pt;
|
||||
};
|
||||
|
||||
cc.Size.create = function (w, h) {
|
||||
var sz = new cc.Size();
|
||||
sz.width = w;
|
||||
sz.height = h;
|
||||
return sz;
|
||||
};
|
||||
|
||||
cc.Sprite.create = function (file) {
|
||||
var s = new cc.Sprite();
|
||||
s.initWithFile(file);
|
||||
return s;
|
||||
};
|
||||
|
||||
var pointZero = cc.Point.create(0, 0);
|
||||
var sizeZero = cc.Size.create(0, 0);
|
||||
|
||||
var director = cc.Director.sharedDirector();
|
||||
var winSize = director.winSize;
|
||||
|
||||
var scenes = {};
|
||||
scenes.currentScene = 1;
|
||||
|
||||
//
|
||||
// EaseIn / EaseOut
|
||||
//
|
||||
scenes['test_easein'] = function () {
|
||||
var s1 = new cc.Sprite.create("grossinis_sister1.png");
|
||||
s1.position = cc.Point.create(50, winSize.height * 3 / 4 );
|
||||
|
||||
var s2 = new cc.Sprite.create("grossini_dance_05.png");
|
||||
s2.position = cc.Point.create(50, winSize.height * 2 / 4);
|
||||
|
||||
var s3 = new cc.Sprite.create("grossinis_sister2.png");
|
||||
s3.position = cc.Point.create(50, winSize.height * 1 / 4);
|
||||
|
||||
var moveBy1 = new cc.MoveBy();
|
||||
var moveBy2 = new cc.MoveBy();
|
||||
var moveBy3 = new cc.MoveBy();
|
||||
|
||||
moveBy1.initWithDuration(2.0, cc.Point.create( winSize.width-100, 0));
|
||||
moveBy2.initWithDuration(2.0, cc.Point.create( winSize.width-100, 0));
|
||||
moveBy3.initWithDuration(2.0, cc.Point.create( winSize.width-100, 0));
|
||||
|
||||
var easein = cc.EaseIn.actionWithAction(moveBy1, 0.2);
|
||||
var easein_back = cc.EaseIn.actionWithAction( moveBy1.reverse(), 1/0.2 );
|
||||
var seq1 = cc.Sequence.actions(easein, easein_back);
|
||||
s1.runAction(seq1);
|
||||
|
||||
var seq2 = cc.Sequence.actions(moveBy2, moveBy2.reverse());
|
||||
s2.runAction(seq2);
|
||||
|
||||
var easeout = cc.EaseOut.actionWithAction(moveBy3, 0.2);
|
||||
var seq3 = cc.Sequence.actions(easeout, easeout.reverse());
|
||||
s3.runAction(seq3);
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
scene.addChild(s1);
|
||||
scene.addChild(s2);
|
||||
scene.addChild(s3);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Test EaseIn / EaseOut");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
//
|
||||
// EaseIn / EaseOut
|
||||
//
|
||||
scenes['test_easeinout'] = function () {
|
||||
|
||||
var s1 = new cc.Sprite.create("grossinis_sister1.png");
|
||||
s1.position = cc.Point.create(50, winSize.height * 3 / 4 );
|
||||
|
||||
var s2 = new cc.Sprite.create("grossini_dance_05.png");
|
||||
s2.position = cc.Point.create(50, winSize.height * 2 / 4);
|
||||
|
||||
var s3 = new cc.Sprite.create("grossinis_sister2.png");
|
||||
s3.position = cc.Point.create(50, winSize.height * 1 / 4);
|
||||
|
||||
|
||||
var move1 = cc.MoveBy.actionWithDuration(3, cc.Point.create(winSize.width-130,0) );
|
||||
var move2 = cc.MoveBy.actionWithDuration(3, cc.Point.create(winSize.width-130,0) );
|
||||
var move3 = cc.MoveBy.actionWithDuration(3, cc.Point.create(winSize.width-130,0) );
|
||||
|
||||
var move_ease_inout1 = cc.EaseInOut.actionWithAction( move1, 2 );
|
||||
var move_ease_inout_back1 = move_ease_inout1.reverse();
|
||||
|
||||
var move_ease_inout2 = cc.EaseInOut.actionWithAction( move2, 3 );
|
||||
var move_ease_inout_back2 = move_ease_inout2.reverse();
|
||||
|
||||
var move_ease_inout3 = cc.EaseInOut.actionWithAction( move3, 4 );
|
||||
var move_ease_inout_back3 = move_ease_inout3.reverse();
|
||||
|
||||
// var delay = [CCDelayTime actionWithDuration:0.25f];
|
||||
|
||||
var seq1 = cc.Sequence.actions( move_ease_inout1, move_ease_inout_back1 );
|
||||
var seq2 = cc.Sequence.actions( move_ease_inout2, move_ease_inout_back2 );
|
||||
var seq3 = cc.Sequence.actions( move_ease_inout3, move_ease_inout_back3 );
|
||||
|
||||
s1.runAction( cc.RepeatForever.actionWithAction( seq1 ) );
|
||||
s2.runAction( cc.RepeatForever.actionWithAction( seq2 ) );
|
||||
s3.runAction( cc.RepeatForever.actionWithAction( seq3 ) );
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
scene.addChild(s1);
|
||||
scene.addChild(s2);
|
||||
scene.addChild(s3);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Test EaseInOut and reverse");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
//
|
||||
// Ease BounceIn / Out
|
||||
//
|
||||
scenes['test_bouncein'] = function () {
|
||||
var s1 = new cc.Sprite.create("grossinis_sister1.png");
|
||||
s1.position = cc.Point.create(50, winSize.height * 3 / 4 );
|
||||
|
||||
var s2 = new cc.Sprite.create("grossini_dance_05.png");
|
||||
s2.position = cc.Point.create(50, winSize.height * 2 / 4);
|
||||
|
||||
var s3 = new cc.Sprite.create("grossinis_sister2.png");
|
||||
s3.position = cc.Point.create(50, winSize.height * 1 / 4);
|
||||
|
||||
var move1 = cc.MoveBy.actionWithDuration(3, cc.Point.create(winSize.width-130,0) );
|
||||
var move2 = cc.MoveBy.actionWithDuration(3, cc.Point.create(winSize.width-130,0) );
|
||||
var move3 = cc.MoveBy.actionWithDuration(3, cc.Point.create(winSize.width-130,0) );
|
||||
|
||||
var move1_back = move1.reverse();
|
||||
|
||||
var move_ease_in = cc.EaseBounceIn.actionWithAction( move2 );
|
||||
var move_ease_in_back = move_ease_in.reverse();
|
||||
|
||||
var move_ease_out = cc.EaseBounceOut.actionWithAction( move3 );
|
||||
var move_ease_out_back = move_ease_out.reverse();
|
||||
|
||||
var seq1 = cc.Sequence.actions( move1, move1_back );
|
||||
var seq2 = cc.Sequence.actions( move_ease_in, move_ease_in_back );
|
||||
var seq3 = cc.Sequence.actions( move_ease_out, move_ease_out_back );
|
||||
|
||||
s1.runAction( cc.RepeatForever.actionWithAction( seq1 ) );
|
||||
s2.runAction( cc.RepeatForever.actionWithAction( seq2 ) );
|
||||
s3.runAction( cc.RepeatForever.actionWithAction( seq3 ) );
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
scene.addChild(s1);
|
||||
scene.addChild(s2);
|
||||
scene.addChild(s3);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Test EaseBounceIn / Out and reverse");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
//
|
||||
// Ease BounceInOut
|
||||
//
|
||||
scenes['test_bounceinout'] = function () {
|
||||
|
||||
var s1 = new cc.Sprite.create("grossinis_sister1.png");
|
||||
s1.position = cc.Point.create(50, winSize.height * 3 / 4 );
|
||||
|
||||
var s2 = new cc.Sprite.create("grossinis_sister2.png");
|
||||
s2.position = cc.Point.create(50, winSize.height * 1 / 4);
|
||||
|
||||
|
||||
var move1 = cc.MoveBy.actionWithDuration(3, cc.Point.create(winSize.width-130,0) );
|
||||
var move2 = cc.MoveBy.actionWithDuration(3, cc.Point.create(winSize.width-130,0) );
|
||||
|
||||
var move1_back = move1.reverse();
|
||||
|
||||
var move_ease = cc.EaseBounceInOut.actionWithAction( move2 );
|
||||
var move_ease_back = move_ease.reverse();
|
||||
|
||||
var seq1 = cc.Sequence.actions( move1, move1_back );
|
||||
var seq2 = cc.Sequence.actions( move_ease, move_ease_back );
|
||||
|
||||
|
||||
s1.runAction( cc.RepeatForever.actionWithAction( seq1 ) );
|
||||
s2.runAction( cc.RepeatForever.actionWithAction( seq2 ) );
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
scene.addChild(s1);
|
||||
scene.addChild(s2);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Test EaseBounceInOut + reverse");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
//
|
||||
// EaseBackIn / Out
|
||||
//
|
||||
scenes['test_backin_out'] = function () {
|
||||
|
||||
var s1 = new cc.Sprite.create("grossinis_sister1.png");
|
||||
s1.position = cc.Point.create(50, winSize.height * 3 / 4 );
|
||||
|
||||
var s2 = new cc.Sprite.create("grossini_dance_05.png");
|
||||
s2.position = cc.Point.create(50, winSize.height * 2 / 4);
|
||||
|
||||
var s3 = new cc.Sprite.create("grossinis_sister2.png");
|
||||
s3.position = cc.Point.create(50, winSize.height * 1 / 4);
|
||||
|
||||
|
||||
var move1 = cc.MoveBy.actionWithDuration(3, cc.Point.create(winSize.width-130,0) );
|
||||
var move2 = cc.MoveBy.actionWithDuration(3, cc.Point.create(winSize.width-130,0) );
|
||||
var move3 = cc.MoveBy.actionWithDuration(3, cc.Point.create(winSize.width-130,0) );
|
||||
|
||||
var move1_back = move1.reverse();
|
||||
|
||||
|
||||
var move_ease_in = cc.EaseBackIn.actionWithAction( move2 );
|
||||
var move_ease_in_back = move_ease_in.reverse();
|
||||
|
||||
var move_ease_out = cc.EaseBackOut.actionWithAction( move3 );
|
||||
var move_ease_out_back = move_ease_out.reverse();
|
||||
|
||||
var seq1 = cc.Sequence.actions( move1, move1_back );
|
||||
var seq2 = cc.Sequence.actions( move_ease_in, move_ease_in_back );
|
||||
var seq3 = cc.Sequence.actions( move_ease_out, move_ease_out_back );
|
||||
|
||||
s1.runAction( cc.RepeatForever.actionWithAction( seq1 ) );
|
||||
s2.runAction( cc.RepeatForever.actionWithAction( seq2 ) );
|
||||
s3.runAction( cc.RepeatForever.actionWithAction( seq3 ) );
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
scene.addChild(s1);
|
||||
scene.addChild(s2);
|
||||
scene.addChild(s3);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Test EaseBackIn / Out and reverse");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
//
|
||||
// EaseBackInOut
|
||||
//
|
||||
scenes['test_backinout'] = function () {
|
||||
|
||||
var s1 = new cc.Sprite.create("grossinis_sister1.png");
|
||||
s1.position = cc.Point.create(50, winSize.height * 3 / 4 );
|
||||
|
||||
var s2 = new cc.Sprite.create("grossinis_sister2.png");
|
||||
s2.position = cc.Point.create(50, winSize.height * 1 / 4);
|
||||
|
||||
|
||||
var move1 = cc.MoveBy.actionWithDuration(3, cc.Point.create(winSize.width-130,0) );
|
||||
var move2 = cc.MoveBy.actionWithDuration(3, cc.Point.create(winSize.width-130,0) );
|
||||
|
||||
var move1_back = move1.reverse();
|
||||
|
||||
var move_ease = cc.EaseBackInOut.actionWithAction( move2 );
|
||||
var move_ease_back = move_ease.reverse();
|
||||
|
||||
var seq1 = cc.Sequence.actions( move1, move1_back );
|
||||
var seq2 = cc.Sequence.actions( move_ease, move_ease_back );
|
||||
|
||||
|
||||
s1.runAction( cc.RepeatForever.actionWithAction( seq1 ) );
|
||||
s2.runAction( cc.RepeatForever.actionWithAction( seq2 ) );
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
scene.addChild(s1);
|
||||
scene.addChild(s2);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Test EaseBackInOut + reverse");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
//
|
||||
// EaseBounceIn / Out
|
||||
//
|
||||
scenes['test_sinein_out'] = function () {
|
||||
|
||||
var s1 = new cc.Sprite.create("grossinis_sister1.png");
|
||||
s1.position = cc.Point.create(50, winSize.height * 3 / 4 );
|
||||
|
||||
var s2 = new cc.Sprite.create("grossini_dance_05.png");
|
||||
s2.position = cc.Point.create(50, winSize.height * 2 / 4);
|
||||
|
||||
var s3 = new cc.Sprite.create("grossinis_sister2.png");
|
||||
s3.position = cc.Point.create(50, winSize.height * 1 / 4);
|
||||
|
||||
|
||||
var move1 = cc.MoveBy.actionWithDuration(3, cc.Point.create(winSize.width-130,0) );
|
||||
var move2 = cc.MoveBy.actionWithDuration(3, cc.Point.create(winSize.width-130,0) );
|
||||
var move3 = cc.MoveBy.actionWithDuration(3, cc.Point.create(winSize.width-130,0) );
|
||||
|
||||
var move1_back = move1.reverse();
|
||||
|
||||
|
||||
var move_ease_in = cc.EaseSineIn.actionWithAction( move2 );
|
||||
var move_ease_in_back = move_ease_in.reverse();
|
||||
|
||||
var move_ease_out = cc.EaseSineOut.actionWithAction( move3 );
|
||||
var move_ease_out_back = move_ease_out.reverse();
|
||||
|
||||
var seq1 = cc.Sequence.actions( move1, move1_back );
|
||||
var seq2 = cc.Sequence.actions( move_ease_in, move_ease_in_back );
|
||||
var seq3 = cc.Sequence.actions( move_ease_out, move_ease_out_back );
|
||||
|
||||
s1.runAction( cc.RepeatForever.actionWithAction( seq1 ) );
|
||||
s2.runAction( cc.RepeatForever.actionWithAction( seq2 ) );
|
||||
s3.runAction( cc.RepeatForever.actionWithAction( seq3 ) );
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
scene.addChild(s1);
|
||||
scene.addChild(s2);
|
||||
scene.addChild(s3);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Test EaseSineIn / Out and reverse");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
//
|
||||
// EaseSineInOut
|
||||
//
|
||||
scenes['test_sineinout'] = function () {
|
||||
|
||||
var s1 = new cc.Sprite.create("grossinis_sister1.png");
|
||||
s1.position = cc.Point.create(50, winSize.height * 3 / 4 );
|
||||
|
||||
var s2 = new cc.Sprite.create("grossinis_sister2.png");
|
||||
s2.position = cc.Point.create(50, winSize.height * 1 / 4);
|
||||
|
||||
|
||||
var move1 = cc.MoveBy.actionWithDuration(3, cc.Point.create(winSize.width-130,0) );
|
||||
var move2 = cc.MoveBy.actionWithDuration(3, cc.Point.create(winSize.width-130,0) );
|
||||
|
||||
var move1_back = move1.reverse();
|
||||
|
||||
var move_ease = cc.EaseSineInOut.actionWithAction( move2 );
|
||||
var move_ease_back = move_ease.reverse();
|
||||
|
||||
var seq1 = cc.Sequence.actions( move1, move1_back );
|
||||
var seq2 = cc.Sequence.actions( move_ease, move_ease_back );
|
||||
|
||||
|
||||
s1.runAction( cc.RepeatForever.actionWithAction( seq1 ) );
|
||||
s2.runAction( cc.RepeatForever.actionWithAction( seq2 ) );
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
scene.addChild(s1);
|
||||
scene.addChild(s2);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Test EaseSineInOut + reverse");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
//
|
||||
// EaseElasticIn / Out
|
||||
//
|
||||
scenes['test_elasticin_out'] = function () {
|
||||
|
||||
var s1 = new cc.Sprite.create("grossinis_sister1.png");
|
||||
s1.position = cc.Point.create(50, winSize.height * 3 / 4 );
|
||||
|
||||
var s2 = new cc.Sprite.create("grossini_dance_05.png");
|
||||
s2.position = cc.Point.create(50, winSize.height * 2 / 4);
|
||||
|
||||
var s3 = new cc.Sprite.create("grossinis_sister2.png");
|
||||
s3.position = cc.Point.create(50, winSize.height * 1 / 4);
|
||||
|
||||
|
||||
var move1 = cc.MoveBy.actionWithDuration(3, cc.Point.create(winSize.width-130,0) );
|
||||
var move2 = cc.MoveBy.actionWithDuration(3, cc.Point.create(winSize.width-130,0) );
|
||||
var move3 = cc.MoveBy.actionWithDuration(3, cc.Point.create(winSize.width-130,0) );
|
||||
|
||||
var move1_back = move1.reverse();
|
||||
|
||||
var move_ease_in = cc.EaseElasticIn.actionWithAction( move2 );
|
||||
var move_ease_in_back = move_ease_in.reverse();
|
||||
|
||||
var move_ease_out = cc.EaseElasticOut.actionWithAction( move3 );
|
||||
var move_ease_out_back = move_ease_out.reverse();
|
||||
|
||||
var seq1 = cc.Sequence.actions( move1, move1_back );
|
||||
var seq2 = cc.Sequence.actions( move_ease_in, move_ease_in_back );
|
||||
var seq3 = cc.Sequence.actions( move_ease_out, move_ease_out_back );
|
||||
|
||||
s1.runAction( cc.RepeatForever.actionWithAction( seq1 ) );
|
||||
s2.runAction( cc.RepeatForever.actionWithAction( seq2 ) );
|
||||
s3.runAction( cc.RepeatForever.actionWithAction( seq3 ) );
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
scene.addChild(s1);
|
||||
scene.addChild(s2);
|
||||
scene.addChild(s3);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Test EaseElasticIn / Out and reverse");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
//
|
||||
// EaseElasticInOut
|
||||
//
|
||||
scenes['test_elasticinout'] = function () {
|
||||
|
||||
var s1 = new cc.Sprite.create("grossinis_sister1.png");
|
||||
s1.position = cc.Point.create(50, winSize.height * 3 / 4 );
|
||||
|
||||
var s2 = new cc.Sprite.create("grossinis_sister2.png");
|
||||
s2.position = cc.Point.create(50, winSize.height * 1 / 4);
|
||||
|
||||
|
||||
var move1 = cc.MoveBy.actionWithDuration(3, cc.Point.create(winSize.width-130,0) );
|
||||
var move2 = cc.MoveBy.actionWithDuration(3, cc.Point.create(winSize.width-130,0) );
|
||||
|
||||
var move1_back = move1.reverse();
|
||||
|
||||
var move_ease = cc.EaseElasticInOut.actionWithAction( move2 );
|
||||
var move_ease_back = move_ease.reverse();
|
||||
|
||||
var seq1 = cc.Sequence.actions( move1, move1_back );
|
||||
var seq2 = cc.Sequence.actions( move_ease, move_ease_back );
|
||||
|
||||
|
||||
s1.runAction( cc.RepeatForever.actionWithAction( seq1 ) );
|
||||
s2.runAction( cc.RepeatForever.actionWithAction( seq2 ) );
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
scene.addChild(s1);
|
||||
scene.addChild(s2);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Test EaseElasticInOut + reverse");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
/**
|
||||
* from here on there's code that can be shared between different tests
|
||||
* basically is the hud and the scene handling
|
||||
*/
|
||||
|
||||
// changes to the next scene
|
||||
var nextScene = function () {
|
||||
var l = Object.keys(scenes).length;
|
||||
scenes.currentScene = (scenes.currentScene + 1) % l;
|
||||
if (scenes.currentScene === 0) {
|
||||
scenes.currentScene = 1;
|
||||
}
|
||||
playCurrentScene();
|
||||
};
|
||||
|
||||
// changes to the previous scene
|
||||
var prevScene = function () {
|
||||
var l = Object.keys(scenes).length;
|
||||
scenes.currentScene -= 1;
|
||||
if (scenes.currentScene < 1) {
|
||||
scenes.currentScene = l - 1;
|
||||
}
|
||||
playCurrentScene();
|
||||
};
|
||||
|
||||
var playCurrentScene = function () {
|
||||
var name = Object.keys(scenes)[scenes.currentScene];
|
||||
var scene = scenes[name]();
|
||||
// cc.log("running scene: " + name + "(" + scene + ")");
|
||||
if (director.runningScene === null) {
|
||||
director.runWithScene(scene);
|
||||
} else {
|
||||
director.replaceScene(scene);
|
||||
}
|
||||
};
|
||||
|
||||
// creates the hud
|
||||
var createMenu = function (labelText) {
|
||||
var hudMenu = new cc.Menu();
|
||||
hudMenu.init();
|
||||
|
||||
var b1 = new cc.Sprite(); b1.initWithFile("b1.png");
|
||||
var b2 = new cc.Sprite(); b2.initWithFile("b2.png");
|
||||
item1 = new cc.MenuItemSprite();
|
||||
item1.initWithNormalSprite(b1, b2);
|
||||
item1.action = function () {
|
||||
prevScene();
|
||||
};
|
||||
|
||||
var r1 = new cc.Sprite(); r1.initWithFile("r1.png");
|
||||
var r2 = new cc.Sprite(); r2.initWithFile("r2.png");
|
||||
item2 = new cc.MenuItemSprite();
|
||||
item2.initWithNormalSprite(r1, r2);
|
||||
item2.action = function () {
|
||||
// cc.executeScript("JS/1to1/test_actions.js");
|
||||
playCurrentScene();
|
||||
};
|
||||
|
||||
var f1 = new cc.Sprite(); f1.initWithFile("f1.png");
|
||||
var f2 = new cc.Sprite(); f2.initWithFile("f2.png");
|
||||
item3 = new cc.MenuItemSprite();
|
||||
item3.initWithNormalSprite(f1, f2);
|
||||
item3.action = function () {
|
||||
nextScene();
|
||||
};
|
||||
|
||||
var c1 = new cc.Sprite(); c1.initWithFile("r1.png");
|
||||
var c2 = new cc.Sprite(); c2.initWithFile("r2.png");
|
||||
item4 = new cc.MenuItemSprite();
|
||||
item4.initWithNormalSprite(c1, c2);
|
||||
item4.action = function () {
|
||||
cc.executeScript("JS/1to1/test_ease_actions.js");
|
||||
};
|
||||
|
||||
item1.position = cc.Point.create(winSize.width / 2 - 100, 30);
|
||||
item2.position = cc.Point.create(winSize.width / 2 , 30);
|
||||
item3.position = cc.Point.create(winSize.width / 2 + 100, 30);
|
||||
item4.position = cc.Point.create(30, winSize.height - 30);
|
||||
|
||||
hudMenu.addChild(item1);
|
||||
hudMenu.addChild(item2);
|
||||
hudMenu.addChild(item3);
|
||||
hudMenu.addChild(item4);
|
||||
hudMenu.position = pointZero;
|
||||
|
||||
if (labelText) {
|
||||
var label = new cc.LabelTTF();
|
||||
// initWithString: text, size, alignment, font, fontSize
|
||||
label.initWithString(labelText, sizeZero, 0, "Arial", 18.0);
|
||||
var menuLabel = new cc.MenuItemLabel();
|
||||
menuLabel.initWithLabel(label);
|
||||
menuLabel.position = cc.Point.create(winSize.width / 2, winSize.height - 30);
|
||||
hudMenu.addChild(menuLabel);
|
||||
}
|
||||
|
||||
// just to avoid GC
|
||||
hudMenu.items = [item1, item2, item3];
|
||||
return hudMenu;
|
||||
};
|
||||
|
||||
playCurrentScene();
|
|
@ -1,206 +0,0 @@
|
|||
/*
|
||||
* showcasing layer and touch events
|
||||
*/
|
||||
|
||||
/**
|
||||
* simple wrappers
|
||||
*/
|
||||
cc.Point.create = function (x, y) {
|
||||
var pt = new cc.Point();
|
||||
pt.x = x;
|
||||
pt.y = y;
|
||||
return pt;
|
||||
};
|
||||
|
||||
cc.Size.create = function (w, h) {
|
||||
var sz = new cc.Size();
|
||||
sz.width = w;
|
||||
sz.height = h;
|
||||
return sz;
|
||||
};
|
||||
|
||||
cc.Sprite.create = function (file) {
|
||||
var s = new cc.Sprite();
|
||||
s.initWithFile(file);
|
||||
return s;
|
||||
};
|
||||
|
||||
var pointZero = cc.Point.create(0, 0);
|
||||
var sizeZero = cc.Size.create(0, 0);
|
||||
|
||||
var director = cc.Director.sharedDirector();
|
||||
var winSize = director.winSize;
|
||||
|
||||
var scenes = {};
|
||||
scenes.currentScene = 1;
|
||||
|
||||
/**
|
||||
* tests the most basic function: moveTo and moveBy
|
||||
*/
|
||||
scenes['test_layer_1'] = function () {
|
||||
var layer = new cc.Layer(); layer.init();
|
||||
layer.isTouchEnabled = true;
|
||||
layer.ccTouchesBegan = function (touches) {
|
||||
for (var i in touches) {
|
||||
var pt = touches[i].locationInView();
|
||||
pt = director.convertToGL(pt);
|
||||
var s = new cc.Sprite.create("grossinis_sister1.png");
|
||||
s.position = pt;
|
||||
s.rotation = Math.random() * 360;
|
||||
this.addChild(s);
|
||||
}
|
||||
};
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
scene.addChild(layer);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Test Layer 1");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
scenes['test_layer_2'] = function () {
|
||||
var layer = new cc.Layer(); layer.init();
|
||||
layer.isTouchEnabled = true;
|
||||
layer.currentSprite = null;
|
||||
|
||||
layer.ccTouchesBegan = function (touches) {
|
||||
for (var i in touches) {
|
||||
var pt = touches[i].locationInView();
|
||||
pt = director.convertToGL(pt);
|
||||
var s = new cc.Sprite.create("grossinis_sister1.png");
|
||||
s.position = pt;
|
||||
s.rotation = Math.random() * 360;
|
||||
this.addChild(s);
|
||||
// only the first
|
||||
if (this.currentSprite === null) {
|
||||
this.currentSprite = s;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
layer.ccTouchesMoved = function (touches) {
|
||||
pt = touches[0].locationInView();
|
||||
pt = director.convertToGL(pt);
|
||||
if (this.currentSprite) {
|
||||
this.currentSprite.position = pt;
|
||||
}
|
||||
};
|
||||
|
||||
layer.ccTouchesEnded = function (touches) {
|
||||
this.currentSprite = null;
|
||||
};
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
scene.addChild(layer);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Test Layer 2");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
/**
|
||||
* from here on there's code that can be shared between different tests
|
||||
* basically is the hud and the scene handling
|
||||
*/
|
||||
|
||||
// changes to the next scene
|
||||
var nextScene = function () {
|
||||
var l = Object.keys(scenes).length;
|
||||
scenes.currentScene = (scenes.currentScene + 1) % l;
|
||||
if (scenes.currentScene === 0) {
|
||||
scenes.currentScene = 1;
|
||||
}
|
||||
playCurrentScene();
|
||||
};
|
||||
|
||||
// changes to the previous scene
|
||||
var prevScene = function () {
|
||||
var l = Object.keys(scenes).length;
|
||||
scenes.currentScene -= 1;
|
||||
if (scenes.currentScene < 1) {
|
||||
scenes.currentScene = l - 1;
|
||||
}
|
||||
playCurrentScene();
|
||||
};
|
||||
|
||||
var playCurrentScene = function () {
|
||||
var name = Object.keys(scenes)[scenes.currentScene];
|
||||
var scene = scenes[name]();
|
||||
// cc.log("running scene: " + name + "(" + scene + ")");
|
||||
if (director.runningScene === null) {
|
||||
director.runWithScene(scene);
|
||||
} else {
|
||||
director.replaceScene(scene);
|
||||
}
|
||||
};
|
||||
|
||||
// creates the hud
|
||||
var createMenu = function (labelText) {
|
||||
var hudMenu = new cc.Menu();
|
||||
hudMenu.init();
|
||||
|
||||
var b1 = new cc.Sprite(); b1.initWithFile("b1.png");
|
||||
var b2 = new cc.Sprite(); b2.initWithFile("b2.png");
|
||||
item1 = new cc.MenuItemSprite();
|
||||
item1.initWithNormalSprite(b1, b2);
|
||||
item1.action = function () {
|
||||
prevScene();
|
||||
};
|
||||
|
||||
var r1 = new cc.Sprite(); r1.initWithFile("r1.png");
|
||||
var r2 = new cc.Sprite(); r2.initWithFile("r2.png");
|
||||
item2 = new cc.MenuItemSprite();
|
||||
item2.initWithNormalSprite(r1, r2);
|
||||
item2.action = function () {
|
||||
// cc.executeScript("JS/1to1/test_actions.js");
|
||||
playCurrentScene();
|
||||
};
|
||||
|
||||
var f1 = new cc.Sprite(); f1.initWithFile("f1.png");
|
||||
var f2 = new cc.Sprite(); f2.initWithFile("f2.png");
|
||||
item3 = new cc.MenuItemSprite();
|
||||
item3.initWithNormalSprite(f1, f2);
|
||||
item3.action = function () {
|
||||
nextScene();
|
||||
};
|
||||
|
||||
var c1 = new cc.Sprite(); c1.initWithFile("r1.png");
|
||||
var c2 = new cc.Sprite(); c2.initWithFile("r2.png");
|
||||
item4 = new cc.MenuItemSprite();
|
||||
item4.initWithNormalSprite(c1, c2);
|
||||
item4.action = function () {
|
||||
cc.executeScript("JS/1to1/test_layer.js");
|
||||
};
|
||||
|
||||
item1.position = cc.Point.create(winSize.width / 2 - 100, 30);
|
||||
item2.position = cc.Point.create(winSize.width / 2 , 30);
|
||||
item3.position = cc.Point.create(winSize.width / 2 + 100, 30);
|
||||
item4.position = cc.Point.create(30, winSize.height - 30);
|
||||
|
||||
hudMenu.addChild(item1);
|
||||
hudMenu.addChild(item2);
|
||||
hudMenu.addChild(item3);
|
||||
hudMenu.addChild(item4);
|
||||
hudMenu.position = pointZero;
|
||||
|
||||
if (labelText) {
|
||||
var label = new cc.LabelTTF();
|
||||
// initWithString: text, size, alignment, font, fontSize
|
||||
label.initWithString(labelText, sizeZero, 0, "Arial", 18.0);
|
||||
var menuLabel = new cc.MenuItemLabel();
|
||||
menuLabel.initWithLabel(label);
|
||||
menuLabel.position = cc.Point.create(winSize.width / 2, winSize.height - 30);
|
||||
hudMenu.addChild(menuLabel);
|
||||
}
|
||||
|
||||
// just to avoid GC
|
||||
hudMenu.items = [item1, item2, item3];
|
||||
return hudMenu;
|
||||
};
|
||||
|
||||
playCurrentScene();
|
|
@ -1,484 +0,0 @@
|
|||
/*
|
||||
* showcasing actions
|
||||
*/
|
||||
|
||||
/**
|
||||
* simple wrappers
|
||||
*/
|
||||
cc.Point.create = function (x, y) {
|
||||
var pt = new cc.Point();
|
||||
pt.x = x;
|
||||
pt.y = y;
|
||||
return pt;
|
||||
};
|
||||
|
||||
cc.Size.create = function (w, h) {
|
||||
var sz = new cc.Size();
|
||||
sz.width = w;
|
||||
sz.height = h;
|
||||
return sz;
|
||||
};
|
||||
|
||||
cc.Sprite.create = function (file) {
|
||||
var s = new cc.Sprite();
|
||||
s.initWithFile(file);
|
||||
return s;
|
||||
};
|
||||
|
||||
var pointZero = cc.Point.create(0, 0);
|
||||
var sizeZero = cc.Size.create(0, 0);
|
||||
|
||||
var director = cc.Director.sharedDirector();
|
||||
var winSize = director.winSize;
|
||||
|
||||
var scenes = {};
|
||||
scenes.currentScene = 1;
|
||||
|
||||
/**
|
||||
* Manual Particle
|
||||
*/
|
||||
scenes['test_manual'] = function () {
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
|
||||
var p1 = new cc.ParticleSystem();
|
||||
p1.initWithTotalParticles(250);
|
||||
p1.position = cc.Point.create(winSize.width / 2, winSize.height / 2 );
|
||||
|
||||
scene.addChild(p1);
|
||||
|
||||
p1.texture = cc.TextureCache.sharedTextureCache().addImage( "stars2.png" );
|
||||
|
||||
p1.duration = 3;
|
||||
|
||||
// gravity
|
||||
p1.gravity = cc.Point.create(0, -5);
|
||||
|
||||
// angle
|
||||
p1.angle = 90;
|
||||
p1.angleVar = 360;
|
||||
|
||||
// speed of particles
|
||||
p1.speed = 160;
|
||||
p1.speedVar = 20;
|
||||
|
||||
// radial
|
||||
p1.radialAccel = -120;
|
||||
p1.radialAccelVar = 0;
|
||||
|
||||
// tagential
|
||||
p1.tangentialAccel = 30;
|
||||
p1.tangentialAccelVar = 0;
|
||||
|
||||
// emitter position
|
||||
// p1.position = cc.Point.create(0, 0);
|
||||
p1.posVar = cc.Point.create(0, 0);
|
||||
|
||||
// life of particles
|
||||
p1.life = 4;
|
||||
p1.lifeVar = 1;
|
||||
|
||||
// spin of particles
|
||||
p1.startSpin = 0;
|
||||
p1.startSizeVar = 0;
|
||||
p1.endSpin = 0;
|
||||
p1.endSpinVar = 0;
|
||||
|
||||
// color of particles
|
||||
p1.startColor = [0.5, 0.5, 0.5, 1.0];
|
||||
p1.startColorVar = [0.5, 0.5, 0.5, 1.0];
|
||||
p1.endColor = [0.1, 0.1, 0.1, 0.2];
|
||||
p1.endColorVar = [0.1, 0.1, 0.1, 0.2];
|
||||
|
||||
// size, in pixels
|
||||
p1.startSize = 30;
|
||||
p1.startSizeVar = 0;
|
||||
// p1.endSize = kParticleStartSizeEqualToEndSize;
|
||||
|
||||
// emits per second
|
||||
p1.emissionRate = 500;
|
||||
|
||||
// additive
|
||||
p1.isBlendAdditive = true;
|
||||
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Particle: Manual Particle");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
/**
|
||||
* test particle
|
||||
*/
|
||||
scenes['test_lava_flow'] = function () {
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
|
||||
var p1 = cc.ParticleSystem.particleWithFile("LavaFlow.plist");
|
||||
p1.position = cc.Point.create(winSize.width / 2, winSize.height / 2 );
|
||||
scene.addChild(p1);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Particle: Lave Flow");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* test particle
|
||||
*/
|
||||
scenes['test_forest_fire'] = function () {
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
|
||||
var p1 = cc.ParticleSystem.particleWithFile("ForestFire.plist");
|
||||
p1.position = cc.Point.create(winSize.width / 2, winSize.height / 2 );
|
||||
scene.addChild(p1);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Particle: Forest Fire");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
/**
|
||||
* test particle
|
||||
*/
|
||||
scenes['test_boiling_foam'] = function () {
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
|
||||
var p1 = cc.ParticleSystem.particleWithFile("BoilingFoam.plist");
|
||||
p1.position = cc.Point.create(winSize.width / 2, winSize.height / 2 );
|
||||
scene.addChild(p1);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Particle: Boiling Foam");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* test particle
|
||||
*/
|
||||
scenes['test_burst_pipe'] = function () {
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
|
||||
var p1 = cc.ParticleSystem.particleWithFile("BurstPipe.plist");
|
||||
p1.position = cc.Point.create(winSize.width / 2, winSize.height / 2 );
|
||||
scene.addChild(p1);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Particle: Burst Pipe");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
/**
|
||||
* test particle
|
||||
*/
|
||||
scenes['test_comet'] = function () {
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
|
||||
var p1 = cc.ParticleSystem.particleWithFile("Comet.plist");
|
||||
p1.position = cc.Point.create(winSize.width / 2, winSize.height / 2 );
|
||||
scene.addChild(p1);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Particle: Comet");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
/**
|
||||
* test particle
|
||||
*/
|
||||
scenes['test_debian'] = function () {
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
|
||||
var p1 = cc.ParticleSystem.particleWithFile("debian.plist");
|
||||
p1.position = cc.Point.create(winSize.width / 2, winSize.height / 2 );
|
||||
scene.addChild(p1);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Particle: Debian");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
/**
|
||||
* test particle
|
||||
*/
|
||||
scenes['test_exploding_ring'] = function () {
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
|
||||
var p1 = cc.ParticleSystem.particleWithFile("ExplodingRing.plist");
|
||||
p1.position = cc.Point.create(winSize.width / 2, winSize.height / 2 );
|
||||
scene.addChild(p1);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Particle: Exploding Ring");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
/**
|
||||
* test particle
|
||||
*/
|
||||
scenes['test_flower'] = function () {
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
|
||||
var p1 = cc.ParticleSystem.particleWithFile("Flower.plist");
|
||||
p1.position = cc.Point.create(winSize.width / 2, winSize.height / 2 );
|
||||
scene.addChild(p1);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Particle: Flower");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
/**
|
||||
* test particle
|
||||
*/
|
||||
scenes['test_galaxy'] = function () {
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
|
||||
var p1 = cc.ParticleSystem.particleWithFile("Galaxy.plist");
|
||||
p1.position = cc.Point.create(winSize.width / 2, winSize.height / 2 );
|
||||
scene.addChild(p1);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Particle: Galaxy");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
/**
|
||||
* test particle
|
||||
*/
|
||||
scenes['test_phoenix'] = function () {
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
|
||||
var p1 = cc.ParticleSystem.particleWithFile("Phoenix.plist");
|
||||
p1.position = cc.Point.create(winSize.width / 2, winSize.height / 2 );
|
||||
scene.addChild(p1);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Particle: Phoenix");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
/**
|
||||
* test particle
|
||||
*/
|
||||
scenes['test_small_sun'] = function () {
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
|
||||
var p1 = cc.ParticleSystem.particleWithFile("SmallSun.plist");
|
||||
p1.position = cc.Point.create(winSize.width / 2, winSize.height / 2 );
|
||||
scene.addChild(p1);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Particle: Small Sun");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
/**
|
||||
* test particle
|
||||
*/
|
||||
scenes['test_spinningpeas'] = function () {
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
|
||||
var p1 = cc.ParticleSystem.particleWithFile("SpinningPeas.plist");
|
||||
p1.position = cc.Point.create(winSize.width / 2, winSize.height / 2 );
|
||||
scene.addChild(p1);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Particle: Spinning Peas");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
/**
|
||||
* test particle
|
||||
*/
|
||||
scenes['test_spiral'] = function () {
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
|
||||
var p1 = cc.ParticleSystem.particleWithFile("Spiral.plist");
|
||||
p1.position = cc.Point.create(winSize.width / 2, winSize.height / 2 );
|
||||
scene.addChild(p1);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Particle: Spiral");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
/**
|
||||
* test particle
|
||||
*/
|
||||
scenes['test_sookypeas'] = function () {
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
|
||||
var p1 = cc.ParticleSystem.particleWithFile("SpookyPeas.plist");
|
||||
p1.position = cc.Point.create(winSize.width / 2, winSize.height / 2 );
|
||||
scene.addChild(p1);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Particle: Spooky Peas");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
/**
|
||||
* test particle
|
||||
*/
|
||||
scenes['test_upsidedown'] = function () {
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
|
||||
var p1 = cc.ParticleSystem.particleWithFile("Upsidedown.plist");
|
||||
p1.position = cc.Point.create(winSize.width / 2, winSize.height / 2 );
|
||||
scene.addChild(p1);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Particle: Upside Down test");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
/**
|
||||
* from here on there's code that can be shared between different tests
|
||||
* basically is the hud and the scene handling
|
||||
*/
|
||||
|
||||
// changes to the next scene
|
||||
var nextScene = function () {
|
||||
var l = Object.keys(scenes).length;
|
||||
scenes.currentScene = (scenes.currentScene + 1) % l;
|
||||
if (scenes.currentScene === 0) {
|
||||
scenes.currentScene = 1;
|
||||
}
|
||||
playCurrentScene();
|
||||
};
|
||||
|
||||
// changes to the previous scene
|
||||
var prevScene = function () {
|
||||
var l = Object.keys(scenes).length;
|
||||
scenes.currentScene -= 1;
|
||||
if (scenes.currentScene < 1) {
|
||||
scenes.currentScene = l - 1;
|
||||
}
|
||||
playCurrentScene();
|
||||
};
|
||||
|
||||
var playCurrentScene = function () {
|
||||
var name = Object.keys(scenes)[scenes.currentScene];
|
||||
var scene = scenes[name]();
|
||||
// cc.log("running scene: " + name + "(" + scene + ")");
|
||||
if (director.runningScene === null) {
|
||||
director.runWithScene(scene);
|
||||
} else {
|
||||
director.replaceScene(scene);
|
||||
}
|
||||
};
|
||||
|
||||
// creates the hud
|
||||
var createMenu = function (labelText) {
|
||||
var hudMenu = new cc.Menu();
|
||||
hudMenu.init();
|
||||
|
||||
var b1 = new cc.Sprite(); b1.initWithFile("b1.png");
|
||||
var b2 = new cc.Sprite(); b2.initWithFile("b2.png");
|
||||
item1 = new cc.MenuItemSprite();
|
||||
item1.initWithNormalSprite(b1, b2);
|
||||
item1.action = function () {
|
||||
prevScene();
|
||||
};
|
||||
|
||||
var r1 = new cc.Sprite(); r1.initWithFile("r1.png");
|
||||
var r2 = new cc.Sprite(); r2.initWithFile("r2.png");
|
||||
item2 = new cc.MenuItemSprite();
|
||||
item2.initWithNormalSprite(r1, r2);
|
||||
item2.action = function () {
|
||||
// cc.executeScript("JS/1to1/test_actions.js");
|
||||
playCurrentScene();
|
||||
};
|
||||
|
||||
var f1 = new cc.Sprite(); f1.initWithFile("f1.png");
|
||||
var f2 = new cc.Sprite(); f2.initWithFile("f2.png");
|
||||
item3 = new cc.MenuItemSprite();
|
||||
item3.initWithNormalSprite(f1, f2);
|
||||
item3.action = function () {
|
||||
nextScene();
|
||||
};
|
||||
|
||||
var c1 = new cc.Sprite(); c1.initWithFile("r1.png");
|
||||
var c2 = new cc.Sprite(); c2.initWithFile("r2.png");
|
||||
item4 = new cc.MenuItemSprite();
|
||||
item4.initWithNormalSprite(c1, c2);
|
||||
item4.action = function () {
|
||||
cc.executeScript("JS/1to1/test_particles.js");
|
||||
};
|
||||
|
||||
item1.position = cc.Point.create(winSize.width / 2 - 100, 30);
|
||||
item2.position = cc.Point.create(winSize.width / 2 , 30);
|
||||
item3.position = cc.Point.create(winSize.width / 2 + 100, 30);
|
||||
item4.position = cc.Point.create(30, winSize.height - 30);
|
||||
|
||||
hudMenu.addChild(item1);
|
||||
hudMenu.addChild(item2);
|
||||
hudMenu.addChild(item3);
|
||||
hudMenu.addChild(item4);
|
||||
hudMenu.position = pointZero;
|
||||
|
||||
if (labelText) {
|
||||
var label = new cc.LabelTTF();
|
||||
// initWithString: text, size, alignment, font, fontSize
|
||||
label.initWithString(labelText, sizeZero, 0, "Arial", 18.0);
|
||||
var menuLabel = new cc.MenuItemLabel();
|
||||
menuLabel.initWithLabel(label);
|
||||
menuLabel.position = cc.Point.create(winSize.width / 2, winSize.height - 30);
|
||||
hudMenu.addChild(menuLabel);
|
||||
}
|
||||
|
||||
// just to avoid GC
|
||||
hudMenu.items = [item1, item2, item3];
|
||||
return hudMenu;
|
||||
};
|
||||
|
||||
playCurrentScene();
|
|
@ -1,3 +0,0 @@
|
|||
require("JS/1to1/test_require_second.js");
|
||||
|
||||
cc.log("value: " + value);
|
|
@ -1 +0,0 @@
|
|||
value = "this was set in another file";
|
|
@ -1,166 +0,0 @@
|
|||
/*
|
||||
* showcasing sound
|
||||
*/
|
||||
|
||||
/**
|
||||
* simple wrappers
|
||||
*/
|
||||
cc.Point.create = function (x, y) {
|
||||
var pt = new cc.Point();
|
||||
pt.x = x;
|
||||
pt.y = y;
|
||||
return pt;
|
||||
};
|
||||
|
||||
cc.Size.create = function (w, h) {
|
||||
var sz = new cc.Size();
|
||||
sz.width = w;
|
||||
sz.height = h;
|
||||
return sz;
|
||||
};
|
||||
|
||||
cc.Sprite.create = function (file) {
|
||||
var s = new cc.Sprite();
|
||||
s.initWithFile(file);
|
||||
return s;
|
||||
};
|
||||
|
||||
var pointZero = cc.Point.create(0, 0);
|
||||
var sizeZero = cc.Size.create(0, 0);
|
||||
|
||||
var director = cc.Director.sharedDirector();
|
||||
var winSize = director.winSize;
|
||||
|
||||
var scenes = {};
|
||||
scenes.currentScene = 1;
|
||||
|
||||
/**
|
||||
* tests the most basic function: moveTo and moveBy
|
||||
*/
|
||||
scenes['test_move'] = function () {
|
||||
var audioEngine = cc.SimpleAudioEngine.sharedEngine();
|
||||
audioEngine.preloadBackgroundMusic("Silly Fun Theme A.mp3");
|
||||
audioEngine.preloadEffect("ballbounce.wav");
|
||||
|
||||
var layer = new cc.Layer(); layer.init();
|
||||
layer.isTouchEnabled = true;
|
||||
layer.ccTouchesBegan = function (touches) {
|
||||
for (var i in touches) {
|
||||
// no loop
|
||||
audioEngine.playEffect("ballbounce.wav", false);
|
||||
}
|
||||
};
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
scene.addChild(layer);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Test Sounds - Touch for SFX");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
// play the bg music - loop
|
||||
audioEngine.playBackgroundMusic("Silly Fun Theme A.mp3", true);
|
||||
return scene;
|
||||
};
|
||||
|
||||
/**
|
||||
* from here on there's code that can be shared between different tests
|
||||
* basically is the hud and the scene handling
|
||||
*/
|
||||
|
||||
// changes to the next scene
|
||||
var nextScene = function () {
|
||||
var l = Object.keys(scenes).length;
|
||||
scenes.currentScene = (scenes.currentScene + 1) % l;
|
||||
if (scenes.currentScene === 0) {
|
||||
scenes.currentScene = 1;
|
||||
}
|
||||
playCurrentScene();
|
||||
};
|
||||
|
||||
// changes to the previous scene
|
||||
var prevScene = function () {
|
||||
var l = Object.keys(scenes).length;
|
||||
scenes.currentScene -= 1;
|
||||
if (scenes.currentScene < 1) {
|
||||
scenes.currentScene = l - 1;
|
||||
}
|
||||
playCurrentScene();
|
||||
};
|
||||
|
||||
var playCurrentScene = function () {
|
||||
var name = Object.keys(scenes)[scenes.currentScene];
|
||||
var scene = scenes[name]();
|
||||
// cc.log("running scene: " + name + "(" + scene + ")");
|
||||
if (director.runningScene === null) {
|
||||
director.runWithScene(scene);
|
||||
} else {
|
||||
director.replaceScene(scene);
|
||||
}
|
||||
};
|
||||
|
||||
// creates the hud
|
||||
var createMenu = function (labelText) {
|
||||
var hudMenu = new cc.Menu();
|
||||
hudMenu.init();
|
||||
|
||||
var b1 = new cc.Sprite(); b1.initWithFile("b1.png");
|
||||
var b2 = new cc.Sprite(); b2.initWithFile("b2.png");
|
||||
item1 = new cc.MenuItemSprite();
|
||||
item1.initWithNormalSprite(b1, b2);
|
||||
item1.action = function () {
|
||||
prevScene();
|
||||
};
|
||||
|
||||
var r1 = new cc.Sprite(); r1.initWithFile("r1.png");
|
||||
var r2 = new cc.Sprite(); r2.initWithFile("r2.png");
|
||||
item2 = new cc.MenuItemSprite();
|
||||
item2.initWithNormalSprite(r1, r2);
|
||||
item2.action = function () {
|
||||
// cc.executeScript("JS/1to1/test_actions.js");
|
||||
playCurrentScene();
|
||||
};
|
||||
|
||||
var f1 = new cc.Sprite(); f1.initWithFile("f1.png");
|
||||
var f2 = new cc.Sprite(); f2.initWithFile("f2.png");
|
||||
item3 = new cc.MenuItemSprite();
|
||||
item3.initWithNormalSprite(f1, f2);
|
||||
item3.action = function () {
|
||||
nextScene();
|
||||
};
|
||||
|
||||
var c1 = new cc.Sprite(); c1.initWithFile("r1.png");
|
||||
var c2 = new cc.Sprite(); c2.initWithFile("r2.png");
|
||||
item4 = new cc.MenuItemSprite();
|
||||
item4.initWithNormalSprite(c1, c2);
|
||||
item4.action = function () {
|
||||
cc.executeScript("JS/1to1/test_actions.js");
|
||||
};
|
||||
|
||||
item1.position = cc.Point.create(winSize.width / 2 - 100, 30);
|
||||
item2.position = cc.Point.create(winSize.width / 2 , 30);
|
||||
item3.position = cc.Point.create(winSize.width / 2 + 100, 30);
|
||||
item4.position = cc.Point.create(30, winSize.height - 30);
|
||||
|
||||
hudMenu.addChild(item1);
|
||||
hudMenu.addChild(item2);
|
||||
hudMenu.addChild(item3);
|
||||
hudMenu.addChild(item4);
|
||||
hudMenu.position = pointZero;
|
||||
|
||||
if (labelText) {
|
||||
var label = new cc.LabelTTF();
|
||||
// initWithString: text, size, alignment, font, fontSize
|
||||
label.initWithString(labelText, sizeZero, 0, "Arial", 18.0);
|
||||
var menuLabel = new cc.MenuItemLabel();
|
||||
menuLabel.initWithLabel(label);
|
||||
menuLabel.position = cc.Point.create(winSize.width / 2, winSize.height - 30);
|
||||
hudMenu.addChild(menuLabel);
|
||||
}
|
||||
|
||||
// just to avoid GC
|
||||
hudMenu.items = [item1, item2, item3];
|
||||
return hudMenu;
|
||||
};
|
||||
|
||||
playCurrentScene();
|
|
@ -1,171 +0,0 @@
|
|||
/*
|
||||
* showcasing transitions
|
||||
*/
|
||||
|
||||
/**
|
||||
* simple wrappers
|
||||
*/
|
||||
cc.Point.create = function (x, y) {
|
||||
var pt = new cc.Point();
|
||||
pt.x = x;
|
||||
pt.y = y;
|
||||
return pt;
|
||||
};
|
||||
|
||||
cc.Size.create = function (w, h) {
|
||||
var sz = new cc.Size();
|
||||
sz.width = w;
|
||||
sz.height = h;
|
||||
return sz;
|
||||
};
|
||||
|
||||
cc.Sprite.create = function (file) {
|
||||
var s = new cc.Sprite();
|
||||
s.initWithFile(file);
|
||||
return s;
|
||||
};
|
||||
|
||||
var pointZero = cc.Point.create(0, 0);
|
||||
var sizeZero = cc.Size.create(0, 0);
|
||||
|
||||
var director = cc.Director.sharedDirector();
|
||||
var winSize = director.winSize;
|
||||
|
||||
var scenes = {};
|
||||
scenes.currentScene = 1;
|
||||
|
||||
/**
|
||||
* tests the most basic function: moveTo and moveBy
|
||||
*/
|
||||
scenes['test_roto_zoom'] = function () {
|
||||
var s1 = new cc.Sprite.create("grossini_dance_05.png");
|
||||
s1.position = cc.Point.create(winSize.width / 2 + 50, winSize.height / 2);
|
||||
var s2 = new cc.Sprite.create("grossinis_sister1.png");
|
||||
s2.position = cc.Point.create(winSize.width / 2 - 50, winSize.height / 2);
|
||||
|
||||
var moveTo = new cc.MoveTo();
|
||||
moveTo.initWithDuration(2.0, cc.Point.create(winSize.width, winSize.height / 2));
|
||||
var moveBy = new cc.MoveBy();
|
||||
moveBy.initWithDuration(2.0, cc.Point.create(100, 100));
|
||||
|
||||
s1.runAction(moveTo);
|
||||
s2.runAction(moveBy);
|
||||
|
||||
var scene = new cc.Scene(); scene.init();
|
||||
scene.addChild(s1);
|
||||
scene.addChild(s2);
|
||||
|
||||
// add the menu
|
||||
var menu = createMenu("Test Roto Zoom");
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
var current = director.runningScene;
|
||||
if (current) {
|
||||
var transition = cc.TransitionRotoZoom.transitionWithDuration(1.5, scene);
|
||||
return transition;
|
||||
}
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
/**
|
||||
* from here on there's code that can be shared between different tests
|
||||
* basically is the hud and the scene handling
|
||||
*/
|
||||
|
||||
// changes to the next scene
|
||||
var nextScene = function () {
|
||||
var l = Object.keys(scenes).length;
|
||||
scenes.currentScene = (scenes.currentScene + 1) % l;
|
||||
if (scenes.currentScene === 0) {
|
||||
scenes.currentScene = 1;
|
||||
}
|
||||
playCurrentScene();
|
||||
};
|
||||
|
||||
// changes to the previous scene
|
||||
var prevScene = function () {
|
||||
var l = Object.keys(scenes).length;
|
||||
scenes.currentScene -= 1;
|
||||
if (scenes.currentScene < 1) {
|
||||
scenes.currentScene = l - 1;
|
||||
}
|
||||
playCurrentScene();
|
||||
};
|
||||
|
||||
var playCurrentScene = function () {
|
||||
var name = Object.keys(scenes)[scenes.currentScene];
|
||||
var scene = scenes[name]();
|
||||
// cc.log("running scene: " + name + "(" + scene + ")");
|
||||
if (director.runningScene === null) {
|
||||
director.runWithScene(scene);
|
||||
} else {
|
||||
director.replaceScene(scene);
|
||||
}
|
||||
};
|
||||
|
||||
// creates the hud
|
||||
var createMenu = function (labelText) {
|
||||
var hudMenu = new cc.Menu();
|
||||
hudMenu.init();
|
||||
|
||||
var b1 = new cc.Sprite(); b1.initWithFile("b1.png");
|
||||
var b2 = new cc.Sprite(); b2.initWithFile("b2.png");
|
||||
item1 = new cc.MenuItemSprite();
|
||||
item1.initWithNormalSprite(b1, b2);
|
||||
item1.action = function () {
|
||||
prevScene();
|
||||
};
|
||||
|
||||
var r1 = new cc.Sprite(); r1.initWithFile("r1.png");
|
||||
var r2 = new cc.Sprite(); r2.initWithFile("r2.png");
|
||||
item2 = new cc.MenuItemSprite();
|
||||
item2.initWithNormalSprite(r1, r2);
|
||||
item2.action = function () {
|
||||
// cc.executeScript("JS/1to1/test_actions.js");
|
||||
playCurrentScene();
|
||||
};
|
||||
|
||||
var f1 = new cc.Sprite(); f1.initWithFile("f1.png");
|
||||
var f2 = new cc.Sprite(); f2.initWithFile("f2.png");
|
||||
item3 = new cc.MenuItemSprite();
|
||||
item3.initWithNormalSprite(f1, f2);
|
||||
item3.action = function () {
|
||||
nextScene();
|
||||
};
|
||||
|
||||
var c1 = new cc.Sprite(); c1.initWithFile("r1.png");
|
||||
var c2 = new cc.Sprite(); c2.initWithFile("r2.png");
|
||||
item4 = new cc.MenuItemSprite();
|
||||
item4.initWithNormalSprite(c1, c2);
|
||||
item4.action = function () {
|
||||
cc.executeScript("JS/1to1/test_actions.js");
|
||||
};
|
||||
|
||||
item1.position = cc.Point.create(winSize.width / 2 - 100, 30);
|
||||
item2.position = cc.Point.create(winSize.width / 2 , 30);
|
||||
item3.position = cc.Point.create(winSize.width / 2 + 100, 30);
|
||||
item4.position = cc.Point.create(30, winSize.height - 30);
|
||||
|
||||
hudMenu.addChild(item1);
|
||||
hudMenu.addChild(item2);
|
||||
hudMenu.addChild(item3);
|
||||
hudMenu.addChild(item4);
|
||||
hudMenu.position = pointZero;
|
||||
|
||||
if (labelText) {
|
||||
var label = new cc.LabelTTF();
|
||||
// initWithString: text, size, alignment, font, fontSize
|
||||
label.initWithString(labelText, sizeZero, 0, "Arial", 18.0);
|
||||
var menuLabel = new cc.MenuItemLabel();
|
||||
menuLabel.initWithLabel(label);
|
||||
menuLabel.position = cc.Point.create(winSize.width / 2, winSize.height - 30);
|
||||
hudMenu.addChild(menuLabel);
|
||||
}
|
||||
|
||||
// just to avoid GC
|
||||
hudMenu.items = [item1, item2, item3];
|
||||
return hudMenu;
|
||||
};
|
||||
|
||||
playCurrentScene();
|
|
@ -1,517 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* vim: set ts=8 sw=4 et tw=78:
|
||||
*
|
||||
* jorendb - A toy command-line debugger for shell-js programs.
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is jorendb toy JS debugger.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jason Orendorff <jorendorff@mozilla.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/*
|
||||
* jorendb is a simple command-line debugger for shell-js programs. It is
|
||||
* intended as a demo of the Debugger object (as there are no shell js programs
|
||||
* to speak of).
|
||||
*
|
||||
* To run it: $JS -d path/to/this/file/jorendb.js
|
||||
* To run some JS code under it, try:
|
||||
* (jorendb) print load("my-script-to-debug.js")
|
||||
* Execution will stop at debugger statements and you'll get a jorendb prompt.
|
||||
*/
|
||||
|
||||
// Debugger state.
|
||||
var focusedFrame = null;
|
||||
var topFrame = null;
|
||||
var debuggeeValues = [null];
|
||||
var lastExc = null;
|
||||
|
||||
// Cleanup functions to run when we next re-enter the repl.
|
||||
var replCleanups = [];
|
||||
|
||||
// Convert a debuggee value v to a string.
|
||||
function dvToString(v) {
|
||||
return (typeof v !== 'object' || v === null) ? uneval(v) : "[object " + v.class + "]";
|
||||
}
|
||||
|
||||
function showDebuggeeValue(dv) {
|
||||
var dvrepr = dvToString(dv);
|
||||
var i = debuggeeValues.length;
|
||||
debuggeeValues[i] = dv;
|
||||
print("$" + i + " = " + dvrepr);
|
||||
}
|
||||
|
||||
Object.defineProperty(Debugger.Frame.prototype, "num", {
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
get: function () {
|
||||
var i = 0;
|
||||
for (var f = topFrame; f && f !== this; f = f.older)
|
||||
i++;
|
||||
return f === null ? undefined : i;
|
||||
}
|
||||
});
|
||||
|
||||
Debugger.Frame.prototype.frameDescription = function frameDescription() {
|
||||
if (this.type == "call")
|
||||
return ((this.callee.name || '<anonymous>') +
|
||||
"(" + this.arguments.map(dvToString).join(", ") + ")");
|
||||
else
|
||||
return this.type + " code";
|
||||
}
|
||||
|
||||
Debugger.Frame.prototype.positionDescription = function positionDescription() {
|
||||
if (this.script) {
|
||||
var line = this.script.getOffsetLine(this.offset);
|
||||
if (this.script.url)
|
||||
return this.script.url + ":" + line;
|
||||
return "line " + line;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Debugger.Frame.prototype.fullDescription = function fullDescription() {
|
||||
var fr = this.frameDescription();
|
||||
var pos = this.positionDescription();
|
||||
if (pos)
|
||||
return fr + ", " + pos;
|
||||
return fr;
|
||||
}
|
||||
|
||||
Object.defineProperty(Debugger.Frame.prototype, "line", {
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
get: function() {
|
||||
if (this.script)
|
||||
return this.script.getOffsetLine(this.offset);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
function callDescription(f) {
|
||||
return ((f.callee.name || '<anonymous>') +
|
||||
"(" + f.arguments.map(dvToString).join(", ") + ")");
|
||||
}
|
||||
|
||||
function showFrame(f, n) {
|
||||
if (f === undefined || f === null) {
|
||||
f = focusedFrame;
|
||||
if (f === null) {
|
||||
print("No stack.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (n === undefined) {
|
||||
n = f.num;
|
||||
if (n === undefined)
|
||||
throw new Error("Internal error: frame not on stack");
|
||||
}
|
||||
|
||||
print('#' + n + " " + f.fullDescription());
|
||||
}
|
||||
|
||||
function saveExcursion(fn) {
|
||||
var tf = topFrame, ff = focusedFrame;
|
||||
try {
|
||||
return fn();
|
||||
} finally {
|
||||
topFrame = tf;
|
||||
focusedFrame = ff;
|
||||
}
|
||||
}
|
||||
|
||||
function quitCommand() {
|
||||
dbg.enabled = false;
|
||||
quit(0);
|
||||
}
|
||||
|
||||
function backtraceCommand() {
|
||||
if (topFrame === null)
|
||||
print("No stack.");
|
||||
for (var i = 0, f = topFrame; f; i++, f = f.older)
|
||||
showFrame(f, i);
|
||||
}
|
||||
|
||||
function printCommand(rest) {
|
||||
if (focusedFrame === null) {
|
||||
// This is super bogus, need a way to create an env wrapping the debuggeeGlobal
|
||||
// and eval against that.
|
||||
var nonwrappedValue;
|
||||
try {
|
||||
nonwrappedValue = debuggeeGlobal.eval(rest);
|
||||
} catch (exc) {
|
||||
print("Exception caught.");
|
||||
nonwrappedValue = exc;
|
||||
}
|
||||
if (typeof nonwrappedValue !== "object" || nonwrappedValue === null) {
|
||||
// primitive value, no sweat
|
||||
print(" " + uneval(nonwrappedValue));
|
||||
} else {
|
||||
// junk for now
|
||||
print(" " + Object.prototype.toString.call(nonwrappedValue));
|
||||
}
|
||||
} else {
|
||||
// This is the real deal.
|
||||
var cv = saveExcursion(function () {
|
||||
return focusedFrame.eval(rest);
|
||||
});
|
||||
if (cv === null) {
|
||||
if (!dbg.enabled)
|
||||
return [cv];
|
||||
print("Debuggee died.");
|
||||
} else if ('return' in cv) {
|
||||
if (!dbg.enabled)
|
||||
return [undefined];
|
||||
showDebuggeeValue(cv.return);
|
||||
} else {
|
||||
if (!dbg.enabled)
|
||||
return [cv];
|
||||
print("Exception caught. (To rethrow it, type 'throw'.)");
|
||||
lastExc = cv.throw;
|
||||
showDebuggeeValue(lastExc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function detachCommand() {
|
||||
dbg.enabled = false;
|
||||
return [undefined];
|
||||
}
|
||||
|
||||
function continueCommand() {
|
||||
if (focusedFrame === null) {
|
||||
print("No stack.");
|
||||
return;
|
||||
}
|
||||
return [undefined];
|
||||
}
|
||||
|
||||
function throwCommand(rest) {
|
||||
var v;
|
||||
if (focusedFrame !== topFrame) {
|
||||
print("To throw, you must select the newest frame (use 'frame 0').");
|
||||
return;
|
||||
} else if (focusedFrame === null) {
|
||||
print("No stack.");
|
||||
return;
|
||||
} else if (rest === '') {
|
||||
return [{throw: lastExc}];
|
||||
} else {
|
||||
var cv = saveExcursion(function () { return focusedFrame.eval(rest); });
|
||||
if (cv === null) {
|
||||
if (!dbg.enabled)
|
||||
return [cv];
|
||||
print("Debuggee died while determining what to throw. Stopped.");
|
||||
} else if ('return' in cv) {
|
||||
return [{throw: cv.return}];
|
||||
} else {
|
||||
if (!dbg.enabled)
|
||||
return [cv];
|
||||
print("Exception determining what to throw. Stopped.");
|
||||
showDebuggeeValue(cv.throw);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function frameCommand(rest) {
|
||||
var n, f;
|
||||
if (rest.match(/[0-9]+/)) {
|
||||
n = +rest;
|
||||
f = topFrame;
|
||||
if (f === null) {
|
||||
print("No stack.");
|
||||
return;
|
||||
}
|
||||
for (var i = 0; i < n && f; i++) {
|
||||
if (!f.older) {
|
||||
print("There is no frame " + rest + ".");
|
||||
return;
|
||||
}
|
||||
f.older.younger = f;
|
||||
f = f.older;
|
||||
}
|
||||
focusedFrame = f;
|
||||
showFrame(f, n);
|
||||
} else if (rest !== '') {
|
||||
if (topFrame === null)
|
||||
print("No stack.");
|
||||
else
|
||||
showFrame();
|
||||
} else {
|
||||
print("do what now?");
|
||||
}
|
||||
}
|
||||
|
||||
function upCommand() {
|
||||
if (focusedFrame === null)
|
||||
print("No stack.");
|
||||
else if (focusedFrame.older === null)
|
||||
print("Initial frame selected; you cannot go up.");
|
||||
else {
|
||||
focusedFrame.older.younger = focusedFrame;
|
||||
focusedFrame = focusedFrame.older;
|
||||
showFrame();
|
||||
}
|
||||
}
|
||||
|
||||
function downCommand() {
|
||||
if (focusedFrame === null)
|
||||
print("No stack.");
|
||||
else if (!focusedFrame.younger)
|
||||
print("Youngest frame selected; you cannot go down.");
|
||||
else {
|
||||
focusedFrame = focusedFrame.younger;
|
||||
showFrame();
|
||||
}
|
||||
}
|
||||
|
||||
function forcereturnCommand(rest) {
|
||||
var v;
|
||||
var f = focusedFrame;
|
||||
if (f !== topFrame) {
|
||||
print("To forcereturn, you must select the newest frame (use 'frame 0').");
|
||||
} else if (f === null) {
|
||||
print("Nothing on the stack.");
|
||||
} else if (rest === '') {
|
||||
return [{return: undefined}];
|
||||
} else {
|
||||
var cv = saveExcursion(function () { return f.eval(rest); });
|
||||
if (cv === null) {
|
||||
if (!dbg.enabled)
|
||||
return [cv];
|
||||
print("Debuggee died while determining what to forcereturn. Stopped.");
|
||||
} else if ('return' in cv) {
|
||||
return [{return: cv.return}];
|
||||
} else {
|
||||
if (!dbg.enabled)
|
||||
return [cv];
|
||||
print("Error determining what to forcereturn. Stopped.");
|
||||
showDebuggeeValue(cv.throw);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function printPop(f, c) {
|
||||
var fdesc = f.fullDescription();
|
||||
if (c.return) {
|
||||
print("frame returning (still selected): " + fdesc);
|
||||
showDebuggeeValue(c.return);
|
||||
} else if (c.throw) {
|
||||
print("frame threw exception: " + fdesc);
|
||||
showDebuggeeValue(c.throw);
|
||||
print("(To rethrow it, type 'throw'.)");
|
||||
lastExc = c.throw;
|
||||
} else {
|
||||
print("frame was terminated: " + fdesc);
|
||||
}
|
||||
}
|
||||
|
||||
// Set |prop| on |obj| to |value|, but then restore its current value
|
||||
// when we next enter the repl.
|
||||
function setUntilRepl(obj, prop, value) {
|
||||
var saved = obj[prop];
|
||||
obj[prop] = value;
|
||||
replCleanups.push(function () { obj[prop] = saved; });
|
||||
}
|
||||
|
||||
function doStepOrNext(kind) {
|
||||
var startFrame = topFrame;
|
||||
var startLine = startFrame.line;
|
||||
print("stepping in: " + startFrame.fullDescription());
|
||||
print("starting line: " + uneval(startLine));
|
||||
|
||||
function stepPopped(completion) {
|
||||
// Note that we're popping this frame; we need to watch for
|
||||
// subsequent step events on its caller.
|
||||
this.reportedPop = true;
|
||||
printPop(this, completion);
|
||||
topFrame = focusedFrame = this;
|
||||
return repl();
|
||||
}
|
||||
|
||||
function stepEntered(newFrame) {
|
||||
print("entered frame: " + newFrame.fullDescription());
|
||||
topFrame = focusedFrame = newFrame;
|
||||
return repl();
|
||||
}
|
||||
|
||||
function stepStepped() {
|
||||
print("stepStepped: " + this.fullDescription());
|
||||
// If we've changed frame or line, then report that.
|
||||
if (this !== startFrame || this.line != startLine) {
|
||||
topFrame = focusedFrame = this;
|
||||
if (focusedFrame != startFrame)
|
||||
print(focusedFrame.fullDescription());
|
||||
return repl();
|
||||
}
|
||||
|
||||
// Otherwise, let execution continue.
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (kind.step)
|
||||
setUntilRepl(dbg, 'onEnterFrame', stepEntered);
|
||||
|
||||
// If we're stepping after an onPop, watch for steps and pops in the
|
||||
// next-older frame; this one is done.
|
||||
var stepFrame = startFrame.reportedPop ? startFrame.older : startFrame;
|
||||
if (!stepFrame || !stepFrame.script)
|
||||
stepFrame = null;
|
||||
if (stepFrame) {
|
||||
setUntilRepl(stepFrame, 'onStep', stepStepped);
|
||||
setUntilRepl(stepFrame, 'onPop', stepPopped);
|
||||
}
|
||||
|
||||
// Let the program continue!
|
||||
return [undefined];
|
||||
}
|
||||
|
||||
function stepCommand() { return doStepOrNext({step:true}); }
|
||||
function nextCommand() { return doStepOrNext({next:true}); }
|
||||
|
||||
// Build the table of commands.
|
||||
var commands = {};
|
||||
var commandArray = [
|
||||
backtraceCommand, "bt", "where",
|
||||
continueCommand, "c",
|
||||
detachCommand,
|
||||
downCommand, "d",
|
||||
forcereturnCommand,
|
||||
frameCommand, "f",
|
||||
nextCommand, "n",
|
||||
printCommand, "p",
|
||||
quitCommand, "q",
|
||||
stepCommand, "s",
|
||||
throwCommand, "t",
|
||||
upCommand, "u"
|
||||
];
|
||||
var last = null;
|
||||
for (var i = 0; i < commandArray.length; i++) {
|
||||
var cmd = commandArray[i];
|
||||
if (typeof cmd === "string")
|
||||
commands[cmd] = last;
|
||||
else
|
||||
last = commands[cmd.name.replace(/Command$/, '')] = cmd;
|
||||
}
|
||||
|
||||
// Break cmd into two parts: its first word and everything else.
|
||||
function breakcmd(cmd) {
|
||||
cmd = cmd.trimLeft();
|
||||
var m = /\s/.exec(cmd);
|
||||
if (m === null)
|
||||
return [cmd, ''];
|
||||
return [cmd.slice(0, m.index), cmd.slice(m.index).trimLeft()];
|
||||
}
|
||||
|
||||
function runcmd(cmd) {
|
||||
var pieces = breakcmd(cmd);
|
||||
if (pieces[0] === "")
|
||||
return undefined;
|
||||
|
||||
var first = pieces[0], rest = pieces[1];
|
||||
if (!commands.hasOwnProperty(first)) {
|
||||
print("unrecognized command '" + first + "'");
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var cmd = commands[first];
|
||||
if (cmd.length === 0 && rest !== '') {
|
||||
print("this command cannot take an argument");
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return cmd(rest);
|
||||
}
|
||||
|
||||
function repl() {
|
||||
while (replCleanups.length > 0)
|
||||
replCleanups.pop()();
|
||||
|
||||
var cmd;
|
||||
for (;;) {
|
||||
print("\n" + prompt);
|
||||
cmd = readline();
|
||||
if (cmd === null)
|
||||
return null;
|
||||
|
||||
try {
|
||||
var result = runcmd(cmd);
|
||||
if (result === undefined)
|
||||
; // do nothing
|
||||
else if (Array.isArray(result))
|
||||
return result[0];
|
||||
else
|
||||
throw new Error("Internal error: result of runcmd wasn't array or undefined");
|
||||
} catch (exc) {
|
||||
print("*** Internal error: exception in the debugger code.");
|
||||
print(" " + exc);
|
||||
print(exc.stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var dbg = new Debugger();
|
||||
dbg.onDebuggerStatement = function (frame) {
|
||||
return saveExcursion(function () {
|
||||
topFrame = focusedFrame = frame;
|
||||
print("'debugger' statement hit.");
|
||||
showFrame();
|
||||
return repl();
|
||||
});
|
||||
};
|
||||
dbg.onThrow = function (frame, exc) {
|
||||
return saveExcursion(function () {
|
||||
topFrame = focusedFrame = frame;
|
||||
print("Unwinding due to exception. (Type 'c' to continue unwinding.)");
|
||||
showFrame();
|
||||
print("Exception value is:");
|
||||
showDebuggeeValue(exc);
|
||||
return repl();
|
||||
});
|
||||
};
|
||||
|
||||
// The depth of jorendb nesting.
|
||||
var jorendbDepth;
|
||||
if (typeof jorendbDepth == 'undefined') jorendbDepth = 0;
|
||||
|
||||
var debuggeeGlobal = newGlobal("new-compartment");
|
||||
debuggeeGlobal.jorendbDepth = jorendbDepth + 1;
|
||||
dbg.addDebuggee(debuggeeGlobal);
|
||||
|
||||
print("jorendb version -0.0");
|
||||
prompt = '(' + Array(jorendbDepth+1).join('meta-') + 'jorendb)';
|
||||
print("Prompt is " + prompt);
|
||||
repl();
|
|
@ -1,125 +0,0 @@
|
|||
cc.log("welcome to cocos2d-x-javascript");
|
||||
|
||||
var Test = function () {
|
||||
};
|
||||
Test.prototype.assertNum = 0;
|
||||
Test.prototype.assertEqual = function (expr, target, str) {
|
||||
this.assertNum++;
|
||||
str = str || "";
|
||||
if (expr != target) {
|
||||
throw "assert failed: " + str + " (" + expr + ")";
|
||||
}
|
||||
};
|
||||
Test.prototype.assertFloatEqual = function (num1, target, str) {
|
||||
this.assertNum++;
|
||||
str = str || "";
|
||||
if (Math.abs(num1 - target) > 0.000001) {
|
||||
throw "assert failed: " + str + " (" + expr + ")";
|
||||
}
|
||||
};
|
||||
Test.prototype.setup = function () {};
|
||||
Test.prototype.run = function () {
|
||||
cc.log("Test started");
|
||||
var ok = 0, fail = 0, failed = [];
|
||||
for (var key in this) {
|
||||
if (key.match(/^test/)) {
|
||||
try {
|
||||
this[key]();
|
||||
ok++;
|
||||
} catch (e) {
|
||||
failed.push(this.assertNum + ": " + e);
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
}
|
||||
cc.log("total asserts: " + this.assertNum);
|
||||
cc.log("tests [ok]: " + ok);
|
||||
cc.log("tests [fail]: " + fail);
|
||||
cc.log(failed.join("\n"));
|
||||
};
|
||||
|
||||
var GeometryTest = function () {
|
||||
};
|
||||
GeometryTest.prototype = Object.create(Test.prototype);
|
||||
|
||||
GeometryTest.prototype.test_point1 = function () {
|
||||
var pt = new cc.Point();
|
||||
this.assertEqual(pt.x, 0, "pt.x == 0");
|
||||
this.assertEqual(pt.y, 0, "pt.y == 0");
|
||||
|
||||
pt.x = 0.5;
|
||||
pt.y = 13.37;
|
||||
this.assertFloatEqual(pt.x, 0.5, "pt.x == 0.5");
|
||||
this.assertFloatEqual(pt.y, 13.37, "pt.y == 13.37");
|
||||
};
|
||||
|
||||
GeometryTest.prototype.test_point2 = function () {
|
||||
var pt1 = new cc.Point();
|
||||
var pt2 = new cc.Point();
|
||||
pt1.x = 100.50;
|
||||
pt2.y = 99;
|
||||
pt1.y = pt1.x + pt2.y;
|
||||
this.assertFloatEqual(pt1.y, 100.50 + 99, "pt1.y == 100.50 + 99");
|
||||
};
|
||||
|
||||
GeometryTest.prototype.test_size1 = function () {
|
||||
var sz1 = new cc.Size();
|
||||
this.assertEqual(sz1.width, 0, "sz1.width == 0");
|
||||
this.assertEqual(sz1.height, 0, "sz1.height == 0");
|
||||
|
||||
sz1.width = 99.2323;
|
||||
sz1.height = 13.3700;
|
||||
this.assertFloatEqual(sz1.width, 99.2323, "sz1.width == 99.2323");
|
||||
this.assertFloatEqual(sz1.height, 13.3700, "sz1.height == 13.3700");
|
||||
};
|
||||
|
||||
GeometryTest.prototype.test_rect1 = function () {
|
||||
var rect = new cc.Rect();
|
||||
var orig = rect.origin;
|
||||
this.assertEqual(orig.x, 0, "orig.x == 0");
|
||||
this.assertEqual(orig.y, 0, "orig.y == 0");
|
||||
orig.x = 51343.034;
|
||||
|
||||
var orig2 = rect.origin;
|
||||
this.assertFloatEqual(orig2.x, orig.x, "orig2.x == orig.x");
|
||||
};
|
||||
|
||||
GeometryTest.prototype.test_rect2 = function () {
|
||||
var rect1 = new cc.Rect();
|
||||
var rect2 = new cc.Rect();
|
||||
var pt1 = new cc.Point();
|
||||
var pt2 = rect1.origin;
|
||||
|
||||
pt2.x = 500; pt2.y = 900;
|
||||
this.assertEqual(pt2.x, 500, "pt2.x == 500");
|
||||
this.assertEqual(pt2.y, 900, "pt2.y == 900");
|
||||
|
||||
pt1.x = 13.37; pt1.y = 13.13;
|
||||
rect2.origin = pt1;
|
||||
pt2 = rect2.origin;
|
||||
|
||||
this.assertFloatEqual(pt2.x, 13.37, "pt2.x == 13.37");
|
||||
this.assertFloatEqual(pt2.y, 13.13, "pt2.y == 13.13");
|
||||
};
|
||||
|
||||
test = new GeometryTest();
|
||||
test.run();
|
||||
|
||||
// small performance test
|
||||
|
||||
var totalIter = 10000;
|
||||
var rect = new cc.Rect();
|
||||
var pt = new cc.Point();
|
||||
var sum;
|
||||
|
||||
sum = 0;
|
||||
for (var i=0; i < totalIter; i++) {
|
||||
pt.x = i;
|
||||
var startTime = Date.now();
|
||||
rect.origin = pt;
|
||||
var endTime = Date.now();
|
||||
sum += (endTime - startTime) / 1000.0;
|
||||
}
|
||||
cc.log(totalIter + "\t" + sum);
|
||||
|
||||
cc.log("END OF TEST");
|
|
@ -1,121 +0,0 @@
|
|||
/**
|
||||
* trying to use the same benchmark that the guys from OA used:
|
||||
* http://openaphid.github.com/blog/2012/02/20/javascript-and-cocos2d-a-sneak-peek/
|
||||
*/
|
||||
|
||||
// taken from goog.inherits
|
||||
cc.inherits = function(childCtor, parentCtor) {
|
||||
/** @constructor */
|
||||
function tempCtor() {};
|
||||
tempCtor.prototype = parentCtor.prototype;
|
||||
childCtor.superClass_ = parentCtor.prototype;
|
||||
childCtor.prototype = new tempCtor();
|
||||
childCtor.prototype.constructor = childCtor;
|
||||
};
|
||||
|
||||
var scene = new cc.Scene();
|
||||
scene.init();
|
||||
var background = new cc.Sprite();
|
||||
background.initWithFile("background.png");
|
||||
scene.addChild(background);
|
||||
|
||||
var spriteFrameCache = cc.SpriteFrameCache.sharedSpriteFrameCache();
|
||||
spriteFrameCache.addSpriteFramesWithFile("tank.plist");
|
||||
|
||||
// wrapper around CCSprite
|
||||
var Tank = function () {
|
||||
var sprite = new cc.Sprite();
|
||||
sprite.initWithSpriteFrameName("tank1.png");
|
||||
|
||||
var pos = new cc.Point();
|
||||
pos.x = Math.random() * 320;
|
||||
pos.y = Math.random() * 480;
|
||||
sprite.position = pos;
|
||||
sprite.vx = Math.random() > 0.5 ? 100 : -100;
|
||||
sprite.vy = Math.random() > 0.5 ? 100 : -100;
|
||||
sprite.scheduleUpdate();
|
||||
sprite.update = function (delta) {
|
||||
var p = this.position;
|
||||
p.x += delta * this.vx;
|
||||
p.y += delta * this.vy;
|
||||
//set the new position
|
||||
this.position = p;
|
||||
|
||||
//make sure tank is inside the screen
|
||||
if (p.x < 0) {
|
||||
p.x = 0;
|
||||
this.vx = -this.vx;
|
||||
}
|
||||
|
||||
if (p.x > 320) {
|
||||
p.x = 320;
|
||||
this.vx = -this.vx;
|
||||
}
|
||||
|
||||
if (p.y < 0) {
|
||||
p.y = 0;
|
||||
this.vy = -this.vy;
|
||||
}
|
||||
|
||||
if (p.y > 480) {
|
||||
p.y = 480;
|
||||
this.vy = -this.vy;
|
||||
}
|
||||
};
|
||||
|
||||
this.sprite = sprite;
|
||||
};
|
||||
|
||||
// create animation
|
||||
var frames = ["tank1.png", "tank2.png", "tank3.png", "tank4.png", "tank5.png"];
|
||||
var animation = new cc.Animation();
|
||||
animation.init();
|
||||
animation.delay = 0.1;
|
||||
for (var i=0; i < frames.length; i++) {
|
||||
var frame = spriteFrameCache.spriteFrameByName(frames[i]);
|
||||
animation.addFrame(frame);
|
||||
}
|
||||
|
||||
// do the fun
|
||||
// global array to prevent GC
|
||||
var tanks = new Array(100);
|
||||
for (var i=0; i < tanks.length; i++) {
|
||||
var tank = new Tank();
|
||||
tank.tankId = i;
|
||||
scene.addChild(tank.sprite);
|
||||
if (i === 0) {
|
||||
// this is not working correctly (only on ccnodes)
|
||||
tank.sprite.onEnter = function () {
|
||||
cc.log("on enter");
|
||||
};
|
||||
}
|
||||
|
||||
// second argument false by default
|
||||
tank.action = new cc.Animate();
|
||||
tank.action.initWithAnimation(animation);
|
||||
tank.repeat = new cc.RepeatForever();
|
||||
tank.repeat.initWithAction(tank.action);
|
||||
tank.sprite.runAction(tank.repeat);
|
||||
|
||||
tanks[i] = tank;
|
||||
}
|
||||
|
||||
var layer = new cc.Layer();
|
||||
layer.onEnter = function () {
|
||||
cc.log("layer enter");
|
||||
};
|
||||
layer.isTouchEnabled = true;
|
||||
layer.ccTouchBegan = function (touch) {
|
||||
var point = touch.locationInView();
|
||||
cc.log("cc touch: " + point.x + "," + point.y);
|
||||
};
|
||||
layer.ccTouchesBegan = function (touches) {
|
||||
for (var i=0; i < touches.length; i++) {
|
||||
var point = touches[i].locationInView();
|
||||
cc.log("cc touches: " + point.x + "," + point.y);
|
||||
}
|
||||
};
|
||||
scene.addChild(layer);
|
||||
|
||||
var director = cc.Director.sharedDirector();
|
||||
director.runWithScene(scene);
|
|
@ -1,55 +0,0 @@
|
|||
var director = cc.Director.sharedDirector();
|
||||
var scene = new cc.Scene();
|
||||
scene.init();
|
||||
|
||||
// our test sprite
|
||||
var sprite = new cc.Sprite();
|
||||
sprite.initWithFile("Icon.png");
|
||||
var pt = new cc.Point();
|
||||
pt.x = 160;
|
||||
pt.y = 240;
|
||||
sprite.position = pt;
|
||||
|
||||
// will call "update" every frame if there's an update property
|
||||
//sprite.scheduleUpdate();
|
||||
sprite.speed = new cc.Point();
|
||||
sprite.speed.x = Math.random() * 10 - 5;
|
||||
sprite.speed.y = Math.random() * 10 - 5;
|
||||
|
||||
// the actual update function
|
||||
sprite.update = function () {
|
||||
var curPos = this.position;
|
||||
curPos.x += this.speed.x;
|
||||
curPos.y += this.speed.y;
|
||||
this.position = curPos;
|
||||
if (curPos.x >= 320 || curPos.x <= 0) this.speed.x *= -1;
|
||||
if (curPos.y >= 480 || curPos.y <= 0) this.speed.y *= -1;
|
||||
};
|
||||
|
||||
// adds the sprite to the scene
|
||||
scene.addChild(sprite);
|
||||
|
||||
// add a menu
|
||||
var item = new cc.MenuItemImage();//Sprite();
|
||||
//var normal = new cc.Sprite(); normal.initWithFile("CloseNormal.png");
|
||||
//var selected = new cc.Sprite(); selected.initWithFile("CloseSelected.png");
|
||||
//item.initWithNormalSprite(normal, selected);
|
||||
item.initFromNormalImage("CloseNormal.png", "CloseSelected.png");
|
||||
item.action = function () {
|
||||
cc.log("action");
|
||||
};
|
||||
cc.log("normal image: " + item.normalImage);
|
||||
pt.x = 20;
|
||||
pt.y = 20;
|
||||
item.position = pt;
|
||||
var menu = new cc.Menu();
|
||||
menu.init();
|
||||
menu.addChild(item);
|
||||
|
||||
pt.x = 0;
|
||||
pt.y = 0;
|
||||
menu.position = pt;
|
||||
scene.addChild(menu, 1);
|
||||
|
||||
// let the games begin
|
||||
director.runWithScene(scene);
|
Loading…
Reference in New Issue