mirror of https://github.com/axmolengine/axmol.git
Improve gc test case and add action cycle reference test
This commit is contained in:
parent
f8016978ff
commit
751e2f6eb8
|
@ -12,7 +12,6 @@ var MySprite = cc.Sprite.extend({
|
||||||
// Scene Test 1
|
// Scene Test 1
|
||||||
//
|
//
|
||||||
function runScene1(sender) {
|
function runScene1(sender) {
|
||||||
|
|
||||||
var scene = new cc.Scene();
|
var scene = new cc.Scene();
|
||||||
|
|
||||||
for (i = 0; i < 5; i++) {
|
for (i = 0; i < 5; i++) {
|
||||||
|
@ -21,16 +20,7 @@ function runScene1(sender) {
|
||||||
scene.addChild(sprite);
|
scene.addChild(sprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
// menu
|
return scene;
|
||||||
var button = new cc.MenuItemFont("Go to Scene 2", runScene2);
|
|
||||||
button.fontSize = 20;
|
|
||||||
button.fontName = "Arial";
|
|
||||||
var menu = new cc.Menu();
|
|
||||||
menu.addChild(button);
|
|
||||||
menu.setPosition(300,20);
|
|
||||||
scene.addChild(menu);
|
|
||||||
|
|
||||||
cc.director.replaceScene(scene);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -46,16 +36,7 @@ function runScene2(sender) {
|
||||||
scene.addChild(sprite);
|
scene.addChild(sprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
// menu
|
return scene;
|
||||||
var button = new cc.MenuItemFont("Go to Scene 3", runScene3);
|
|
||||||
button.fontSize = 20;
|
|
||||||
button.fontName = "Arial";
|
|
||||||
var menu = new cc.Menu();
|
|
||||||
menu.addChild(button);
|
|
||||||
menu.setPosition(300,20);
|
|
||||||
scene.addChild(menu);
|
|
||||||
|
|
||||||
cc.director.replaceScene(scene);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -72,19 +53,13 @@ function runScene3(sender) {
|
||||||
this.label.setPosition(300,300);
|
this.label.setPosition(300,300);
|
||||||
scene.addChild(this.label);
|
scene.addChild(this.label);
|
||||||
|
|
||||||
// menu
|
var touchListener = null;
|
||||||
var button = new cc.MenuItemFont("Go to Scene 4", runScene4);
|
var mouseListener = null;
|
||||||
button.fontSize = 20;
|
|
||||||
button.fontName = "Arial";
|
|
||||||
var menu = new cc.Menu();
|
|
||||||
menu.addChild(button);
|
|
||||||
menu.setPosition(300,20);
|
|
||||||
scene.addChild(menu);
|
|
||||||
|
|
||||||
// 'browser' can use touches or mouse.
|
// 'browser' can use touches or mouse.
|
||||||
// The benefit of using 'touches' in a browser, is that it works both with mouse events or touches events
|
// The benefit of using 'touches' in a browser, is that it works both with mouse events or touches events
|
||||||
if ('touches' in cc.sys.capabilities) {
|
if ('touches' in cc.sys.capabilities) {
|
||||||
cc.eventManager.addListener({
|
touchListener = cc.eventManager.addListener({
|
||||||
event: cc.EventListener.TOUCH_ALL_AT_ONCE,
|
event: cc.EventListener.TOUCH_ALL_AT_ONCE,
|
||||||
onTouchesMoved: function (touches, event) {
|
onTouchesMoved: function (touches, event) {
|
||||||
var delta = touches[0].getDelta();
|
var delta = touches[0].getDelta();
|
||||||
|
@ -94,7 +69,7 @@ function runScene3(sender) {
|
||||||
},
|
},
|
||||||
10);
|
10);
|
||||||
} else if ('mouse' in cc.sys.capabilities) {
|
} else if ('mouse' in cc.sys.capabilities) {
|
||||||
cc.eventManager.addListener({
|
mouseListener = cc.eventManager.addListener({
|
||||||
event: cc.EventListener.MOUSE,
|
event: cc.EventListener.MOUSE,
|
||||||
onMouseMove: function (event) {
|
onMouseMove: function (event) {
|
||||||
if(event.getButton() == cc.EventMouse.BUTTON_LEFT)
|
if(event.getButton() == cc.EventMouse.BUTTON_LEFT)
|
||||||
|
@ -109,7 +84,17 @@ function runScene3(sender) {
|
||||||
10);
|
10);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc.director.replaceScene(scene);
|
this.label.onExit = function () {
|
||||||
|
if (touchListener) {
|
||||||
|
cc.eventManager.removeListener(touchListener);
|
||||||
|
}
|
||||||
|
if (mouseListener) {
|
||||||
|
cc.eventManager.removeListener(mouseListener);
|
||||||
|
}
|
||||||
|
cc.LabelTTF.prototype.onExit.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
return scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -141,34 +126,116 @@ function runScene4(sender) {
|
||||||
var action = cc.sequence(actionUp, delay.clone()).repeatForever();
|
var action = cc.sequence(actionUp, delay.clone()).repeatForever();
|
||||||
sprite3.runAction(action);
|
sprite3.runAction(action);
|
||||||
|
|
||||||
|
return scene;
|
||||||
// menu
|
|
||||||
var button = new cc.MenuItemFont("Go to Scene 5", runScene5);
|
|
||||||
button.fontSize = 20;
|
|
||||||
button.fontName = "Arial";
|
|
||||||
var menu = new cc.Menu();
|
|
||||||
menu.addChild(button);
|
|
||||||
menu.setPosition(300,20);
|
|
||||||
scene.addChild(menu);
|
|
||||||
|
|
||||||
cc.director.replaceScene(scene);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function runScene5(sender) {
|
function runScene5(sender) {
|
||||||
var scene = new TreeScene(5);
|
var scene = new cc.Scene();
|
||||||
|
|
||||||
|
var tree = createTree(5, cc.rect(0, 0, cc.winSize.width, cc.winSize.height));
|
||||||
|
scene.addChild(tree);
|
||||||
|
|
||||||
// menu
|
// menu
|
||||||
var button = new cc.MenuItemFont("Go to Scene 1", runScene1);
|
var menu = new cc.Menu();
|
||||||
|
var button = new cc.MenuItemFont("Replace Tree", function () {
|
||||||
|
var s = tree.parent;
|
||||||
|
tree.removeFromParent(true);
|
||||||
|
var levels = 4 + Math.floor( Math.random() * 4 );
|
||||||
|
tree = createTree(levels, cc.rect(0, 0, cc.winSize.width, cc.winSize.height));
|
||||||
|
s.addChild(tree);
|
||||||
|
});
|
||||||
button.fontSize = 20;
|
button.fontSize = 20;
|
||||||
button.fontName = "Arial";
|
button.fontName = "Arial";
|
||||||
|
menu.addChild(button);
|
||||||
|
menu.setPosition(cc.winSize.width / 4, cc.winSize.height - 40);
|
||||||
|
scene.addChild(menu);
|
||||||
|
|
||||||
|
return scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
function runScene6 () {
|
||||||
|
var scene = new cc.Scene();
|
||||||
|
|
||||||
|
var callback = function () {
|
||||||
|
cc.log('A callback which do nothing');
|
||||||
|
};
|
||||||
|
|
||||||
|
var sprite = new cc.Sprite("res/Images/grossini_dance_01.png");
|
||||||
|
sprite.x = cc.winSize.width/2;
|
||||||
|
sprite.y = cc.winSize.height/2;
|
||||||
|
sprite.action = cc.callFunc(callback, sprite);
|
||||||
|
|
||||||
|
var SPRITE_TAG = 999;
|
||||||
|
scene.addChild(sprite, 0, SPRITE_TAG);
|
||||||
|
|
||||||
|
var fontDef = new cc.FontDefinition();
|
||||||
|
fontDef.fontName = "Arial";
|
||||||
|
fontDef.fontSize = 20;
|
||||||
|
fontDef.boundingWidth = cc.winSize.width * 0.8;
|
||||||
|
var label = new cc.LabelTTF("Click screen to remove sprite and it should be garbage collected", fontDef);
|
||||||
|
label.setPosition(cc.winSize.width / 2, cc.winSize.height / 2 + 100);
|
||||||
|
scene.addChild(label);
|
||||||
|
|
||||||
|
var touchListener = cc.eventManager.addListener({
|
||||||
|
event: cc.EventListener.TOUCH_ALL_AT_ONCE,
|
||||||
|
onTouchesEnded: function (touches, event) {
|
||||||
|
cc.sys.garbageCollect();
|
||||||
|
cc.sys.garbageCollect();
|
||||||
|
cc.log('You should see immidiately two release messages in Console (Sprite and Action)');
|
||||||
|
label.setString('You should see immidiately two release messages in Console (Sprite and Action)');
|
||||||
|
var target = event.getCurrentTarget();
|
||||||
|
target.removeChildByTag(SPRITE_TAG);
|
||||||
|
cc.sys.garbageCollect();
|
||||||
|
cc.eventManager.removeListener(touchListener);
|
||||||
|
}
|
||||||
|
}, scene);
|
||||||
|
|
||||||
|
return scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
var tests = [
|
||||||
|
runScene1,
|
||||||
|
runScene2,
|
||||||
|
runScene3,
|
||||||
|
runScene4,
|
||||||
|
runScene5,
|
||||||
|
runScene6
|
||||||
|
];
|
||||||
|
|
||||||
|
var replaceScene = (function () {
|
||||||
|
var curr = tests.length-1;
|
||||||
|
|
||||||
|
return function () {
|
||||||
|
if (curr < tests.length-1) {
|
||||||
|
curr++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
curr = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
var scene = tests[curr]();
|
||||||
|
|
||||||
|
// menu
|
||||||
var menu = new cc.Menu();
|
var menu = new cc.Menu();
|
||||||
|
var button = new cc.MenuItemFont("Next Scene", replaceScene);
|
||||||
|
button.fontSize = 20;
|
||||||
|
button.fontName = "Arial";
|
||||||
|
menu.addChild(button);
|
||||||
|
button = new cc.MenuItemFont("Run GC", cc.sys.garbageCollect);
|
||||||
|
button.fontSize = 20;
|
||||||
|
button.fontName = "Arial";
|
||||||
|
button.x = cc.winSize.width/4;
|
||||||
|
button.y = cc.winSize.height - 60;
|
||||||
menu.addChild(button);
|
menu.addChild(button);
|
||||||
menu.setPosition(cc.winSize.width/2, 20);
|
menu.setPosition(cc.winSize.width/2, 20);
|
||||||
scene.addChild(menu);
|
scene.addChild(menu);
|
||||||
|
|
||||||
cc.director.replaceScene(scene);
|
cc.director.replaceScene(scene);
|
||||||
}
|
|
||||||
|
cc.sys.garbageCollect();
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
//
|
//
|
||||||
// Main Entry point
|
// Main Entry point
|
||||||
|
@ -178,7 +245,7 @@ function runMain() {
|
||||||
var scene = new cc.Scene();
|
var scene = new cc.Scene();
|
||||||
|
|
||||||
// menu
|
// menu
|
||||||
var button = new cc.MenuItemFont("Start Test", runScene1);
|
var button = new cc.MenuItemFont("Start Test", replaceScene);
|
||||||
button.fontSize = 20;
|
button.fontSize = 20;
|
||||||
button.fontName = "Arial";
|
button.fontName = "Arial";
|
||||||
var menu = new cc.Menu();
|
var menu = new cc.Menu();
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
var TreeScene = (function () {
|
var createTree = (function () {
|
||||||
|
|
||||||
var _ORIGIN_WIDTH = 85;
|
var _ORIGIN_WIDTH = 85;
|
||||||
var _ORIGIN_HEIGHT = 121;
|
var _ORIGIN_HEIGHT = 121;
|
||||||
|
@ -29,7 +29,7 @@ var _createLevel = function (upLevel, width, height, scale) {
|
||||||
return level;
|
return level;
|
||||||
};
|
};
|
||||||
|
|
||||||
var _createTree = function (levels, zone) {
|
return function (levels, zone) {
|
||||||
var height = zone.height / levels;
|
var height = zone.height / levels;
|
||||||
var scale = height * 0.9 / _ORIGIN_HEIGHT;
|
var scale = height * 0.9 / _ORIGIN_HEIGHT;
|
||||||
if (scale > 1) scale = 1;
|
if (scale > 1) scale = 1;
|
||||||
|
@ -42,36 +42,4 @@ var _createTree = function (levels, zone) {
|
||||||
return root;
|
return root;
|
||||||
};
|
};
|
||||||
|
|
||||||
var TreeScene = cc.Scene.extend({
|
|
||||||
ctor: function (levels) {
|
|
||||||
this._super();
|
|
||||||
this.levels = levels;
|
|
||||||
|
|
||||||
this.tree = _createTree(levels, cc.rect(0, 0, cc.winSize.width, cc.winSize.height));
|
|
||||||
this.addChild(this.tree);
|
|
||||||
|
|
||||||
// menu
|
|
||||||
var menu = new cc.Menu();
|
|
||||||
var button = new cc.MenuItemFont("Replace Tree", this.replaceTree, this);
|
|
||||||
button.fontSize = 20;
|
|
||||||
button.fontName = "Arial";
|
|
||||||
menu.addChild(button);
|
|
||||||
button = new cc.MenuItemFont("Run GC", cc.sys.garbageCollect);
|
|
||||||
button.fontSize = 20;
|
|
||||||
button.fontName = "Arial";
|
|
||||||
button.x = 150;
|
|
||||||
menu.addChild(button);
|
|
||||||
menu.setPosition(cc.winSize.width * 3/4 - 50, cc.winSize.height - 40);
|
|
||||||
this.addChild(menu);
|
|
||||||
},
|
|
||||||
|
|
||||||
replaceTree: function () {
|
|
||||||
this.tree.removeFromParent(true);
|
|
||||||
this.tree = _createTree(this.levels, cc.rect(0, 0, cc.winSize.width, cc.winSize.height));
|
|
||||||
this.addChild(this.tree);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return TreeScene;
|
|
||||||
|
|
||||||
})();
|
})();
|
Loading…
Reference in New Issue