mirror of https://github.com/axmolengine/axmol.git
Adding CocosDragonJS project
This commit is contained in:
parent
36bbd80b68
commit
cfb59529a8
|
@ -0,0 +1,85 @@
|
|||
#include "AppDelegate.h"
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "SimpleAudioEngine.h"
|
||||
#include "ScriptingCore.h"
|
||||
#include "generated/cocos2dx.hpp"
|
||||
#include "cocos2d_specifics.hpp"
|
||||
#include "js_bindings_chipmunk_registration.h"
|
||||
#include "js_bindings_ccbreader.h"
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace CocosDenshion;
|
||||
|
||||
AppDelegate::AppDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
AppDelegate::~AppDelegate()
|
||||
{
|
||||
CCScriptEngineManager::sharedManager()->purgeSharedManager();
|
||||
}
|
||||
|
||||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
// initialize director
|
||||
CCDirector *pDirector = CCDirector::sharedDirector();
|
||||
pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
|
||||
|
||||
// turn on display FPS
|
||||
pDirector->setDisplayStats(true);
|
||||
|
||||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
pDirector->setAnimationInterval(1.0 / 60);
|
||||
|
||||
ScriptingCore* sc = ScriptingCore::getInstance();
|
||||
sc->addRegisterCallback(register_all_cocos2dx);
|
||||
sc->addRegisterCallback(register_cocos2dx_js_extensions);
|
||||
sc->addRegisterCallback(register_CCBuilderReader);
|
||||
sc->addRegisterCallback(jsb_register_chipmunk);
|
||||
|
||||
sc->start();
|
||||
|
||||
js_log("RUNNING Main");
|
||||
CCScriptEngineProtocol *pEngine = ScriptingCore::getInstance();
|
||||
CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine);
|
||||
ScriptingCore::getInstance()->runScript("main.js");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void handle_signal(int signal) {
|
||||
static int internal_state = 0;
|
||||
ScriptingCore* sc = ScriptingCore::getInstance();
|
||||
// should start everything back
|
||||
CCDirector* director = CCDirector::sharedDirector();
|
||||
if (director->getRunningScene()) {
|
||||
director->popToRootScene();
|
||||
} else {
|
||||
CCPoolManager::sharedPoolManager()->finalize();
|
||||
if (internal_state == 0) {
|
||||
//sc->dumpRoot(NULL, 0, NULL);
|
||||
sc->start();
|
||||
internal_state = 1;
|
||||
} else {
|
||||
sc->runScript("hello.js");
|
||||
internal_state = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground()
|
||||
{
|
||||
CCDirector::sharedDirector()->stopAnimation();
|
||||
SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
|
||||
SimpleAudioEngine::sharedEngine()->pauseAllEffects();
|
||||
}
|
||||
|
||||
// this function will be called when the app is active again
|
||||
void AppDelegate::applicationWillEnterForeground()
|
||||
{
|
||||
CCDirector::sharedDirector()->startAnimation();
|
||||
SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
||||
SimpleAudioEngine::sharedEngine()->resumeAllEffects();
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
//
|
||||
// GCTestAppDelegate.h
|
||||
// GCTest
|
||||
//
|
||||
// Created by Rohan Kuruvilla on 06/08/2012.
|
||||
// Copyright __MyCompanyName__ 2012. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef _APP_DELEGATE_H_
|
||||
#define _APP_DELEGATE_H_
|
||||
|
||||
#include "CCApplication.h"
|
||||
/**
|
||||
@brief The cocos2d Application.
|
||||
|
||||
The reason for implement as private inheritance is to hide some interface call by CCDirector.
|
||||
*/
|
||||
class AppDelegate : private cocos2d::CCApplication
|
||||
{
|
||||
public:
|
||||
AppDelegate();
|
||||
virtual ~AppDelegate();
|
||||
|
||||
/**
|
||||
@brief Implement CCDirector and CCScene init code here.
|
||||
@return true Initialize success, app continue.
|
||||
@return false Initialize failed, app terminate.
|
||||
*/
|
||||
virtual bool applicationDidFinishLaunching();
|
||||
|
||||
/**
|
||||
@brief The function be called when the application enter background
|
||||
@param the pointer of the application
|
||||
*/
|
||||
virtual void applicationDidEnterBackground();
|
||||
|
||||
/**
|
||||
@brief The function be called when the application enter foreground
|
||||
@param the pointer of the application
|
||||
*/
|
||||
virtual void applicationWillEnterForeground();
|
||||
};
|
||||
|
||||
#endif // _APP_DELEGATE_H_
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/* http://www.cocosbuilder.com
|
||||
* http://www.cocos2d-iphone.org
|
||||
*
|
||||
* Copyright (c) 2012 Zynga, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
//
|
||||
// Controller for the Bomb Object
|
||||
// When the Dragon (hero) touches this object, the Dragon moves downwards.
|
||||
//
|
||||
var Bomb = function()
|
||||
{
|
||||
this.radius = 15;
|
||||
};
|
||||
|
||||
Bomb.prototype.onUpdate = function()
|
||||
{};
|
||||
|
||||
Bomb.prototype.handleCollisionWith = function(gameObjectController)
|
||||
{
|
||||
if (gameObjectController.controllerName == "Dragon")
|
||||
{
|
||||
// Collided with the dragon, remove object and add an exposion instead
|
||||
this.isScheduledForRemove = true;
|
||||
|
||||
cc.AudioEngine.getInstance().playEffect("Explo.caf");
|
||||
|
||||
var explosion = cc.Reader.load("Explosion.ccbi");
|
||||
explosion.setPosition(this.rootNode.getPosition());
|
||||
|
||||
this.rootNode.getParent().addChild(explosion);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,46 @@
|
|||
/* http://www.cocosbuilder.com
|
||||
* http://www.cocos2d-iphone.org
|
||||
*
|
||||
* Copyright (c) 2012 Zynga, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
//
|
||||
// Controller for the Coin Object
|
||||
// When the Dragon (hero) touches this object, the Dragon moves upwards
|
||||
//
|
||||
|
||||
var Coin = function()
|
||||
{
|
||||
this.radius = 15;
|
||||
};
|
||||
|
||||
Coin.prototype.onUpdate = function()
|
||||
{};
|
||||
|
||||
Coin.prototype.handleCollisionWith = function(gameObjectController)
|
||||
{
|
||||
if (gameObjectController.controllerName == "Dragon")
|
||||
{
|
||||
cc.AudioEngine.getInstance().playEffect("Coin.caf");
|
||||
this.isScheduledForRemove = true;
|
||||
}
|
||||
};
|
|
@ -0,0 +1,85 @@
|
|||
/* http://www.cocosbuilder.com
|
||||
* http://www.cocos2d-iphone.org
|
||||
*
|
||||
* Copyright (c) 2012 Zynga, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
//
|
||||
// controller for the Dragon Object (the Hero)
|
||||
//
|
||||
|
||||
// Constants
|
||||
var CD_START_SPEED = 8;
|
||||
var CD_COIN_SPEED = 8;
|
||||
var CD_START_TARGET = 160;
|
||||
|
||||
var CD_TARGET_FILTER_FACTOR = 0.05;
|
||||
var CD_SLOW_DOWN_FACTOR = 0.995;
|
||||
var CD_GRAVITY_SPEED = 0.1;
|
||||
var CD_GAMEOVER_SPEED = -10;
|
||||
var CD_DELTA_TO_ROTATION_FACTOR = 5;
|
||||
|
||||
var Dragon = function()
|
||||
{
|
||||
this.xTarget = CD_START_TARGET*gScaleFactor;
|
||||
this.ySpeed = CD_START_SPEED;
|
||||
this.radius = 25;
|
||||
};
|
||||
|
||||
Dragon.prototype.onUpdate = function()
|
||||
{
|
||||
// Calculate the new position
|
||||
var oldPosition = cc.pMult(this.rootNode.getPosition(), 1.0/gScaleFactor);
|
||||
|
||||
var xNew = (this.xTarget/gScaleFactor) * CD_TARGET_FILTER_FACTOR + oldPosition.x * (1-CD_TARGET_FILTER_FACTOR);
|
||||
var yNew = oldPosition.y + this.ySpeed;
|
||||
this.rootNode.setPosition(xNew*gScaleFactor, yNew*gScaleFactor);
|
||||
|
||||
// Update the vertical speed
|
||||
this.ySpeed = (this.ySpeed - CD_GRAVITY_SPEED) * CD_SLOW_DOWN_FACTOR;
|
||||
|
||||
// Tilt the dragon
|
||||
var xDelta = xNew - oldPosition.x;
|
||||
this.rootNode.setRotation(xDelta * CD_DELTA_TO_ROTATION_FACTOR);
|
||||
|
||||
// Check for game over
|
||||
if (this.ySpeed < CD_GAMEOVER_SPEED)
|
||||
{
|
||||
sharedGameScene.handleGameOver();
|
||||
}
|
||||
};
|
||||
|
||||
Dragon.prototype.handleCollisionWith = function(gameObjectController)
|
||||
{
|
||||
if (gameObjectController.controllerName == "Coin")
|
||||
{
|
||||
// Took a coin
|
||||
this.ySpeed = CD_COIN_SPEED;
|
||||
sharedGameScene.setScore(sharedGameScene.score+1);
|
||||
}
|
||||
else if (gameObjectController.controllerName == "Bomb")
|
||||
{
|
||||
// Hit a bomb
|
||||
if (this.ySpeed > 0) this.ySpeed = 0;
|
||||
|
||||
this.rootNode.animationManager.runAnimationsForSequenceNamed("Hit");
|
||||
}
|
||||
};
|
|
@ -0,0 +1,45 @@
|
|||
/* http://www.cocosbuilder.com
|
||||
* http://www.cocos2d-iphone.org
|
||||
*
|
||||
* Copyright (c) 2012 Zynga, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
//
|
||||
// Controller for the EndCoin object
|
||||
// When the Dragon (hero) touches this object, the game is won.
|
||||
//
|
||||
var EndCoin = function()
|
||||
{
|
||||
this.radius = 15;
|
||||
};
|
||||
|
||||
EndCoin.prototype.onUpdate = function()
|
||||
{};
|
||||
|
||||
EndCoin.prototype.handleCollisionWith = function(gameObjectController)
|
||||
{
|
||||
if (gameObjectController.controllerName == "Dragon")
|
||||
{
|
||||
cc.AudioEngine.getInstance().playEffect("Coin.caf");
|
||||
this.isScheduledForRemove = true;
|
||||
sharedGameScene.handleLevelComplete();
|
||||
}
|
||||
};
|
|
@ -0,0 +1,49 @@
|
|||
/* http://www.cocosbuilder.com
|
||||
* http://www.cocos2d-iphone.org
|
||||
*
|
||||
* Copyright (c) 2012 Zynga, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
//
|
||||
// Controller for the Bomb Object
|
||||
// This object is run when the Dragon (hero) touches a bomb
|
||||
//
|
||||
|
||||
var Explosion = function()
|
||||
{
|
||||
this.radius = 15;
|
||||
};
|
||||
|
||||
Explosion.prototype.onDidLoadFromCCB = function()
|
||||
{
|
||||
this.rootNode.animationManager.setCompletedAnimationCallback(this, this.onAnimationComplete);
|
||||
};
|
||||
|
||||
Explosion.prototype.onUpdate = function()
|
||||
{};
|
||||
|
||||
Explosion.prototype.handleCollisionWith = function(gameObjectController)
|
||||
{};
|
||||
|
||||
Explosion.prototype.onAnimationComplete = function(animationManager)
|
||||
{
|
||||
this.isScheduledForRemove = true;
|
||||
};
|
|
@ -0,0 +1,71 @@
|
|||
/* http://www.cocosbuilder.com
|
||||
* http://www.cocos2d-iphone.org
|
||||
*
|
||||
* Copyright (c) 2012 Zynga, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
//
|
||||
// Controller for the GameScene Object
|
||||
// This object loads the main Scene
|
||||
//
|
||||
|
||||
var GameScene = function(){};
|
||||
var sharedGameScene;
|
||||
var gLevelOffsetX = 0;
|
||||
|
||||
GameScene.prototype.onDidLoadFromCCB = function()
|
||||
{
|
||||
sharedGameScene = this;
|
||||
|
||||
this.score = 0;
|
||||
|
||||
var level = cc.Reader.load("Level.ccbi");
|
||||
|
||||
// Center the level on Screen
|
||||
gLevelOffsetX = (gWinSize.width-CD_LEVEL_WIDTH*gScaleFactor)/2;
|
||||
|
||||
level.setPosition(cc.p(gLevelOffsetX,0));
|
||||
|
||||
this.rootNode.addChild(level);
|
||||
};
|
||||
|
||||
GameScene.prototype.setScore = function(score)
|
||||
{
|
||||
this.score = score;
|
||||
this.scoreLabel.setString(""+score);
|
||||
};
|
||||
|
||||
GameScene.prototype.getScore = function()
|
||||
{
|
||||
return this.score;
|
||||
};
|
||||
|
||||
GameScene.prototype.handleGameOver = function()
|
||||
{
|
||||
var scene = cc.Reader.loadAsScene("MainMenuScene.ccbi");
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
};
|
||||
|
||||
GameScene.prototype.handleLevelComplete = function()
|
||||
{
|
||||
var scene = cc.Reader.loadAsScene("MainMenuScene.ccbi");
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
};
|
|
@ -0,0 +1,166 @@
|
|||
/* http://www.cocosbuilder.com
|
||||
* http://www.cocos2d-iphone.org
|
||||
*
|
||||
* Copyright (c) 2012 Zynga, Inc.
|
||||
*
|
||||
* 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 CD_LEVEL_WIDTH = 320;
|
||||
var CD_SCROLL_FILTER_FACTOR = 0.1;
|
||||
var CD_DRAGON_TARGET_OFFET = 80;
|
||||
|
||||
// Accelerometer
|
||||
var CD_ACCEL_FILTER_FACTOR = 0.25;
|
||||
|
||||
/**
|
||||
* Level is the controller object of the game:
|
||||
* It receives the following events:
|
||||
* - onUpdate
|
||||
* - Input events like touches, mouse and accelerometer
|
||||
*/
|
||||
var Level = function(){
|
||||
this.winSize = cc.Director.getInstance().getWinSize();
|
||||
|
||||
// Used for the low-pass filter on the accelerometer
|
||||
this.prevX = 0;
|
||||
};
|
||||
|
||||
Level.prototype.onDidLoadFromCCB = function()
|
||||
{
|
||||
// Forward relevant touch events to controller (this)
|
||||
this.rootNode.onTouchesBegan = function( touches, event) {
|
||||
this.controller.onTouchesBegan(touches, event);
|
||||
return true;
|
||||
};
|
||||
this.rootNode.onTouchesMoved = function( touches, event) {
|
||||
this.controller.onTouchesMoved(touches, event);
|
||||
return true;
|
||||
};
|
||||
this.rootNode.onMouseDragged = function( event) {
|
||||
this.controller.onMouseDragged(event);
|
||||
return true;
|
||||
};
|
||||
|
||||
this.rootNode.onAccelerometer = function( event) {
|
||||
this.controller.onAccelerometer(event);
|
||||
};
|
||||
|
||||
// Schedule callback
|
||||
this.rootNode.onUpdate = function(dt) {
|
||||
this.controller.onUpdate();
|
||||
};
|
||||
this.rootNode.schedule(this.rootNode.onUpdate);
|
||||
};
|
||||
|
||||
//
|
||||
// Events
|
||||
//
|
||||
Level.prototype.onTouchesBegan = function(touches, event)
|
||||
{
|
||||
if (gSettingControlType != CD_CONTROLTYPE_TOUCH) return;
|
||||
|
||||
var loc = touches[0].getLocation();
|
||||
this.dragon.controller.xTarget = loc.x - gLevelOffsetX;
|
||||
};
|
||||
|
||||
Level.prototype.onTouchesMoved = function(touches, event)
|
||||
{
|
||||
if (gSettingControlType != CD_CONTROLTYPE_TOUCH) return;
|
||||
|
||||
var loc = touches[0].getLocation();
|
||||
this.dragon.controller.xTarget = loc.x - gLevelOffsetX;
|
||||
};
|
||||
|
||||
Level.prototype.onMouseDragged = function(event)
|
||||
{
|
||||
if (gSettingControlType != CD_CONTROLTYPE_TOUCH) return;
|
||||
|
||||
var loc = event.getLocation();
|
||||
this.dragon.controller.xTarget = loc.x;
|
||||
};
|
||||
|
||||
Level.prototype.onAccelerometer = function(accelEvent)
|
||||
{
|
||||
if (gSettingControlType != CD_CONTROLTYPE_TILT) return;
|
||||
|
||||
// low pass filter for accelerometer. This makes the movement softer
|
||||
var accelX = accelEvent.x * CD_ACCEL_FILTER_FACTOR + (1 - CD_ACCEL_FILTER_FACTOR) * this.prevX;
|
||||
this.prevX = accelX;
|
||||
|
||||
var newX = this.winSize.width * accelX + this.winSize.width/2;
|
||||
this.dragon.controller.xTarget = newX;
|
||||
// cc.log('Accel x: '+ accelEvent.x + ' y:' + accelEvent.y + ' z:' + accelEvent.z + ' time:' + accelEvent.timestamp );
|
||||
};
|
||||
|
||||
|
||||
// Game main loop
|
||||
Level.prototype.onUpdate = function(dt)
|
||||
{
|
||||
var i=0;
|
||||
var gameObject = null;
|
||||
var gameObjectController = null;
|
||||
|
||||
// Iterate though all objects in the level layer
|
||||
var children = this.rootNode.getChildren();
|
||||
for (i = 0; i < children.length; i++)
|
||||
{
|
||||
// Check if the child has a controller (only the updatable objects will have one)
|
||||
gameObject = children[i];
|
||||
gameObjectController = gameObject.controller;
|
||||
if (gameObjectController)
|
||||
{
|
||||
// Update all game objects
|
||||
gameObjectController.onUpdate();
|
||||
|
||||
var gameObjectPos = cc.pMult(gameObject.getPosition(), 1.0/gScaleFactor);
|
||||
var dragonPos = cc.pMult(this.dragon.getPosition(), 1.0/gScaleFactor);
|
||||
|
||||
// Check for collisions with dragon
|
||||
if (gameObject !== this.dragon)
|
||||
{
|
||||
if (cc.pDistance(gameObjectPos, dragonPos) < gameObjectController.radius + this.dragon.controller.radius)
|
||||
{
|
||||
gameObjectController.handleCollisionWith(this.dragon.controller);
|
||||
this.dragon.controller.handleCollisionWith(gameObjectController);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check for objects to remove
|
||||
for (i = children.length-1; i >=0; i--)
|
||||
{
|
||||
gameObject = children[i];
|
||||
gameObjectController = gameObject.controller;
|
||||
if (gameObjectController && gameObjectController.isScheduledForRemove)
|
||||
{
|
||||
this.rootNode.removeChild(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
// Adjust position of the layer so dragon is visible
|
||||
var yTarget = CD_DRAGON_TARGET_OFFET - this.dragon.getPosition().y;
|
||||
var oldLayerPosition = this.rootNode.getPosition();
|
||||
|
||||
var xNew = oldLayerPosition.x;
|
||||
var yNew = yTarget * CD_SCROLL_FILTER_FACTOR + oldLayerPosition.y * (1 - CD_SCROLL_FILTER_FACTOR);
|
||||
|
||||
this.rootNode.setPosition(xNew, yNew);
|
||||
};
|
|
@ -0,0 +1,104 @@
|
|||
/* http://www.cocosbuilder.com
|
||||
* http://www.cocos2d-iphone.org
|
||||
*
|
||||
* Copyright (c) 2012 Zynga, Inc.
|
||||
*
|
||||
* 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 CD_CONTROLTYPE_TOUCH = 0;
|
||||
var CD_CONTROLTYPE_TILT = 1;
|
||||
|
||||
// Setup global variables
|
||||
var gSettingMusicEnabled = true;
|
||||
var gSettingControlType;
|
||||
|
||||
var gWinSize = cc.Director.getInstance().getWinSize();
|
||||
|
||||
var gScaleFactor;
|
||||
if (gWinSize.width <= 320) gScaleFactor = 1;
|
||||
else gScaleFactor = 2;
|
||||
|
||||
// Start playing looped background music
|
||||
cc.AudioEngine.getInstance().setEffectsVolume(0.2);
|
||||
cc.AudioEngine.getInstance().playMusic("Music.mp3");
|
||||
|
||||
//
|
||||
// MainMenuScene class
|
||||
//
|
||||
|
||||
var MainMenuScene = function(){};
|
||||
|
||||
MainMenuScene.prototype.updateSettingsDisplay = function()
|
||||
{
|
||||
// Music on/off
|
||||
this.sprtMusicOff.setVisible(!gSettingMusicEnabled);
|
||||
|
||||
// Controls
|
||||
if (gSettingControlType == CD_CONTROLTYPE_TOUCH)
|
||||
{
|
||||
this.sprtControlTouch.setVisible(true);
|
||||
this.sprtControlTilt.setVisible(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.sprtControlTouch.setVisible(false);
|
||||
this.sprtControlTilt.setVisible(true);
|
||||
}
|
||||
};
|
||||
|
||||
MainMenuScene.prototype.onDidLoadFromCCB = function()
|
||||
{
|
||||
this.updateSettingsDisplay();
|
||||
};
|
||||
|
||||
MainMenuScene.prototype.onPressedPlay = function()
|
||||
{
|
||||
var scene = cc.Reader.loadAsScene("GameScene.ccbi");
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
};
|
||||
|
||||
MainMenuScene.prototype.onPressedMusic = function()
|
||||
{
|
||||
gSettingMusicEnabled = !gSettingMusicEnabled;
|
||||
|
||||
if (gSettingMusicEnabled)
|
||||
{
|
||||
cc.AudioEngine.getInstance().playMusic("Music.mp3");
|
||||
}
|
||||
else
|
||||
{
|
||||
cc.AudioEngine.getInstance().stopMusic();
|
||||
}
|
||||
|
||||
this.updateSettingsDisplay();
|
||||
};
|
||||
|
||||
MainMenuScene.prototype.onPressedControl = function()
|
||||
{
|
||||
if (gSettingControlType == CD_CONTROLTYPE_TOUCH)
|
||||
{
|
||||
gSettingControlType = CD_CONTROLTYPE_TILT;
|
||||
}
|
||||
else
|
||||
{
|
||||
gSettingControlType = CD_CONTROLTYPE_TOUCH;
|
||||
}
|
||||
this.updateSettingsDisplay();
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
5783809fbb118e460886314c5da4429ea1f6577d
|
|
@ -0,0 +1,22 @@
|
|||
// Autogenerated main.js file
|
||||
|
||||
require("jsb_constants.js");
|
||||
require("Bomb.js");
|
||||
require("Coin.js");
|
||||
require("Dragon.js");
|
||||
require("EndCoin.js");
|
||||
require("Explosion.js");
|
||||
require("GameScene.js");
|
||||
require("Level.js");
|
||||
require("MainMenuScene.js");
|
||||
|
||||
function main()
|
||||
{
|
||||
var scene = cc.Reader.loadAsScene("MainMenuScene.ccbi");
|
||||
var director = cc.Director.getInstance();
|
||||
var runningScene = director.getRunningScene();
|
||||
if (runningScene === null) director.runWithScene(scene);
|
||||
else director.replaceScene(scene);
|
||||
}
|
||||
|
||||
main();
|
|
@ -0,0 +1 @@
|
|||
b0c5e740238e0eb308fa7c7d919b955788ce98db
|
|
@ -0,0 +1 @@
|
|||
b0c5e740238e0eb308fa7c7d919b955788ce98db
|
|
@ -0,0 +1 @@
|
|||
6e1a684f77d5fceff75f93f9e269576d0f88c06f
|
|
@ -0,0 +1 @@
|
|||
373c2b2260c711a02a90ad3b68abd7a1853a0527
|
|
@ -0,0 +1 @@
|
|||
af983ed63f13ab325322da1bbb6917290b6142f2
|
|
@ -0,0 +1 @@
|
|||
74cec9c4c8844fed81ea1f0323eb57df1737a1a3
|
|
@ -0,0 +1 @@
|
|||
969548df813b9d834bdce8848a34d20b69995612
|
|
@ -0,0 +1,306 @@
|
|||
/****************************************************************************
|
||||
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_NODE = 5560;
|
||||
var TAG_GROSSINI = 5561;
|
||||
var TAG_SEQUENCE = 5562;
|
||||
|
||||
var sceneIdx = -1;
|
||||
var MAX_LAYER = 5;
|
||||
|
||||
var nextActionManagerAction = function () {
|
||||
sceneIdx++;
|
||||
sceneIdx = sceneIdx % MAX_LAYER;
|
||||
|
||||
return createActionManagerLayer(sceneIdx);
|
||||
};
|
||||
var backActionManagerAction = function () {
|
||||
sceneIdx--;
|
||||
if (sceneIdx < 0)
|
||||
sceneIdx += MAX_LAYER;
|
||||
|
||||
return createActionManagerLayer(sceneIdx);
|
||||
};
|
||||
var restartActionManagerAction = function () {
|
||||
return createActionManagerLayer(sceneIdx);
|
||||
};
|
||||
|
||||
var createActionManagerLayer = function (index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return new CrashTest();
|
||||
case 1:
|
||||
return new LogicTest();
|
||||
case 2:
|
||||
return new PauseTest();
|
||||
case 3:
|
||||
return new RemoveTest();
|
||||
case 4:
|
||||
return new ResumeTest();
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// ActionManagerTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var ActionManagerTest = cc.Layer.extend({
|
||||
_atlas:null,
|
||||
_title:"",
|
||||
|
||||
ctor:function () {
|
||||
this._super();
|
||||
},
|
||||
title:function () {
|
||||
return "No title";
|
||||
},
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 32);
|
||||
this.addChild(label, 1);
|
||||
label.setPosition(cc.p(s.width / 2, s.height - 50));
|
||||
|
||||
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);
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3);
|
||||
|
||||
menu.setPosition(cc.p(0,0));
|
||||
item1.setPosition(cc.p(s.width / 2 - item2.getContentSize().width * 2, item2.getContentSize().height / 2));
|
||||
item2.setPosition(cc.p(s.width / 2, item2.getContentSize().height / 2));
|
||||
item3.setPosition(cc.p(s.width / 2 + item2.getContentSize().width * 2, item2.getContentSize().height / 2));
|
||||
|
||||
this.addChild(menu, 1);
|
||||
},
|
||||
|
||||
restartCallback:function (sender) {
|
||||
var s = new ActionManagerTestScene();
|
||||
s.addChild(restartActionManagerAction());
|
||||
cc.Director.getInstance().replaceScene(s);
|
||||
},
|
||||
nextCallback:function (sender) {
|
||||
var s = new ActionManagerTestScene();
|
||||
s.addChild(nextActionManagerAction());
|
||||
cc.Director.getInstance().replaceScene(s);
|
||||
},
|
||||
backCallback:function (sender) {
|
||||
var s = new ActionManagerTestScene();
|
||||
s.addChild(backActionManagerAction());
|
||||
cc.Director.getInstance().replaceScene(s);
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Test1
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var CrashTest = ActionManagerTest.extend({
|
||||
title:function () {
|
||||
return "Test 1. Should not crash";
|
||||
},
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var child = cc.Sprite.create(s_pathGrossini);
|
||||
child.setPosition(cc.p(200, 200));
|
||||
this.addChild(child, 1);
|
||||
|
||||
//Sum of all action's duration is 1.5 second.
|
||||
child.runAction(cc.RotateBy.create(1.5, 90));
|
||||
child.runAction(cc.Sequence.create(
|
||||
cc.DelayTime.create(1.4),
|
||||
cc.FadeOut.create(1.1))
|
||||
);
|
||||
|
||||
//After 1.5 second, self will be removed.
|
||||
this.runAction(cc.Sequence.create(
|
||||
cc.DelayTime.create(1.4),
|
||||
cc.CallFunc.create(this, this.removeThis))
|
||||
);
|
||||
},
|
||||
removeThis:function () {
|
||||
this._parent.removeChild(this, true);
|
||||
this.nextCallback(this);
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Test2
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var LogicTest = ActionManagerTest.extend({
|
||||
title:function () {
|
||||
return "Logic test";
|
||||
},
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var grossini = cc.Sprite.create(s_pathGrossini);
|
||||
this.addChild(grossini, 0, 2);
|
||||
grossini.setPosition(cc.p(200, 200));
|
||||
|
||||
grossini.runAction(cc.Sequence.create(
|
||||
cc.MoveBy.create(1, cc.p(150, 0)),
|
||||
cc.CallFunc.create(this, this.bugMe))
|
||||
);
|
||||
},
|
||||
bugMe:function (node) {
|
||||
node.stopAllActions(); //After this stop next action not working, if remove this stop everything is working
|
||||
node.runAction(cc.ScaleTo.create(2, 2));
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// PauseTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var PauseTest = ActionManagerTest.extend({
|
||||
title:function () {
|
||||
return "Pause Test";
|
||||
},
|
||||
onEnter:function () {
|
||||
//
|
||||
// This test MUST be done in 'onEnter' and not on 'init'
|
||||
// otherwise the paused action will be resumed at 'onEnter' time
|
||||
//
|
||||
this._super();
|
||||
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
var l = cc.LabelTTF.create("After 5 seconds grossini should move", "Thonburi", 16);
|
||||
this.addChild(l);
|
||||
l.setPosition(cc.p(s.width / 2, 245));
|
||||
|
||||
//
|
||||
// Also, this test MUST be done, after [super onEnter]
|
||||
//
|
||||
var grossini = cc.Sprite.create(s_pathGrossini);
|
||||
this.addChild(grossini, 0, TAG_GROSSINI);
|
||||
grossini.setPosition(cc.p(200, 200));
|
||||
|
||||
var action = cc.MoveBy.create(1, cc.p(150, 0));
|
||||
|
||||
cc.Director.getInstance().getActionManager().addAction(action, grossini, true);
|
||||
|
||||
this.schedule(this.unpause, 3);
|
||||
},
|
||||
unpause:function (dt) {
|
||||
this.unschedule(this.unpause);
|
||||
var node = this.getChildByTag(TAG_GROSSINI);
|
||||
cc.Director.getInstance().getActionManager().resumeTarget(node);
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// RemoveTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var RemoveTest = ActionManagerTest.extend({
|
||||
title:function () {
|
||||
return "Remove Test";
|
||||
},
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
var l = cc.LabelTTF.create("Should not crash", "Thonburi", 16);
|
||||
this.addChild(l);
|
||||
l.setPosition(cc.p(s.width / 2, 245));
|
||||
|
||||
var move = cc.MoveBy.create(2, cc.p(200, 0));
|
||||
var callback = cc.CallFunc.create(this, this.stopAction);
|
||||
var sequence = cc.Sequence.create(move, callback);
|
||||
sequence.setTag(TAG_SEQUENCE);
|
||||
|
||||
var child = cc.Sprite.create(s_pathGrossini);
|
||||
child.setPosition(cc.p(200, 200));
|
||||
|
||||
this.addChild(child, 1, TAG_GROSSINI);
|
||||
child.runAction(sequence);
|
||||
},
|
||||
stopAction:function () {
|
||||
var sprite = this.getChildByTag(TAG_GROSSINI);
|
||||
sprite.stopActionByTag(TAG_SEQUENCE);
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// ResumeTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var ResumeTest = ActionManagerTest.extend({
|
||||
title:function () {
|
||||
return "Resume Test";
|
||||
},
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
var l = cc.LabelTTF.create("Grossini only rotate/scale in 3 seconds", "Thonburi", 16);
|
||||
this.addChild(l);
|
||||
l.setPosition(cc.p(s.width / 2, 245));
|
||||
|
||||
var grossini = cc.Sprite.create(s_pathGrossini);
|
||||
this.addChild(grossini, 0, TAG_GROSSINI);
|
||||
grossini.setPosition(cc.p(s.width / 2, s.height / 2));
|
||||
|
||||
grossini.runAction(cc.ScaleBy.create(2, 2));
|
||||
|
||||
cc.Director.getInstance().getActionManager().pauseTarget(grossini);
|
||||
grossini.runAction(cc.RotateBy.create(2, 360));
|
||||
|
||||
this.schedule(this.resumeGrossini, 3.0);
|
||||
},
|
||||
resumeGrossini:function (time) {
|
||||
this.unschedule(this.resumeGrossini);
|
||||
|
||||
var grossini = this.getChildByTag(TAG_GROSSINI);
|
||||
cc.Director.getInstance().getActionManager().resumeTarget(grossini);
|
||||
}
|
||||
});
|
||||
|
||||
var ActionManagerTestScene = TestScene.extend({
|
||||
runThisTest:function () {
|
||||
sceneIdx = -1;
|
||||
MAX_LAYER = 5;
|
||||
var layer = nextActionManagerAction();
|
||||
this.addChild(layer);
|
||||
cc.Director.getInstance().replaceScene(this);
|
||||
}
|
||||
});
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,106 @@
|
|||
/****************************************************************************
|
||||
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 Ball = cc.Sprite.extend({
|
||||
_velocity:cc.p(0,0),
|
||||
_radius:0,
|
||||
ctor: function() {
|
||||
cc.associateWithNative( this, cc.Sprite );
|
||||
this.init();
|
||||
},
|
||||
init: function() {
|
||||
this._super();
|
||||
},
|
||||
radius:function () {
|
||||
return this._radius;
|
||||
},
|
||||
setRadius:function (rad) {
|
||||
this._radius = rad;
|
||||
},
|
||||
move:function (delta) {
|
||||
this.setPosition(cc.pAdd(this.getPosition(), cc.pMult(this._velocity, delta)));
|
||||
var winSize = cc.Director.getInstance().getWinSize();
|
||||
if (this.getPosition().x > winSize.width - this.radius()) {
|
||||
this.setPosition(cc.p(winSize.width - this.radius(), this.getPosition().y));
|
||||
this._velocity.x *= -1;
|
||||
} else if (this.getPosition().x < this.radius()) {
|
||||
this.setPosition(cc.p(this.radius(), this.getPosition().y));
|
||||
this._velocity.x *= -1;
|
||||
}
|
||||
},
|
||||
collideWithPaddle:function (paddle) {
|
||||
var paddleRect = paddle.rect();
|
||||
|
||||
paddleRect.origin.x += paddle.getPosition().x;
|
||||
paddleRect.origin.y += paddle.getPosition().y;
|
||||
|
||||
var lowY = cc.Rect.CCRectGetMinY(paddleRect);
|
||||
var midY = cc.Rect.CCRectGetMidY(paddleRect);
|
||||
var highY = cc.Rect.CCRectGetMaxY(paddleRect);
|
||||
|
||||
var leftX = cc.Rect.CCRectGetMinX(paddleRect);
|
||||
var rightX = cc.Rect.CCRectGetMaxX(paddleRect);
|
||||
|
||||
if ((this.getPosition().x > leftX) && (this.getPosition().x < rightX)) {
|
||||
var hit = false;
|
||||
var angleOffset = 0.0;
|
||||
if ((this.getPositionY() > midY) && (this.getPositionY() <= (highY + this.radius()))) {
|
||||
this.setPosition(cc.p(this.getPosition().x, highY + this.radius()));
|
||||
hit = true;
|
||||
angleOffset = Math.PI / 2;
|
||||
} else if (this.getPosition().y < midY && this.getPosition().y >= lowY - this.radius()) {
|
||||
this.setPosition(cc.p(this.getPosition().x, lowY - this.radius()));
|
||||
hit = true;
|
||||
angleOffset = -Math.PI / 2;
|
||||
}
|
||||
|
||||
if (hit) {
|
||||
var hitAngle = cc.pToAngle(cc.pSub(paddle.getPosition(), this.getPosition())) + angleOffset;
|
||||
|
||||
var scalarVelocity = cc.pLength(this._velocity) * 1.00000005;
|
||||
var velocityAngle = -cc.pToAngle(this._velocity) + 0.00000005 * hitAngle;
|
||||
//this._velocity = -this._velocity.y;
|
||||
this._velocity = cc.pMult(cc.pForAngle(velocityAngle), scalarVelocity);
|
||||
}
|
||||
}
|
||||
},
|
||||
setVelocity:function (velocity) {
|
||||
this._velocity = velocity;
|
||||
},
|
||||
getVelocity:function () {
|
||||
return this._velocity;
|
||||
}
|
||||
});
|
||||
|
||||
Ball.ballWithTexture = function (texture) {
|
||||
log(Ball);
|
||||
var ball = new Ball();
|
||||
ball.initWithTexture(texture);
|
||||
if (texture instanceof cc.Texture2D)
|
||||
ball.setRadius(texture.getContentSize().width / 2);
|
||||
else if ((texture instanceof HTMLImageElement) || (texture instanceof HTMLCanvasElement))
|
||||
ball.setRadius(texture.width / 2);
|
||||
return ball;
|
||||
};
|
|
@ -0,0 +1,200 @@
|
|||
/****************************************************************************
|
||||
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_SPRITE_MANAGER = 1;
|
||||
var PTM_RATIO = 32;
|
||||
|
||||
Box2DTestLayer = cc.Layer.extend({
|
||||
|
||||
world:null,
|
||||
//GLESDebugDraw *m_debugDraw;
|
||||
|
||||
|
||||
ctor:function () {
|
||||
this.setTouchEnabled(true);
|
||||
//setAccelerometerEnabled( true );
|
||||
|
||||
var b2Vec2 = Box2D.Common.Math.b2Vec2
|
||||
, b2BodyDef = Box2D.Dynamics.b2BodyDef
|
||||
, b2Body = Box2D.Dynamics.b2Body
|
||||
, b2FixtureDef = Box2D.Dynamics.b2FixtureDef
|
||||
, b2World = Box2D.Dynamics.b2World
|
||||
, b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape;
|
||||
|
||||
var screenSize = cc.Director.getInstance().getWinSize();
|
||||
//UXLog(L"Screen width %0.2f screen height %0.2f",screenSize.width,screenSize.height);
|
||||
|
||||
|
||||
// Construct a world object, which will hold and simulate the rigid bodies.
|
||||
this.world = new b2World(new b2Vec2(0, -10), true);
|
||||
this.world.SetContinuousPhysics(true);
|
||||
|
||||
// Define the ground body.
|
||||
//var groundBodyDef = new b2BodyDef(); // TODO
|
||||
//groundBodyDef.position.Set(screenSize.width / 2 / PTM_RATIO, screenSize.height / 2 / PTM_RATIO); // bottom-left corner
|
||||
|
||||
// Call the body factory which allocates memory for the ground body
|
||||
// from a pool and creates the ground box shape (also from a pool).
|
||||
// The body is also added to the world.
|
||||
//var groundBody = this.world.CreateBody(groundBodyDef);
|
||||
|
||||
var fixDef = new b2FixtureDef;
|
||||
fixDef.density = 1.0;
|
||||
fixDef.friction = 0.5;
|
||||
fixDef.restitution = 0.2;
|
||||
|
||||
var bodyDef = new b2BodyDef;
|
||||
|
||||
//create ground
|
||||
bodyDef.type = b2Body.b2_staticBody;
|
||||
fixDef.shape = new b2PolygonShape;
|
||||
fixDef.shape.SetAsBox(20, 2);
|
||||
// upper
|
||||
bodyDef.position.Set(10, screenSize.height / PTM_RATIO + 1.8);
|
||||
this.world.CreateBody(bodyDef).CreateFixture(fixDef);
|
||||
// bottom
|
||||
bodyDef.position.Set(10, -1.8);
|
||||
this.world.CreateBody(bodyDef).CreateFixture(fixDef);
|
||||
|
||||
fixDef.shape.SetAsBox(2, 14);
|
||||
// left
|
||||
bodyDef.position.Set(-1.8, 13);
|
||||
this.world.CreateBody(bodyDef).CreateFixture(fixDef);
|
||||
// right
|
||||
bodyDef.position.Set(26.8, 13);
|
||||
this.world.CreateBody(bodyDef).CreateFixture(fixDef);
|
||||
|
||||
//Set up sprite
|
||||
|
||||
var mgr = cc.SpriteBatchNode.create(s_pathBlock, 150);
|
||||
this.addChild(mgr, 0, TAG_SPRITE_MANAGER);
|
||||
|
||||
this.addNewSpriteWithCoords(cc.p(screenSize.width / 2, screenSize.height / 2));
|
||||
|
||||
var label = cc.LabelTTF.create("Tap screen", "Marker Felt", 32);
|
||||
this.addChild(label, 0);
|
||||
label.setColor(cc.c3b(0, 0, 255));
|
||||
label.setPosition(cc.p(screenSize.width / 2, screenSize.height - 50));
|
||||
|
||||
this.scheduleUpdate();
|
||||
|
||||
|
||||
},
|
||||
|
||||
|
||||
//draw:function(){
|
||||
|
||||
//},
|
||||
|
||||
addNewSpriteWithCoords:function (p) {
|
||||
//UXLog(L"Add sprite %0.2f x %02.f",p.x,p.y);
|
||||
var batch = this.getChildByTag(TAG_SPRITE_MANAGER);
|
||||
|
||||
//We have a 64x64 sprite sheet with 4 different 32x32 images. The following code is
|
||||
//just randomly picking one of the images
|
||||
var idx = (Math.random() > .5 ? 0 : 1);
|
||||
var idy = (Math.random() > .5 ? 0 : 1);
|
||||
var sprite = cc.Sprite.createWithTexture(batch.getTexture(), cc.rect(32 * idx, 32 * idy, 32, 32));
|
||||
batch.addChild(sprite);
|
||||
|
||||
sprite.setPosition(cc.p(p.x, p.y));
|
||||
|
||||
// Define the dynamic body.
|
||||
//Set up a 1m squared box in the physics world
|
||||
var b2BodyDef = Box2D.Dynamics.b2BodyDef
|
||||
, b2Body = Box2D.Dynamics.b2Body
|
||||
, b2FixtureDef = Box2D.Dynamics.b2FixtureDef
|
||||
, b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape;
|
||||
|
||||
var bodyDef = new b2BodyDef();
|
||||
bodyDef.type = b2Body.b2_dynamicBody;
|
||||
bodyDef.position.Set(p.x / PTM_RATIO, p.y / PTM_RATIO);
|
||||
bodyDef.userData = sprite;
|
||||
var body = this.world.CreateBody(bodyDef);
|
||||
|
||||
// Define another box shape for our dynamic body.
|
||||
var dynamicBox = new b2PolygonShape();
|
||||
dynamicBox.SetAsBox(0.5, 0.5);//These are mid points for our 1m box
|
||||
|
||||
// Define the dynamic body fixture.
|
||||
var fixtureDef = new b2FixtureDef();
|
||||
fixtureDef.shape = dynamicBox;
|
||||
fixtureDef.density = 1.0;
|
||||
fixtureDef.friction = 0.3;
|
||||
body.CreateFixture(fixtureDef);
|
||||
|
||||
},
|
||||
update:function (dt) {
|
||||
//It is recommended that a fixed time step is used with Box2D for stability
|
||||
//of the simulation, however, we are using a variable time step here.
|
||||
//You need to make an informed choice, the following URL is useful
|
||||
//http://gafferongames.com/game-physics/fix-your-timestep/
|
||||
|
||||
var velocityIterations = 8;
|
||||
var positionIterations = 1;
|
||||
|
||||
// Instruct the world to perform a single step of simulation. It is
|
||||
// generally best to keep the time step and iterations fixed.
|
||||
this.world.Step(dt, velocityIterations, positionIterations);
|
||||
|
||||
//Iterate over the bodies in the physics world
|
||||
for (var b = this.world.GetBodyList(); b; b = b.GetNext()) {
|
||||
if (b.GetUserData() != null) {
|
||||
//Synchronize the AtlasSprites position and rotation with the corresponding body
|
||||
var myActor = b.GetUserData();
|
||||
myActor.setPosition(cc.p(b.GetPosition().x * PTM_RATIO, b.GetPosition().y * PTM_RATIO));
|
||||
myActor.setRotation(-1 * cc.RADIANS_TO_DEGREES(b.GetAngle()));
|
||||
//console.log(b.GetAngle());
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
onTouchesEnded:function (touches, event) {
|
||||
//Add a new body/atlas sprite at the touched location
|
||||
for (var it = 0; it < touches.length; it++) {
|
||||
var touch = touches[it];
|
||||
|
||||
if (!touch)
|
||||
break;
|
||||
|
||||
var location = touch.getLocation();
|
||||
//location = cc.Director.getInstance().convertToGL(location);
|
||||
this.addNewSpriteWithCoords(location);
|
||||
}
|
||||
}
|
||||
|
||||
//CREATE_NODE(Box2DTestLayer);
|
||||
});
|
||||
|
||||
Box2DTestScene = TestScene.extend({
|
||||
|
||||
|
||||
runThisTest:function () {
|
||||
var layer = new Box2DTestLayer();
|
||||
this.addChild(layer);
|
||||
|
||||
cc.Director.getInstance().replaceScene(this);
|
||||
}
|
||||
});
|
|
@ -0,0 +1,250 @@
|
|||
/****************************************************************************
|
||||
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 ControlButtonTest_HelloVariableSize = ControlScene.extend({
|
||||
init:function(){
|
||||
if (this._super()) {
|
||||
var screenSize = cc.Director.getInstance().getWinSize();
|
||||
|
||||
// Defines an array of title to create buttons dynamically
|
||||
var stringArray = ["Hello", "Variable", "Size","!"];
|
||||
|
||||
var layer = cc.Node.create();
|
||||
this.addChild(layer, 1);
|
||||
|
||||
var total_width = 0, height = 0;
|
||||
|
||||
// For each title in the array
|
||||
for(var i = 0; i< stringArray.length; i++){
|
||||
var button = this.standardButtonWithTitle(stringArray[i]);
|
||||
button.setPosition(cc.p(total_width + button.getContentSize().width / 2, button.getContentSize().height / 2));
|
||||
layer.addChild(button);
|
||||
|
||||
// Compute the size of the layer
|
||||
height = button.getContentSize().height;
|
||||
total_width += button.getContentSize().width;
|
||||
}
|
||||
|
||||
layer.setAnchorPoint(cc.p(0.5, 0.5));
|
||||
layer.setContentSize(cc.SizeMake(total_width, height));
|
||||
layer.setPosition(cc.p(screenSize.width / 2.0, screenSize.height / 2.0));
|
||||
|
||||
// Add the black background
|
||||
var background = cc.Scale9Sprite.create(s_extensions_buttonBackground);
|
||||
background.setContentSize(cc.SizeMake(total_width + 14, height + 14));
|
||||
background.setPosition(cc.p(screenSize.width / 2.0, screenSize.height / 2.0));
|
||||
this.addChild(background);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
/** Creates and return a button with a default background and title color. */
|
||||
standardButtonWithTitle:function(title){
|
||||
/** Creates and return a button with a default background and title color. */
|
||||
var backgroundButton = cc.Scale9Sprite.create(s_extensions_button);
|
||||
var backgroundHighlightedButton = cc.Scale9Sprite.create(s_extensions_buttonHighlighted);
|
||||
|
||||
var titleButton = cc.LabelTTF.create(title, "Marker Felt", 30);
|
||||
|
||||
titleButton.setColor(cc.c3(159, 168, 176));
|
||||
|
||||
var button = cc.ControlButton.create(titleButton, backgroundButton);
|
||||
button.setBackgroundSpriteForState(backgroundHighlightedButton, cc.CONTROL_STATE_HIGHLIGHTED);
|
||||
button.setTitleColorForState(cc.white(), cc.CONTROL_STATE_HIGHLIGHTED);
|
||||
|
||||
return button;
|
||||
}
|
||||
});
|
||||
|
||||
ControlButtonTest_HelloVariableSize.create = function(sceneTitle){
|
||||
var scene = cc.Scene.create();
|
||||
var controlLayer = new ControlButtonTest_HelloVariableSize();
|
||||
if(controlLayer && controlLayer.init()){
|
||||
controlLayer.getSceneTitleLabel().setString(sceneTitle);
|
||||
scene.addChild(controlLayer);
|
||||
}
|
||||
return scene;
|
||||
};
|
||||
|
||||
var ControlButtonTest_Event = ControlScene.extend({
|
||||
_displayValueLabel:null,
|
||||
|
||||
ctor:function(){},
|
||||
init:function(){
|
||||
if (this._super()) {
|
||||
var screenSize = cc.Director.getInstance().getWinSize();
|
||||
|
||||
// Add a label in which the button events will be displayed
|
||||
this.setDisplayValueLabel(cc.LabelTTF.create("No Event", "Marker Felt", 32));
|
||||
this._displayValueLabel.setAnchorPoint(cc.p(0.5, -1));
|
||||
this._displayValueLabel.setPosition(cc.p(screenSize.width / 2.0, screenSize.height / 2.0));
|
||||
this.addChild(this._displayValueLabel, 1);
|
||||
|
||||
// Add the button
|
||||
var backgroundButton = cc.Scale9Sprite.create(s_extensions_button);
|
||||
var backgroundHighlightedButton = cc.Scale9Sprite.create(s_extensions_buttonHighlighted);
|
||||
|
||||
var titleButton = cc.LabelTTF.create("Touch Me!", "Marker Felt", 30);
|
||||
|
||||
titleButton.setColor(cc.c3(159, 168, 176));
|
||||
|
||||
var controlButton = cc.ControlButton.create(titleButton, backgroundButton);
|
||||
controlButton.setBackgroundSpriteForState(backgroundHighlightedButton, cc.CONTROL_STATE_HIGHLIGHTED);
|
||||
controlButton.setTitleColorForState(cc.white(), cc.CONTROL_STATE_HIGHLIGHTED);
|
||||
|
||||
controlButton.setAnchorPoint(cc.p(0.5, 1));
|
||||
controlButton.setPosition(cc.p(screenSize.width / 2.0, screenSize.height / 2.0));
|
||||
this.addChild(controlButton, 1);
|
||||
|
||||
// Add the black background
|
||||
var background = cc.Scale9Sprite.create(s_extensions_buttonBackground);
|
||||
background.setContentSize(cc.SizeMake(300, 170));
|
||||
background.setPosition(cc.p(screenSize.width / 2.0, screenSize.height / 2.0));
|
||||
this.addChild(background);
|
||||
|
||||
// Sets up event handlers
|
||||
controlButton.addTargetWithActionForControlEvent(this, this.touchDownAction, cc.CONTROL_EVENT_TOUCH_DOWN);
|
||||
controlButton.addTargetWithActionForControlEvent(this, this.touchDragInsideAction, cc.CONTROL_EVENT_TOUCH_DRAGINSIDE);
|
||||
controlButton.addTargetWithActionForControlEvent(this, this.touchDragOutsideAction, cc.CONTROL_EVENT_TOUCH_DRAGOUTSIDE);
|
||||
controlButton.addTargetWithActionForControlEvent(this, this.touchDragEnterAction, cc.CONTROL_EVENT_TOUCH_DRAGENTER);
|
||||
controlButton.addTargetWithActionForControlEvent(this, this.touchDragExitAction, cc.CONTROL_EVENT_TOUCH_DRAGEXIT);
|
||||
controlButton.addTargetWithActionForControlEvent(this, this.touchUpInsideAction, cc.CONTROL_EVENT_TOUCH_UPINSIDE);
|
||||
controlButton.addTargetWithActionForControlEvent(this, this.touchUpOutsideAction, cc.CONTROL_EVENT_TOUCH_UPOUTSIDE);
|
||||
controlButton.addTargetWithActionForControlEvent(this, this.touchCancelAction, cc.CONTROL_EVENT_TOUCH_CANCEL);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
getDisplayValueLabel:function(){return this._displayValueLabel;},
|
||||
setDisplayValueLabel:function(displayValueLabel) {this._displayValueLabel = displayValueLabel;},
|
||||
|
||||
touchDownAction:function(sender, controlEvent){
|
||||
this._displayValueLabel.setString("Touch Down");
|
||||
},
|
||||
touchDragInsideAction:function(sender,controlEvent){
|
||||
this._displayValueLabel.setString("Drag Inside");
|
||||
},
|
||||
touchDragOutsideAction:function(sender, controlEvent){
|
||||
this._displayValueLabel.setString("Drag Outside");
|
||||
},
|
||||
touchDragEnterAction:function(sender,controlEvent){
|
||||
this._displayValueLabel.setString("Drag Enter");
|
||||
},
|
||||
touchDragExitAction:function(sender, controlEvent){
|
||||
this._displayValueLabel.setString("Drag Exit");
|
||||
},
|
||||
touchUpInsideAction:function(sender,controlEvent){
|
||||
this._displayValueLabel.setString("Touch Up Inside.");
|
||||
},
|
||||
touchUpOutsideAction:function(sender, controlEvent){
|
||||
this._displayValueLabel.setString("Touch Up Outside.");
|
||||
},
|
||||
touchCancelAction:function(sender,controlEvent){
|
||||
this._displayValueLabel.setString("Touch Cancel");
|
||||
}
|
||||
});
|
||||
|
||||
ControlButtonTest_Event.create = function(sceneTitle){
|
||||
var scene = cc.Scene.create();
|
||||
var controlLayer = new ControlButtonTest_Event();
|
||||
if(controlLayer && controlLayer.init()){
|
||||
controlLayer.getSceneTitleLabel().setString(sceneTitle);
|
||||
scene.addChild(controlLayer);
|
||||
}
|
||||
return scene;
|
||||
};
|
||||
|
||||
var ControlButtonTest_Styling = ControlScene.extend({
|
||||
init:function(){
|
||||
if (this._super()) {
|
||||
var screenSize = cc.Director.getInstance().getWinSize();
|
||||
|
||||
var layer = cc.Node.create();
|
||||
this.addChild(layer, 1);
|
||||
|
||||
var space = 10; // px
|
||||
|
||||
var max_w = 0, max_h = 0;
|
||||
for (var i = 0; i < 3; i++)
|
||||
{
|
||||
for (var j = 0; j < 3; j++)
|
||||
{
|
||||
// Add the buttons
|
||||
var button = this.standardButtonWithTitle((0|(Math.random() * 30)) + "");
|
||||
button.setAdjustBackgroundImage(false); // Tells the button that the background image must not be adjust
|
||||
// It'll use the prefered size of the background image
|
||||
button.setPosition(cc.p (button.getContentSize().width / 2 + (button.getContentSize().width + space) * i,
|
||||
button.getContentSize().height / 2 + (button.getContentSize().height + space) * j));
|
||||
layer.addChild(button);
|
||||
|
||||
max_w = Math.max(button.getContentSize().width * (i + 1) + space * i, max_w);
|
||||
max_h = Math.max(button.getContentSize().height * (j + 1) + space * j, max_h);
|
||||
}
|
||||
}
|
||||
|
||||
layer.setAnchorPoint(cc.p(0.5, 0.5));
|
||||
layer.setContentSize(cc.SizeMake(max_w, max_h));
|
||||
layer.setPosition(cc.p(screenSize.width / 2.0, screenSize.height / 2.0));
|
||||
|
||||
// Add the black background
|
||||
var backgroundButton = cc.Scale9Sprite.create(s_extensions_buttonBackground);
|
||||
backgroundButton.setContentSize(cc.SizeMake(max_w + 14, max_h + 14));
|
||||
backgroundButton.setPosition(cc.p(screenSize.width / 2.0, screenSize.height / 2.0));
|
||||
this.addChild(backgroundButton);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
standardButtonWithTitle:function(title){
|
||||
/** Creates and return a button with a default background and title color. */
|
||||
var backgroundButton = cc.Scale9Sprite.create(s_extensions_button);
|
||||
backgroundButton.setPreferredSize(cc.SizeMake(45, 45)); // Set the prefered size
|
||||
var backgroundHighlightedButton = cc.Scale9Sprite.create(s_extensions_buttonHighlighted);
|
||||
backgroundHighlightedButton.setPreferredSize(cc.SizeMake(45, 45)); // Set the prefered size
|
||||
|
||||
var titleButton = cc.LabelTTF.create(title, "Marker Felt", 30);
|
||||
|
||||
titleButton.setColor(cc.c3(159, 168, 176));
|
||||
|
||||
var button = cc.ControlButton.create(titleButton, backgroundButton);
|
||||
button.setBackgroundSpriteForState(backgroundHighlightedButton, cc.CONTROL_STATE_HIGHLIGHTED);
|
||||
button.setTitleColorForState(cc.white(), cc.CONTROL_STATE_HIGHLIGHTED);
|
||||
|
||||
return button;
|
||||
}
|
||||
});
|
||||
|
||||
ControlButtonTest_Styling.create = function(sceneTitle){
|
||||
var scene = cc.Scene.create();
|
||||
var controlLayer = new ControlButtonTest_Styling();
|
||||
if(controlLayer && controlLayer.init()){
|
||||
controlLayer.getSceneTitleLabel().setString(sceneTitle);
|
||||
scene.addChild(controlLayer);
|
||||
}
|
||||
return scene;
|
||||
};
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
/****************************************************************************
|
||||
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 ControlScene = cc.Layer.extend({
|
||||
_sceneTitleLabel:null,
|
||||
|
||||
ctor:function(){},
|
||||
|
||||
getSceneTitleLabel:function(){return this._sceneTitleLabel;},
|
||||
setSceneTitleLabel:function(sceneTitleLabel){this._sceneTitleLabel = sceneTitleLabel;},
|
||||
|
||||
init:function(){
|
||||
if (this._super()) {
|
||||
// Get the sceensize
|
||||
var screensize = cc.Director.getInstance().getWinSize();
|
||||
|
||||
var pBackItem = cc.MenuItemFont.create("Back", this,this.toExtensionsMainLayer);
|
||||
pBackItem.setPosition(cc.p(screensize.width - 50, 25));
|
||||
var pBackMenu = cc.Menu.create(pBackItem);
|
||||
pBackMenu.setPosition( cc.p(0,0));
|
||||
this.addChild(pBackMenu, 10);
|
||||
|
||||
// Add the generated background
|
||||
var background = cc.Sprite.create(s_extensions_background);
|
||||
background.setPosition(cc.p(screensize.width / 2, screensize.height / 2));
|
||||
var bgRect = background.getTextureRect();
|
||||
background.setScaleX(screensize.width/bgRect.size.width);
|
||||
background.setScaleY(screensize.height/bgRect.size.height);
|
||||
this.addChild(background);
|
||||
|
||||
// Add the ribbon
|
||||
var ribbon = cc.Scale9Sprite.create(s_extensions_ribbon, cc.RectMake(1, 1, 48, 55));
|
||||
ribbon.setContentSize(cc.SizeMake(screensize.width, 57));
|
||||
ribbon.setPosition(cc.p(screensize.width / 2.0, screensize.height - ribbon.getContentSize().height / 2.0));
|
||||
this.addChild(ribbon);
|
||||
|
||||
// Add the title
|
||||
this.setSceneTitleLabel(cc.LabelTTF.create("Title", "Arial", 12));
|
||||
this._sceneTitleLabel.setPosition(cc.p (screensize.width / 2, screensize.height - this._sceneTitleLabel.getContentSize().height / 2 - 5));
|
||||
this.addChild(this._sceneTitleLabel, 1);
|
||||
|
||||
// Add the menu
|
||||
var item1 = cc.MenuItemImage.create(s_pathB1, s_pathB2, this, this.previousCallback);
|
||||
var item2 = cc.MenuItemImage.create(s_pathR1, s_pathR2, this, this.restartCallback);
|
||||
var item3 = cc.MenuItemImage.create(s_pathF1, s_pathF2, this, this.nextCallback);
|
||||
|
||||
var menu = cc.Menu.create(item1, item3, item2);
|
||||
menu.setPosition(cc.p(0,0));
|
||||
item1.setPosition(cc.p(screensize.width / 2 - 100, 37));
|
||||
item2.setPosition(cc.p(screensize.width / 2, 35));
|
||||
item3.setPosition(cc.p(screensize.width / 2 + 100, 37));
|
||||
|
||||
this.addChild(menu ,1);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
toExtensionsMainLayer:function(sender){
|
||||
var pScene = new ExtensionsTestScene();
|
||||
pScene.runThisTest();
|
||||
},
|
||||
|
||||
previousCallback:function(sender){
|
||||
cc.Director.getInstance().replaceScene(ControlSceneManager.getInstance().previousControlScene());
|
||||
},
|
||||
restartCallback:function(sender){
|
||||
cc.Director.getInstance().replaceScene(ControlSceneManager.getInstance().currentControlScene());
|
||||
},
|
||||
nextCallback:function(sender){
|
||||
cc.Director.getInstance().replaceScene(ControlSceneManager.getInstance().nextControlScene());
|
||||
}
|
||||
});
|
||||
|
||||
ControlScene.create = function(title){
|
||||
var scene = cc.Scene.create();
|
||||
var controlLayer = new ControlScene();
|
||||
if(controlLayer && controlLayer.init()){
|
||||
controlLayer.getSceneTitleLabel().setString(title);
|
||||
scene.addChild(controlLayer);
|
||||
}
|
||||
return scene;
|
||||
};
|
|
@ -0,0 +1,108 @@
|
|||
/****************************************************************************
|
||||
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 controTestItemNames = [
|
||||
/* {
|
||||
itemTitle:"CCControlSliderTest",
|
||||
testScene:function () {
|
||||
//
|
||||
}
|
||||
},
|
||||
{
|
||||
itemTitle:"ControlColourPickerTest",
|
||||
testScene:function () {
|
||||
//
|
||||
}
|
||||
},
|
||||
{
|
||||
itemTitle:"ControlSwitchTest",
|
||||
testScene:function () {
|
||||
//
|
||||
}
|
||||
},*/
|
||||
{
|
||||
itemTitle:"ControlButtonTest_HelloVariableSize",
|
||||
testScene:function () {
|
||||
return ControlButtonTest_HelloVariableSize.create(this.itemTitle);
|
||||
}
|
||||
},
|
||||
{
|
||||
itemTitle:"ControlButtonTest_Event",
|
||||
testScene:function () {
|
||||
return ControlButtonTest_Event.create(this.itemTitle);
|
||||
}
|
||||
},
|
||||
{
|
||||
itemTitle:"ControlButtonTest_Styling",
|
||||
testScene:function () {
|
||||
return ControlButtonTest_Styling.create(this.itemTitle);
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
var ControlSceneManager = cc.Class.extend({
|
||||
_currentControlSceneId:0,
|
||||
|
||||
ctor:function () {
|
||||
this._currentControlSceneId = 0;
|
||||
},
|
||||
|
||||
getCurrentControlSceneId:function () {
|
||||
return this._currentControlSceneId;
|
||||
},
|
||||
setCurrentControlSceneId:function (currentControlSceneId) {
|
||||
this._currentControlSceneId = currentControlSceneId
|
||||
},
|
||||
|
||||
nextControlScene:function () {
|
||||
this._currentControlSceneId = (this._currentControlSceneId + 1) % controTestItemNames.length;
|
||||
return this.currentControlScene();
|
||||
},
|
||||
|
||||
previousControlScene:function () {
|
||||
this._currentControlSceneId = this._currentControlSceneId - 1;
|
||||
if (this._currentControlSceneId < 0) {
|
||||
this._currentControlSceneId = controTestItemNames.length - 1;
|
||||
}
|
||||
|
||||
return this.currentControlScene();
|
||||
},
|
||||
|
||||
currentControlScene:function () {
|
||||
return controTestItemNames[this._currentControlSceneId].testScene();
|
||||
}
|
||||
});
|
||||
|
||||
ControlSceneManager.sharedInstance = null;
|
||||
/**
|
||||
* Returns the singleton of the control scene manager.
|
||||
*/
|
||||
ControlSceneManager.getInstance = function () {
|
||||
if (ControlSceneManager.sharedInstance == null) {
|
||||
ControlSceneManager.sharedInstance = new ControlSceneManager();
|
||||
}
|
||||
return ControlSceneManager.sharedInstance;
|
||||
};
|
|
@ -0,0 +1,82 @@
|
|||
/****************************************************************************
|
||||
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_SPRITE = 1;
|
||||
|
||||
var ClickAndMoveTestScene = TestScene.extend({
|
||||
runThisTest:function () {
|
||||
var layer = new MainLayer();
|
||||
|
||||
this.addChild(layer);
|
||||
cc.Director.getInstance().replaceScene(this);
|
||||
}
|
||||
});
|
||||
|
||||
var MainLayer = cc.Layer.extend({
|
||||
ctor:function () {
|
||||
this.setTouchEnabled(true);
|
||||
var sprite = cc.Sprite.create(s_pathGrossini);
|
||||
|
||||
var layer = cc.LayerColor.create(cc.c4b(255, 255, 0, 100));
|
||||
this.addChild(layer, -1);
|
||||
|
||||
this.addChild(sprite, 0, TAG_SPRITE);
|
||||
sprite.setPosition(cc.p(20, 150));
|
||||
|
||||
sprite.runAction(cc.JumpTo.create(4, cc.p(300, 48), 100, 4));
|
||||
|
||||
var fadeIn = cc.FadeIn.create(1);
|
||||
var fadeOut = cc.FadeOut.create(1);
|
||||
var forever = cc.RepeatForever.create(cc.Sequence.create(fadeIn, fadeOut));
|
||||
layer.runAction(forever);
|
||||
},
|
||||
|
||||
onTouchesEnded:function (touches, event) {
|
||||
if (touches.length <= 0)
|
||||
return;
|
||||
|
||||
var touch = touches[0];
|
||||
|
||||
var location = touch.getLocation();
|
||||
//var convertedLocation = cc.Director.getInstance().convertToGL(location);
|
||||
|
||||
var sprite = this.getChildByTag(TAG_SPRITE);
|
||||
sprite.stopAllActions();
|
||||
sprite.runAction(cc.MoveTo.create(1, cc.p(location.x, location.y)));
|
||||
var o = location.x - sprite.getPositionX();
|
||||
var a = location.y - sprite.getPositionY();
|
||||
var at = cc.RADIANS_TO_DEGREES(Math.atan(o / a));
|
||||
|
||||
if (a < 0) {
|
||||
if (o < 0)
|
||||
at = 180 + Math.abs(at);
|
||||
else
|
||||
at = 180 - Math.abs(at);
|
||||
}
|
||||
at = at % 360;
|
||||
|
||||
sprite.runAction(cc.RotateTo.create(1, at));
|
||||
}
|
||||
});
|
|
@ -0,0 +1,46 @@
|
|||
/****************************************************************************
|
||||
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 CocosBuilderTestScene = TestScene.extend({
|
||||
runThisTest:function(){
|
||||
/* Create an autorelease CCNodeLoaderLibrary. */
|
||||
var ccNodeLoaderLibrary = cc.NodeLoaderLibrary.newDefaultCCNodeLoaderLibrary();
|
||||
|
||||
ccNodeLoaderLibrary.registerCCNodeLoader("HelloCocosBuilderLayer", new HelloCocosBuilderLayerLoader());
|
||||
|
||||
/* Create an autorelease CCBReader. */
|
||||
var ccbReader = new cc.CCBReader(ccNodeLoaderLibrary);
|
||||
|
||||
/* Read a ccbi file. */
|
||||
var node = ccbReader.readNodeGraphFromFile("res/ccb/official/pub/", "ccb/HelloCocosBuilder.ccbi", this);
|
||||
|
||||
if(node != null) {
|
||||
this.addChild(node);
|
||||
}
|
||||
|
||||
cc.Director.getInstance().replaceScene(this);
|
||||
}
|
||||
});
|
|
@ -0,0 +1,330 @@
|
|||
/****************************************************************************
|
||||
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 MUSIC_FILE = "res/background";
|
||||
var EFFECT_FILE = "res/effect2";
|
||||
|
||||
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.Layer.extend({
|
||||
_itmeMenu:null,
|
||||
_beginPos:cc.p(0,0),
|
||||
isMouseDown:false,
|
||||
_testCount:0,
|
||||
ctor:function () {
|
||||
// add menu items for tests
|
||||
this._itmeMenu = cc.Menu.create(null);
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
for (var i = 0; i < DenshionTests.length; i++) {
|
||||
var label = cc.LabelTTF.create(DenshionTests[i].title, "Arial", 24);
|
||||
var menuItem = cc.MenuItemLabel.create(label, this, this.menuCallback);
|
||||
this._itmeMenu.addChild(menuItem, i + 10000);
|
||||
menuItem.setPosition(cc.p(s.width / 2, (s.height - (i + 1) * LINE_SPACE)));
|
||||
}
|
||||
this._testCount = i;
|
||||
this._itmeMenu.setContentSize(cc.size(s.width, (this._testCount + 1) * LINE_SPACE));
|
||||
this._itmeMenu.setPosition(cc.p(0,0));
|
||||
this.addChild(this._itmeMenu);
|
||||
|
||||
this.setTouchEnabled(true);
|
||||
|
||||
// set default volume
|
||||
cc.AudioEngine.getInstance().setEffectsVolume(0.5);
|
||||
cc.AudioEngine.getInstance().setBackgroundMusicVolume(0.5);
|
||||
},
|
||||
menuCallback:function (sender) {
|
||||
var idx = sender.getZOrder() - 10000;
|
||||
// create the test scene and run it
|
||||
var scene = DenshionTests[idx].playFunc();
|
||||
},
|
||||
onTouchesMoved:function (touches, event) {
|
||||
if (this.isMouseDown) {
|
||||
var touchLocation = touches[0].getLocation();
|
||||
var nMoveY = touchLocation.y - this._beginPos.y;
|
||||
var curPos = this._itmeMenu.getPosition();
|
||||
|
||||
var nextPos = cc.p(curPos.x, curPos.y + nMoveY);
|
||||
var winSize = cc.Director.getInstance().getWinSize();
|
||||
if (nextPos.y < 0.0) {
|
||||
this._itmeMenu.setPosition(cc.p(0,0));
|
||||
return;
|
||||
}
|
||||
|
||||
if (nextPos.y > ((this._testCount + 1) * LINE_SPACE - winSize.height)) {
|
||||
this._itmeMenu.setPosition(cc.p(0, ((this._testCount + 1) * LINE_SPACE - winSize.height)));
|
||||
return;
|
||||
}
|
||||
|
||||
this._itmeMenu.setPosition(nextPos);
|
||||
|
||||
this._beginPos = cc.p(0, touchLocation.y);
|
||||
}
|
||||
},
|
||||
onTouchesBegan:function (touches, event) {
|
||||
if (!this.isMouseDown) {
|
||||
this._beginPos = touches[0].getLocation();
|
||||
}
|
||||
this.isMouseDown = true;
|
||||
},
|
||||
onTouchesEnded:function () {
|
||||
this.isMouseDown = false;
|
||||
},
|
||||
onExit:function () {
|
||||
this._super();
|
||||
cc.AudioEngine.getInstance().end();
|
||||
}
|
||||
});
|
||||
|
||||
CocosDenshionTestScene = TestScene.extend({
|
||||
runThisTest:function () {
|
||||
var layer = new CocosDenshionTest();
|
||||
this.addChild(layer);
|
||||
cc.Director.getInstance().replaceScene(this);
|
||||
}
|
||||
});
|
||||
|
||||
var soundId = null;
|
||||
|
||||
var playBackgroundMusic = function () {
|
||||
cc.log("play background music");
|
||||
cc.AudioEngine.getInstance().playBackgroundMusic(MUSIC_FILE, false);
|
||||
};
|
||||
|
||||
var stopBackgroundMusic = function () {
|
||||
cc.log("stop background music");
|
||||
cc.AudioEngine.getInstance().stopBackgroundMusic();
|
||||
};
|
||||
|
||||
var pauseBackgroundMusic = function () {
|
||||
cc.log("pause background music");
|
||||
cc.AudioEngine.getInstance().pauseBackgroundMusic();
|
||||
};
|
||||
|
||||
var resumeBackgroundMusic = function () {
|
||||
cc.log("resume background music");
|
||||
cc.AudioEngine.getInstance().resumeBackgroundMusic();
|
||||
};
|
||||
|
||||
var rewindBackgroundMusic = function () {
|
||||
cc.log("rewind background music");
|
||||
cc.AudioEngine.getInstance().rewindBackgroundMusic();
|
||||
};
|
||||
|
||||
// is background music playing
|
||||
var isBackgroundMusicPlaying = function () {
|
||||
if (cc.AudioEngine.getInstance().isBackgroundMusicPlaying()) {
|
||||
cc.log("background music is playing");
|
||||
}
|
||||
else {
|
||||
cc.log("background music is not playing");
|
||||
}
|
||||
};
|
||||
|
||||
var playEffect = function () {
|
||||
cc.log("play effect");
|
||||
soundId = cc.AudioEngine.getInstance().playEffect(EFFECT_FILE);
|
||||
};
|
||||
|
||||
var playEffectRepeatly = function () {
|
||||
cc.log("play effect repeatly");
|
||||
soundId = cc.AudioEngine.getInstance().playEffect(EFFECT_FILE, true);
|
||||
};
|
||||
|
||||
var stopEffect = function () {
|
||||
cc.log("stop effect");
|
||||
cc.AudioEngine.getInstance().stopEffect(soundId);
|
||||
};
|
||||
|
||||
var unloadEffect = function () {
|
||||
cc.log("unload effect");
|
||||
cc.AudioEngine.getInstance().unloadEffect(EFFECT_FILE);
|
||||
};
|
||||
|
||||
var addBackgroundMusicVolume = function () {
|
||||
cc.log("add bakcground music volume");
|
||||
cc.AudioEngine.getInstance().setBackgroundMusicVolume(cc.AudioEngine.getInstance().getBackgroundMusicVolume() + 0.1);
|
||||
};
|
||||
|
||||
var subBackgroundMusicVolume = function () {
|
||||
cc.log("sub backgroud music volume");
|
||||
cc.AudioEngine.getInstance().setBackgroundMusicVolume(cc.AudioEngine.getInstance().getBackgroundMusicVolume() - 0.1);
|
||||
};
|
||||
|
||||
var addEffectsVolume = function () {
|
||||
cc.log("add effects volume");
|
||||
cc.AudioEngine.getInstance().setEffectsVolume(cc.AudioEngine.getInstance().getEffectsVolume() + 0.1);
|
||||
};
|
||||
|
||||
var subEffectsVolume = function () {
|
||||
cc.log("sub effects volume");
|
||||
cc.AudioEngine.getInstance().setEffectsVolume(cc.AudioEngine.getInstance().getEffectsVolume() - 0.1);
|
||||
};
|
||||
|
||||
var pauseEffect = function () {
|
||||
cc.log("pause effect");
|
||||
cc.AudioEngine.getInstance().pauseEffect(soundId);
|
||||
};
|
||||
|
||||
var resumeEffect = function () {
|
||||
cc.log("resume effect");
|
||||
cc.AudioEngine.getInstance().resumeEffect(soundId);
|
||||
};
|
||||
|
||||
var pauseAllEffects = function () {
|
||||
cc.log("pause all effects");
|
||||
cc.AudioEngine.getInstance().pauseAllEffects();
|
||||
};
|
||||
var resumeAllEffects = function () {
|
||||
cc.log("resume all effects");
|
||||
cc.AudioEngine.getInstance().resumeAllEffects();
|
||||
};
|
||||
var stopAllEffects = function () {
|
||||
cc.log("stop all effects");
|
||||
cc.AudioEngine.getInstance().stopAllEffects();
|
||||
};
|
|
@ -0,0 +1,658 @@
|
|||
/****************************************************************************
|
||||
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_SPRITE1 = 1;
|
||||
var TAG_SPRITE2 = 2;
|
||||
var TAG_SPRITE3 = 3;
|
||||
var TAG_SLIDER = 4;
|
||||
|
||||
var sceneIdx = -1;
|
||||
var MAX_LAYER = 9;
|
||||
|
||||
var nextCocosNodeAction = function () {
|
||||
sceneIdx++;
|
||||
sceneIdx = sceneIdx % MAX_LAYER;
|
||||
return createCocosNodeLayer(sceneIdx);
|
||||
};
|
||||
|
||||
var backCocosNodeAction = function () {
|
||||
sceneIdx--;
|
||||
if (sceneIdx < 0)
|
||||
sceneIdx += MAX_LAYER;
|
||||
return createCocosNodeLayer(sceneIdx);
|
||||
};
|
||||
|
||||
var restartCocosNodeAction = function () {
|
||||
return createCocosNodeLayer(sceneIdx);
|
||||
};
|
||||
|
||||
var createCocosNodeLayer = function (index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return new CCNodeTest2();
|
||||
case 1:
|
||||
return new CCNodeTest4();
|
||||
case 2:
|
||||
return new CCNodeTest5();
|
||||
case 3:
|
||||
return new CCNodeTest6();
|
||||
case 4:
|
||||
return new StressTest1();
|
||||
case 5:
|
||||
return new StressTest2();
|
||||
case 6:
|
||||
return new NodeToWorld();
|
||||
case 7:
|
||||
return new SchedulerTest1();
|
||||
case 8:
|
||||
return new ConvertToNode();
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
var TestCocosNodeDemo = cc.Layer.extend({
|
||||
ctor:function () {
|
||||
},
|
||||
title:function () {
|
||||
return "No title";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "";
|
||||
},
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 32);
|
||||
this.addChild(label, 1);
|
||||
label.setPosition(cc.p(s.width / 2, s.height - 50));
|
||||
|
||||
var strSubtitle = this.subtitle();
|
||||
if (!strSubtitle == "") {
|
||||
var l = cc.LabelTTF.create(strSubtitle, "Thonburi", 16);
|
||||
this.addChild(l, 1);
|
||||
l.setPosition(cc.p(s.width / 2, s.height - 80));
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3);
|
||||
|
||||
menu.setPosition(cc.p(0,0));
|
||||
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));
|
||||
|
||||
this.addChild(menu, 1);
|
||||
},
|
||||
|
||||
restartCallback:function (sender) {
|
||||
var s = new CocosNodeTestScene();
|
||||
s.addChild(restartCocosNodeAction());
|
||||
cc.Director.getInstance().replaceScene(s);
|
||||
},
|
||||
nextCallback:function (sender) {
|
||||
var s = new CocosNodeTestScene();
|
||||
s.addChild(nextCocosNodeAction());
|
||||
cc.Director.getInstance().replaceScene(s);
|
||||
},
|
||||
backCallback:function (sender) {
|
||||
var s = new CocosNodeTestScene();
|
||||
s.addChild(backCocosNodeAction());
|
||||
cc.Director.getInstance().replaceScene(s);
|
||||
}
|
||||
});
|
||||
|
||||
var CCNodeTest2 = TestCocosNodeDemo.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
var sp1 = cc.Sprite.create(s_pathSister1);
|
||||
var sp2 = cc.Sprite.create(s_pathSister2);
|
||||
var sp3 = cc.Sprite.create(s_pathSister1);
|
||||
var sp4 = cc.Sprite.create(s_pathSister2);
|
||||
|
||||
sp1.setPosition(cc.p(150, s.height / 2));
|
||||
sp2.setPosition(cc.p(s.width - 150, s.height / 2));
|
||||
this.addChild(sp1);
|
||||
this.addChild(sp2);
|
||||
|
||||
sp3.setScale(0.25);
|
||||
sp4.setScale(0.25);
|
||||
|
||||
sp1.addChild(sp3);
|
||||
sp2.addChild(sp4);
|
||||
|
||||
var a1 = cc.RotateBy.create(2, 360);
|
||||
var a2 = cc.ScaleBy.create(2, 2);
|
||||
|
||||
var action1 = cc.RepeatForever.create(cc.Sequence.create(a1, a2, a2.reverse()));
|
||||
var action2 = cc.RepeatForever.create(cc.Sequence.create(
|
||||
a1.copy(), a2.copy(), a2.reverse()));
|
||||
|
||||
sp2.setAnchorPoint(cc.p(0, 0));
|
||||
|
||||
sp1.runAction(action1);
|
||||
sp2.runAction(action2);
|
||||
},
|
||||
title:function () {
|
||||
return "anchorPoint and children";
|
||||
}
|
||||
});
|
||||
|
||||
var SID_DELAY2 = 1;
|
||||
var SID_DELAY4 = 2;
|
||||
var CCNodeTest4 = TestCocosNodeDemo.extend({
|
||||
ctor:function () {
|
||||
var sp1 = cc.Sprite.create(s_pathSister1);
|
||||
var sp2 = cc.Sprite.create(s_pathSister2);
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
sp1.setPosition(cc.p(150, s.height / 2));
|
||||
sp2.setPosition(cc.p(s.width - 150, s.height / 2));
|
||||
|
||||
this.addChild(sp1, 0, 2);
|
||||
this.addChild(sp2, 0, 3);
|
||||
|
||||
this.schedule(this.delay2, 2.0);
|
||||
this.schedule(this.delay4, 4.0);
|
||||
},
|
||||
delay2:function (dt) {
|
||||
var node = this.getChildByTag(2);
|
||||
var action1 = cc.RotateBy.create(1, 360);
|
||||
node.runAction(action1);
|
||||
},
|
||||
delay4:function (dt) {
|
||||
this.unschedule(this.delay4);
|
||||
this.removeChildByTag(3, false);
|
||||
},
|
||||
title:function () {
|
||||
return "tags";
|
||||
}
|
||||
});
|
||||
|
||||
var CCNodeTest5 = TestCocosNodeDemo.extend({
|
||||
ctor:function () {
|
||||
var sp1 = cc.Sprite.create(s_pathSister1);
|
||||
var sp2 = cc.Sprite.create(s_pathSister2);
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
sp1.setPosition(cc.p(150, s.height / 2));
|
||||
sp2.setPosition(cc.p(s.width - 150, s.height / 2));
|
||||
|
||||
var rot = cc.RotateBy.create(2, 360);
|
||||
var rot_back = rot.reverse();
|
||||
var forever = cc.RepeatForever.create(cc.Sequence.create(rot, rot_back));
|
||||
var forever2 = forever.copy();
|
||||
forever.setTag(101);
|
||||
forever2.setTag(102);
|
||||
|
||||
this.addChild(sp1, 0, TAG_SPRITE1);
|
||||
this.addChild(sp2, 0, TAG_SPRITE2);
|
||||
|
||||
sp1.runAction(forever);
|
||||
sp2.runAction(forever2);
|
||||
|
||||
this.schedule(this.addAndRemove, 2.0);
|
||||
},
|
||||
addAndRemove:function (dt) {
|
||||
var sp1 = this.getChildByTag(TAG_SPRITE1);
|
||||
var sp2 = this.getChildByTag(TAG_SPRITE2);
|
||||
|
||||
this.removeChild(sp1, false);
|
||||
this.removeChild(sp2, true);
|
||||
|
||||
this.addChild(sp1, 0, TAG_SPRITE1);
|
||||
this.addChild(sp2, 0, TAG_SPRITE2);
|
||||
},
|
||||
title:function () {
|
||||
return "remove and cleanup";
|
||||
}
|
||||
});
|
||||
|
||||
var CCNodeTest6 = TestCocosNodeDemo.extend({
|
||||
ctor:function () {
|
||||
var sp1 = cc.Sprite.create(s_pathSister1);
|
||||
var sp11 = cc.Sprite.create(s_pathSister1);
|
||||
|
||||
var sp2 = cc.Sprite.create(s_pathSister2);
|
||||
var sp21 = cc.Sprite.create(s_pathSister2);
|
||||
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
sp1.setPosition(cc.p(150, s.height / 2));
|
||||
sp2.setPosition(cc.p(s.width - 150, s.height / 2));
|
||||
|
||||
var rot = cc.RotateBy.create(2, 360);
|
||||
var rot_back = rot.reverse();
|
||||
var forever1 = cc.RepeatForever.create(cc.Sequence.create(rot, rot_back));
|
||||
var forever11 = forever1.copy();
|
||||
|
||||
var forever2 = forever1.copy();
|
||||
var forever21 = forever1.copy();
|
||||
|
||||
this.addChild(sp1, 0, TAG_SPRITE1);
|
||||
sp1.addChild(sp11);
|
||||
this.addChild(sp2, 0, TAG_SPRITE2);
|
||||
sp2.addChild(sp21);
|
||||
|
||||
sp1.runAction(forever1);
|
||||
sp11.runAction(forever11);
|
||||
sp2.runAction(forever2);
|
||||
sp21.runAction(forever21);
|
||||
|
||||
this.schedule(this.addAndRemove, 2.0);
|
||||
},
|
||||
addAndRemove:function (dt) {
|
||||
var sp1 = this.getChildByTag(TAG_SPRITE1);
|
||||
var sp2 = this.getChildByTag(TAG_SPRITE2);
|
||||
|
||||
this.removeChild(sp1, false);
|
||||
this.removeChild(sp2, true);
|
||||
|
||||
this.addChild(sp1, 0, TAG_SPRITE1);
|
||||
this.addChild(sp2, 0, TAG_SPRITE2);
|
||||
},
|
||||
title:function () {
|
||||
return "remove/cleanup with children";
|
||||
}
|
||||
});
|
||||
|
||||
var StressTest1 = TestCocosNodeDemo.extend({
|
||||
ctor:function () {
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
var sp1 = cc.Sprite.create(s_pathSister1);
|
||||
this.addChild(sp1, 0, TAG_SPRITE1);
|
||||
|
||||
sp1.setPosition(cc.p(s.width / 2, s.height / 2));
|
||||
|
||||
this.schedule(this.shouldNotCrash, 1.0);
|
||||
},
|
||||
shouldNotCrash:function (dt) {
|
||||
this.unschedule(this.shouldNotCrash);
|
||||
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
// if the node has timers, it crashes
|
||||
var explosion = cc.ParticleSun.create();
|
||||
explosion.setTexture(cc.TextureCache.getInstance().addImage(s_fire));
|
||||
|
||||
explosion.setPosition(cc.p(s.width / 2, s.height / 2));
|
||||
|
||||
this.runAction(cc.Sequence.create(
|
||||
cc.RotateBy.create(2, 360),
|
||||
cc.CallFunc.create(this, this.removeMe)));
|
||||
|
||||
this.addChild(explosion);
|
||||
},
|
||||
removeMe:function (node) {
|
||||
this._parent.removeChild(node, true);
|
||||
this.nextCallback(this);
|
||||
},
|
||||
title:function () {
|
||||
return "stress test #1: no crashes";
|
||||
}
|
||||
});
|
||||
|
||||
var StressTest2 = TestCocosNodeDemo.extend({
|
||||
ctor:function () {
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
var sublayer = cc.Layer.create();
|
||||
|
||||
var sp1 = cc.Sprite.create(s_pathSister1);
|
||||
sp1.setPosition(cc.p(80, s.height / 2));
|
||||
|
||||
var move = cc.MoveBy.create(3, cc.p(350, 0));
|
||||
var move_ease_inout3 = cc.EaseInOut.create(move.copy(), 2.0);
|
||||
var move_ease_inout_back3 = move_ease_inout3.reverse();
|
||||
var seq3 = cc.Sequence.create(move_ease_inout3, move_ease_inout_back3);
|
||||
sp1.runAction(cc.RepeatForever.create(seq3));
|
||||
sublayer.addChild(sp1, 1);
|
||||
|
||||
var fire = cc.ParticleFire.create();
|
||||
fire.setTexture(cc.TextureCache.getInstance().addImage(s_fire));
|
||||
fire.setPosition(cc.p(80, s.height / 2 - 50));
|
||||
|
||||
var copy_seq3 = seq3.copy();
|
||||
|
||||
fire.runAction(cc.RepeatForever.create(copy_seq3));
|
||||
sublayer.addChild(fire, 2);
|
||||
|
||||
this.schedule(this.shouldNotLeak, 6.0);
|
||||
|
||||
this.addChild(sublayer, 0, TAG_SPRITE1);
|
||||
},
|
||||
shouldNotLeak:function (dt) {
|
||||
this.unschedule(this.shouldNotLeak);
|
||||
var sublayer = this.getChildByTag(TAG_SPRITE1);
|
||||
sublayer.removeAllChildrenWithCleanup(true);
|
||||
},
|
||||
title:function () {
|
||||
return "stress test #2: no leaks";
|
||||
}
|
||||
});
|
||||
|
||||
var SchedulerTest1 = TestCocosNodeDemo.extend({
|
||||
ctor:function () {
|
||||
var layer = cc.Layer.create();
|
||||
//UXLog("retain count after init is %d", layer.retainCount()); // 1
|
||||
|
||||
this.addChild(layer, 0);
|
||||
//UXLog("retain count after addChild is %d", layer.retainCount()); // 2
|
||||
|
||||
layer.schedule(this.doSomething);
|
||||
//UXLog("retain count after schedule is %d", layer.retainCount()); // 3 : (object-c viersion), but win32 version is still 2, because CCTimer class don't save target.
|
||||
|
||||
layer.unschedule(this.doSomething);
|
||||
//UXLog("retain count after unschedule is %d", layer.retainCount()); // STILL 3! (win32 is '2')
|
||||
},
|
||||
doSomething:function (dt) {
|
||||
},
|
||||
title:function () {
|
||||
return "cocosnode scheduler test #1";
|
||||
}
|
||||
});
|
||||
|
||||
var NodeToWorld = TestCocosNodeDemo.extend({
|
||||
ctor:function () {
|
||||
//
|
||||
// This code tests that nodeToParent works OK:
|
||||
// - It tests different anchor Points
|
||||
// - It tests different children anchor points
|
||||
|
||||
var back = cc.Sprite.create(s_back3);
|
||||
this.addChild(back, -10);
|
||||
back.setAnchorPoint(cc.p(0, 0));
|
||||
var backSize = back.getContentSize();
|
||||
|
||||
var item = cc.MenuItemImage.create(s_playNormal, s_playSelect);
|
||||
var menu = cc.Menu.create(item, null);
|
||||
menu.alignItemsVertically();
|
||||
menu.setPosition(cc.p(backSize.width / 2, backSize.height / 2));
|
||||
back.addChild(menu);
|
||||
|
||||
var rot = cc.RotateBy.create(5, 360);
|
||||
var fe = cc.RepeatForever.create(rot);
|
||||
item.runAction(fe);
|
||||
|
||||
var move = cc.MoveBy.create(3, cc.p(200, 0));
|
||||
var move_back = move.reverse();
|
||||
var seq = cc.Sequence.create(move, move_back);
|
||||
var fe2 = cc.RepeatForever.create(seq);
|
||||
back.runAction(fe2);
|
||||
},
|
||||
title:function () {
|
||||
return "nodeToParent transform";
|
||||
}
|
||||
});
|
||||
|
||||
var CameraOrbitTest = TestCocosNodeDemo.extend({
|
||||
ctor:function () {
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
var p = cc.Sprite.create(s_back3);
|
||||
this.addChild(p, 0);
|
||||
p.setPosition(cc.p(s.width / 2, s.height / 2));
|
||||
p.setOpacity(128);
|
||||
|
||||
// LEFT
|
||||
s = p.getContentSize();
|
||||
var sprite = cc.Sprite.create(s_pathGrossini);
|
||||
sprite.setScale(0.5);
|
||||
p.addChild(sprite, 0);
|
||||
sprite.setPosition(cc.p(s.width / 4 * 1, s.height / 2));
|
||||
var cam = sprite.getCamera();
|
||||
var orbit = cc.OrbitCamera.create(2, 1, 0, 0, 360, 0, 0);
|
||||
sprite.runAction(cc.RepeatForever.create(orbit));
|
||||
|
||||
// CENTER
|
||||
sprite = cc.Sprite.create(s_pathGrossini);
|
||||
sprite.setScale(1.0);
|
||||
p.addChild(sprite, 0);
|
||||
sprite.setPosition(cc.p(s.width / 4 * 2, s.height / 2));
|
||||
orbit = cc.OrbitCamera.create(2, 1, 0, 0, 360, 45, 0);
|
||||
sprite.runAction(cc.RepeatForever.create(orbit));
|
||||
|
||||
// RIGHT
|
||||
sprite = cc.Sprite.create(s_pathGrossini);
|
||||
sprite.setScale(2.0);
|
||||
p.addChild(sprite, 0);
|
||||
sprite.setPosition(cc.p(s.width / 4 * 3, s.height / 2));
|
||||
var ss = sprite.getContentSize();
|
||||
orbit = cc.OrbitCamera.create(2, 1, 0, 0, 360, 90, -45);
|
||||
sprite.runAction(cc.RepeatForever.create(orbit));
|
||||
|
||||
// PARENT
|
||||
orbit = cc.OrbitCamera.create(10, 1, 0, 0, 360, 0, 90);
|
||||
p.runAction(cc.RepeatForever.create(orbit));
|
||||
|
||||
this.setScale(1);
|
||||
},
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
cc.Director.getInstance().setProjection(cc.DIRECTOR_PROJECTION_3D);
|
||||
},
|
||||
onExit:function () {
|
||||
cc.Director.getInstance().setProjection(cc.DIRECTOR_PROJECTION_2D);
|
||||
this._super();
|
||||
},
|
||||
title:function () {
|
||||
return "Camera Orbit test";
|
||||
}
|
||||
});
|
||||
|
||||
var CameraZoomTest = TestCocosNodeDemo.extend({
|
||||
_z:0,
|
||||
ctor:function () {
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
// LEFT
|
||||
var sprite = cc.Sprite.create(s_pathGrossini);
|
||||
this.addChild(sprite, 0);
|
||||
sprite.setPosition(cc.p(s.width / 4 * 1, s.height / 2));
|
||||
var cam = sprite.getCamera();
|
||||
cam.setEyeXYZ(0, 0, 415);
|
||||
|
||||
// CENTER
|
||||
sprite = cc.Sprite.create(s_pathGrossini);
|
||||
this.addChild(sprite, 0, 40);
|
||||
sprite.setPosition(cc.p(s.width / 4 * 2, s.height / 2));
|
||||
// cam = [sprite camera);
|
||||
// [cam setEyeX:0 eyeY:0 eyeZ:415/2);
|
||||
|
||||
// RIGHT
|
||||
sprite = cc.Sprite.create(s_pathGrossini);
|
||||
this.addChild(sprite, 0, 20);
|
||||
sprite.setPosition(cc.p(s.width / 4 * 3, s.height / 2));
|
||||
// cam = [sprite camera);
|
||||
// [cam setEyeX:0 eyeY:0 eyeZ:-485);
|
||||
// [cam setCenterX:0 centerY:0 centerZ:0);
|
||||
|
||||
this._z = 0;
|
||||
this.scheduleUpdate();
|
||||
},
|
||||
update:function (dt) {
|
||||
this._z += dt * 100;
|
||||
|
||||
var sprite = this.getChildByTag(20);
|
||||
var cam = sprite.getCamera();
|
||||
cam.setEyeXYZ(0, 0, this._z);
|
||||
|
||||
sprite = this.getChildByTag(40);
|
||||
cam = sprite.getCamera();
|
||||
cam.setEyeXYZ(0, 0, this._z);
|
||||
},
|
||||
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
cc.Director.getInstance().setProjection(cc.DIRECTOR_PROJECTION_3D);
|
||||
},
|
||||
onExit:function () {
|
||||
cc.Director.getInstance().setProjection(cc.DIRECTOR_PROJECTION_2D);
|
||||
this._super();
|
||||
},
|
||||
title:function () {
|
||||
return "Camera Zoom test";
|
||||
}
|
||||
});
|
||||
|
||||
var CameraCenterTest = TestCocosNodeDemo.extend({
|
||||
ctor:function () {
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
// LEFT-TOP
|
||||
var sprite = new cc.Sprite();//.node();
|
||||
sprite.init();
|
||||
this.addChild(sprite, 0);
|
||||
sprite.setPosition(cc.p(s.width / 5 * 1, s.height / 5 * 1));
|
||||
sprite.setColor(cc.c3b(255,0,0));
|
||||
sprite.setTextureRect(cc.rect(0, 0, 120, 50));
|
||||
var orbit = cc.OrbitCamera.create(10, 1, 0, 0, 360, 0, 0);
|
||||
sprite.runAction(cc.RepeatForever.create(orbit));
|
||||
|
||||
// LEFT-BOTTOM
|
||||
sprite = new cc.Sprite();//.node();
|
||||
sprite.init();
|
||||
this.addChild(sprite, 0, 40);
|
||||
sprite.setPosition(cc.p(s.width / 5 * 1, s.height / 5 * 4));
|
||||
sprite.setColor(cc.c3b(0,0,255));
|
||||
sprite.setTextureRect(cc.rect(0, 0, 120, 50));
|
||||
orbit = cc.OrbitCamera.create(10, 1, 0, 0, 360, 0, 0);
|
||||
sprite.runAction(cc.RepeatForever.create(orbit));
|
||||
|
||||
// RIGHT-TOP
|
||||
sprite = new cc.Sprite();//.node();
|
||||
sprite.init();
|
||||
this.addChild(sprite, 0);
|
||||
sprite.setPosition(cc.p(s.width / 5 * 4, s.height / 5 * 1));
|
||||
sprite.setColor(cc.yellow());
|
||||
sprite.setTextureRect(cc.rect(0, 0, 120, 50));
|
||||
orbit = cc.OrbitCamera.create(10, 1, 0, 0, 360, 0, 0);
|
||||
sprite.runAction(cc.RepeatForever.create(orbit));
|
||||
|
||||
// RIGHT-BOTTOM
|
||||
sprite = new cc.Sprite();//.node();
|
||||
sprite.init();
|
||||
this.addChild(sprite, 0, 40);
|
||||
sprite.setPosition(cc.p(s.width / 5 * 4, s.height / 5 * 4));
|
||||
sprite.setColor(cc.c3b(0,255,0));
|
||||
sprite.setTextureRect(cc.rect(0, 0, 120, 50));
|
||||
orbit = cc.OrbitCamera.create(10, 1, 0, 0, 360, 0, 0);
|
||||
sprite.runAction(cc.RepeatForever.create(orbit));
|
||||
|
||||
// CENTER
|
||||
sprite = new cc.Sprite();
|
||||
sprite.init();
|
||||
this.addChild(sprite, 0, 40);
|
||||
sprite.setPosition(cc.p(s.width / 2, s.height / 2));
|
||||
sprite.setColor(cc.white());
|
||||
sprite.setTextureRect(cc.rect(0, 0, 120, 50));
|
||||
orbit = cc.OrbitCamera.create(10, 1, 0, 0, 360, 0, 0);
|
||||
sprite.runAction(cc.RepeatForever.create(orbit));
|
||||
},
|
||||
title:function () {
|
||||
return "Camera Center test";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "Sprites should rotate at the same speed";
|
||||
}
|
||||
});
|
||||
|
||||
var ConvertToNode = TestCocosNodeDemo.extend({
|
||||
ctor:function () {
|
||||
this.setTouchEnabled(true);
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
var rotate = cc.RotateBy.create(10, 360);
|
||||
var action = cc.RepeatForever.create(rotate);
|
||||
for (var i = 0; i < 3; i++) {
|
||||
var sprite = cc.Sprite.create(s_pathGrossini);
|
||||
sprite.setPosition(cc.p(s.width / 4 * (i + 1), s.height / 2));
|
||||
|
||||
var point = cc.Sprite.create(s_pathR1);
|
||||
point.setScale(0.25);
|
||||
point.setPosition(sprite.getPosition());
|
||||
this.addChild(point, 10, 100 + i);
|
||||
|
||||
switch (i) {
|
||||
case 0:
|
||||
sprite.setAnchorPoint(cc.p(0,0));
|
||||
break;
|
||||
case 1:
|
||||
sprite.setAnchorPoint(cc.p(0.5, 0.5));
|
||||
break;
|
||||
case 2:
|
||||
sprite.setAnchorPoint(cc.p(1, 1));
|
||||
break;
|
||||
}
|
||||
|
||||
point.setPosition(sprite.getPosition());
|
||||
|
||||
var copy = action.copy();
|
||||
sprite.runAction(copy);
|
||||
this.addChild(sprite, i);
|
||||
}
|
||||
},
|
||||
onTouchesEnded:function (touches, event) {
|
||||
for (var it = 0; it < touches.length; it++) {
|
||||
var touch = touches[it];
|
||||
var location = touch.getLocation();
|
||||
|
||||
location = cc.Director.getInstance().convertToGL(location);
|
||||
|
||||
for (var i = 0; i < 3; i++) {
|
||||
var node = this.getChildByTag(100 + i);
|
||||
|
||||
var p1 = node.convertToNodeSpaceAR(location);
|
||||
var p2 = node.convertToNodeSpace(location);
|
||||
|
||||
cc.log("AR: x=" + p1.x.toFixed(2) + ", y=" + p1.y.toFixed(2) + " -- Not AR: x=" + p2.x.toFixed(2) + ", y=" + p2.y.toFixed(2));
|
||||
}
|
||||
}
|
||||
},
|
||||
title:function () {
|
||||
return "Convert To Node Space";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "testing convertToNodeSpace / AR. Touch and see console";
|
||||
}
|
||||
});
|
||||
|
||||
var CocosNodeTestScene = TestScene.extend({
|
||||
runThisTest:function () {
|
||||
sceneIdx = -1;
|
||||
MAX_LAYER = 9;
|
||||
var layer = nextCocosNodeAction();
|
||||
this.addChild(layer);
|
||||
|
||||
cc.Director.getInstance().replaceScene(this);
|
||||
}
|
||||
});
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
/****************************************************************************
|
||||
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 CurrentLanguageTest = cc.Layer.extend({
|
||||
ctor:function () {
|
||||
this._super();
|
||||
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
var label = cc.LabelTTF.create("Current language Test", "Arial", 28);
|
||||
this.addChild(label, 0);
|
||||
label.setPosition(cc.p(s.width / 2, s.height - 50));
|
||||
|
||||
var labelLanguage = cc.LabelTTF.create("", "Arial", 20);
|
||||
labelLanguage.setPosition(cc.p(s.width / 2, s.height / 2));
|
||||
|
||||
var currentLanguageType = cc.Application.getCurrentLanguage();
|
||||
switch (currentLanguageType) {
|
||||
case cc.LANGUAGE_ENGLISH:
|
||||
labelLanguage.setString("current language is English");
|
||||
break;
|
||||
case cc.LANGUAGE_CHINESE:
|
||||
labelLanguage.setString("current language is Chinese");
|
||||
break;
|
||||
case cc.LANGUAGE_FRENCH:
|
||||
labelLanguage.setString("current language is French");
|
||||
break;
|
||||
case cc.LANGUAGE_GERMAN:
|
||||
labelLanguage.setString("current language is German");
|
||||
break;
|
||||
case cc.LANGUAGE_ITALIAN:
|
||||
labelLanguage.setString("current language is Italian");
|
||||
break;
|
||||
case cc.LANGUAGE_RUSSIAN:
|
||||
labelLanguage.setString("current language is Russian");
|
||||
break;
|
||||
case cc.LANGUAGE_SPANISH:
|
||||
labelLanguage.setString("current language is Spanish");
|
||||
break;
|
||||
}
|
||||
|
||||
this.addChild(labelLanguage);
|
||||
}
|
||||
});
|
||||
|
||||
var CurrentLanguageTestScene = TestScene.extend({
|
||||
runThisTest:function () {
|
||||
var layer = new CurrentLanguageTest();
|
||||
this.addChild(layer);
|
||||
|
||||
cc.Director.getInstance().replaceScene(this);
|
||||
}
|
||||
});
|
|
@ -0,0 +1,131 @@
|
|||
/****************************************************************************
|
||||
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 DrawPrimitivesTest = cc.Layer.extend({
|
||||
ctor:function () {
|
||||
},
|
||||
draw:function () {
|
||||
this._super();
|
||||
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
cc.renderContext.fillStyle = "rgba(255,255,255,1)";
|
||||
cc.renderContext.strokeStyle = "rgba(255,255,255,1)";
|
||||
// draw a simple line
|
||||
// The default state is:
|
||||
// Line Width: 1
|
||||
// color: 255,255,255,255 (white, non-transparent)
|
||||
// Anti-Aliased
|
||||
cc.drawingUtil.drawLine(cc.p(0, 0), cc.p(s.width, s.height));
|
||||
|
||||
// line: color, width, aliased
|
||||
// glLineWidth > 1 and GL_LINE_SMOOTH are not compatible
|
||||
// GL_SMOOTH_LINE_WIDTH_RANGE = (1,1) on iPhone
|
||||
cc.renderContext.strokeStyle = "rgba(255,0,0,1)";
|
||||
cc.renderContext.lineWidth = "5";
|
||||
|
||||
/*glColor4ub(255,0,0,255);*/
|
||||
//glColor4f(1.0, 0.0, 0.0, 1.0);
|
||||
cc.drawingUtil.drawLine(cc.p(0, s.height), cc.p(s.width, 0));
|
||||
|
||||
// TIP:
|
||||
// If you are going to use always the same color or width, you don't
|
||||
// need to call it before every draw
|
||||
//
|
||||
// Remember: OpenGL is a state-machine.
|
||||
|
||||
// draw big point in the center
|
||||
/*glColor4ub(0,0,255,128);*/
|
||||
//glColor4f(0.0, 0.0, 1.0, 0.5);
|
||||
cc.renderContext.fillStyle = "rgba(0,0,255,0.5)";
|
||||
cc.drawingUtil.drawPoint(cc.p(s.width / 2, s.height / 2), 40);
|
||||
|
||||
// draw 4 small points
|
||||
var points = [cc.p(60, 60), cc.p(70, 70), cc.p(60, 70), cc.p(70, 60)];
|
||||
/*glColor4ub(0,255,255,255);*/
|
||||
cc.renderContext.fillStyle = "rgba(0,255,255,1)";
|
||||
//glColor4f(0.0, 1.0, 1.0, 1.0);
|
||||
cc.drawingUtil.drawPoints(points, 4, 4);
|
||||
|
||||
// draw a green circle with 10 segments
|
||||
//glLineWidth(16);
|
||||
cc.renderContext.lineWidth = "16";
|
||||
/*glColor4ub(0, 255, 0, 255);*/
|
||||
//glColor4f(0.0, 1.0, 0.0, 1.0);
|
||||
cc.renderContext.strokeStyle = "rgba(0,255,0,1)";
|
||||
cc.drawingUtil.drawCircle(cc.p(s.width / 2, s.height / 2), 100, 0, 10, false);
|
||||
|
||||
// draw a green circle with 50 segments with line to center
|
||||
//glLineWidth(2);
|
||||
cc.renderContext.lineWidth = "2";
|
||||
/*glColor4ub(0, 255, 255, 255);*/
|
||||
//glColor4f(0.0, 1.0, 1.0, 1.0);
|
||||
cc.renderContext.strokeStyle = "rgba(0,255,255,1)";
|
||||
cc.drawingUtil.drawCircle(cc.p(s.width / 2, s.height / 2), 50, cc.DEGREES_TO_RADIANS(90), 50, true);
|
||||
|
||||
// open yellow poly
|
||||
/*glColor4ub(255, 255, 0, 255);*/
|
||||
//glColor4f(1.0, 1.0, 0.0, 1.0);
|
||||
cc.renderContext.strokeStyle = "rgba(255,255,0,1)";
|
||||
//glLineWidth(10);
|
||||
cc.renderContext.lineWidth = "10";
|
||||
var vertices = [cc.p(0, 0), cc.p(50, 50), cc.p(100, 50), cc.p(100, 100), cc.p(50, 100) ];
|
||||
cc.drawingUtil.drawPoly(vertices, 5, false);
|
||||
|
||||
// closed purble poly
|
||||
/*glColor4ub(255, 0, 255, 255);*/
|
||||
//glColor4f(1.0, 0.0, 1.0, 1.0);
|
||||
cc.renderContext.strokeStyle = "rgba(255,0,255,1)";
|
||||
//glLineWidth(2);
|
||||
cc.renderContext.lineWidth = "2";
|
||||
var vertices2 = [cc.p(30, 130), cc.p(30, 230), cc.p(50, 200)];
|
||||
cc.drawingUtil.drawPoly(vertices2, 3, true);
|
||||
|
||||
// draw quad bezier path
|
||||
cc.drawingUtil.drawQuadBezier(cc.p(0, s.height), cc.p(s.width / 2, s.height / 2), cc.p(s.width, s.height), 50);
|
||||
|
||||
// draw cubic bezier path
|
||||
cc.drawingUtil.drawCubicBezier(cc.p(s.width / 2, s.height / 2), cc.p(s.width / 2 + 30, s.height / 2 + 50),
|
||||
cc.p(s.width / 2 + 60, s.height / 2 - 50), cc.p(s.width, s.height / 2), 100);
|
||||
|
||||
// restore original values
|
||||
cc.renderContext.lineWidth = "1";
|
||||
//glLineWidth(1);
|
||||
/*glColor4ub(255,255,255,255);*/
|
||||
//glColor4f(1.0, 1.0, 1.0, 1.0);
|
||||
//glPointSize(1);
|
||||
cc.renderContext.fillStyle = "rgba(255,255,255,1)";
|
||||
cc.renderContext.strokeStyle = "rgba(255,255,255,1)";
|
||||
}
|
||||
});
|
||||
|
||||
var DrawPrimitivesTestScene = TestScene.extend({
|
||||
runThisTest:function () {
|
||||
var layer = new DrawPrimitivesTest();
|
||||
this.addChild(layer);
|
||||
|
||||
cc.Director.getInstance().replaceScene(this);
|
||||
}
|
||||
});
|
|
@ -0,0 +1,628 @@
|
|||
/****************************************************************************
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
TAG_ACTION1_EASE_ACTIONS = 1;
|
||||
TAG_ACTION2_EASE_ACTIONS = 2;
|
||||
TAG_SLIDER_EASE_ACTIONS = 1;
|
||||
|
||||
var sceneIdx = -1;
|
||||
|
||||
// the class inherit from TestScene
|
||||
// every .Scene each test used must inherit from TestScene,
|
||||
// make sure the test have the menu item for back to main menu
|
||||
var EaseActionsTestScene = TestScene.extend({
|
||||
runThisTest:function () {
|
||||
sceneIdx = -1;
|
||||
this.addChild(nextEaseActionsTest());
|
||||
director.replaceScene(this);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
var EaseSpriteDemo = cc.Layer.extend({
|
||||
_grossini:null,
|
||||
_tamara:null,
|
||||
_kathia:null,
|
||||
_title:null,
|
||||
|
||||
ctor:function() {
|
||||
cc.associateWithNative( this, cc.Layer );
|
||||
this.init();
|
||||
},
|
||||
init:function() {
|
||||
// this._super(cc.c4b(0, 0, 0, 255), cc.c4b(0, 128, 255, 255));
|
||||
this._super();
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "No title";
|
||||
},
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
// Or you can create an sprite using a filename. PNG and BMP files are supported. Probably TIFF too
|
||||
this._grossini = cc.Sprite.create(s_pathGrossini);
|
||||
this._tamara = cc.Sprite.create(s_pathSister1);
|
||||
this._kathia = cc.Sprite.create(s_pathSister2);
|
||||
|
||||
this.addChild(this._grossini, 3);
|
||||
this.addChild(this._kathia, 2);
|
||||
this.addChild(this._tamara, 1);
|
||||
|
||||
this._grossini.setPosition(cc.p(60, winSize.height*1/5));
|
||||
this._kathia.setPosition(cc.p(60, winSize.height/2));
|
||||
this._tamara.setPosition(cc.p(60, winSize.height*4/5));
|
||||
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 32);
|
||||
this.addChild(label);
|
||||
label.setPosition(cc.p(winSize.width / 2, winSize.height - 50));
|
||||
|
||||
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);
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3);
|
||||
|
||||
menu.setPosition(cc.p(0,0));
|
||||
|
||||
var cs = item2.getContentSize();
|
||||
item1.setPosition( cc.p(winSize.width/2 - cs.width*2, cs.height/2) );
|
||||
item2.setPosition( cc.p(winSize.width/2, cs.height/2) );
|
||||
item3.setPosition( cc.p(winSize.width/2 + cs.width*2, cs.height/2) );
|
||||
|
||||
this.addChild(menu, 1);
|
||||
},
|
||||
|
||||
restartCallback:function (sender) {
|
||||
var s = new EaseActionsTestScene();//cc.Scene.create();
|
||||
s.addChild(restartEaseActionsTest());
|
||||
director.replaceScene(s);
|
||||
},
|
||||
nextCallback:function (sender) {
|
||||
var s = new EaseActionsTestScene();//cc.Scene.create();
|
||||
s.addChild(nextEaseActionsTest());
|
||||
director.replaceScene(s);
|
||||
},
|
||||
backCallback:function (sender) {
|
||||
var s = new EaseActionsTestScene();//cc.Scene.create();
|
||||
s.addChild(previousEaseActionsTest());
|
||||
director.replaceScene(s);
|
||||
},
|
||||
positionForTwo:function () {
|
||||
this._grossini.setPosition(cc.p(60, winSize.height*1/5));
|
||||
this._tamara.setPosition(cc.p(60, winSize.height*4/5));
|
||||
this._kathia.setVisible(false);
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteEase
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteEase = EaseSpriteDemo.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.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.schedule(this.testStopAction, 6);
|
||||
},
|
||||
title:function () {
|
||||
return "EaseIn - EaseOut - Stop";
|
||||
},
|
||||
|
||||
testStopAction:function (dt) {
|
||||
this.unschedule(this.testStopAction);
|
||||
this._tamara.stopActionByTag(1);
|
||||
this._kathia.stopActionByTag(1);
|
||||
this._grossini.stopActionByTag(1);
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteEaseInOut
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteEaseInOut = EaseSpriteDemo.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";
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteEaseExponential
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteEaseExponential = EaseSpriteDemo.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";
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteEaseExponentialInOut
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteEaseExponentialInOut = EaseSpriteDemo.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";
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteEaseSine
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SpriteEaseSine = EaseSpriteDemo.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 = EaseSpriteDemo.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 = EaseSpriteDemo.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 = EaseSpriteDemo.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 = EaseSpriteDemo.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 = EaseSpriteDemo.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 = EaseSpriteDemo.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 = EaseSpriteDemo.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 = EaseSpriteDemo.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
// rotate and jump
|
||||
var jump1 = cc.JumpBy.create(4, cc.p(-winSize.width+80, 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(Math.random() * 2);
|
||||
action2.setSpeed(Math.random() * 2);
|
||||
action3.setSpeed(Math.random() * 2);
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SchedulerTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var SchedulerTest = EaseSpriteDemo.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
// rotate and jump
|
||||
var jump1 = cc.JumpBy.create(4, cc.p(-winSize.width+80, 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.RepeatForever.create(spawn);
|
||||
|
||||
var action2 = action.copy();
|
||||
var action3 = action.copy();
|
||||
|
||||
this._grossini.runAction(cc.Speed.create(action, 0.5));
|
||||
this._tamara.runAction(cc.Speed.create(action2, 1.5));
|
||||
this._kathia.runAction(cc.Speed.create(action3, 1.0));
|
||||
|
||||
var emitter = new cc.ParticleFireworks();
|
||||
emitter.initWithTotalParticles(250);
|
||||
emitter.setTexture(cc.TextureCache.getInstance().addImage("res/Images/fire.png"));
|
||||
this.addChild(emitter);
|
||||
},
|
||||
title:function () {
|
||||
return "Scheduler scaleTime Test";
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// Flow control
|
||||
//
|
||||
var arrayOfEaseActionsTest = [
|
||||
SpriteEase,
|
||||
SpriteEaseInOut,
|
||||
SpriteEaseExponential,
|
||||
SpriteEaseExponentialInOut,
|
||||
SpriteEaseSine,
|
||||
SpriteEaseSineInOut,
|
||||
SpriteEaseElastic,
|
||||
SpriteEaseElasticInOut,
|
||||
SpriteEaseBounce,
|
||||
SpriteEaseBounceInOut,
|
||||
SpriteEaseBack,
|
||||
SpriteEaseBackInOut,
|
||||
SpeedTest,
|
||||
SchedulerTest
|
||||
];
|
||||
|
||||
var nextEaseActionsTest = function () {
|
||||
sceneIdx++;
|
||||
sceneIdx = sceneIdx % arrayOfEaseActionsTest.length;
|
||||
|
||||
return new arrayOfEaseActionsTest[sceneIdx]();
|
||||
};
|
||||
var previousEaseActionsTest = function () {
|
||||
sceneIdx--;
|
||||
if (sceneIdx < 0)
|
||||
sceneIdx += arrayOfEaseActionsTest.length;
|
||||
|
||||
return new arrayOfEaseActionsTest[sceneIdx]();
|
||||
};
|
||||
var restartEaseActionsTest = function () {
|
||||
return new arrayOfEaseActionsTest[sceneIdx]();
|
||||
};
|
|
@ -0,0 +1,113 @@
|
|||
/****************************************************************************
|
||||
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 LINE_SPACE = 40;
|
||||
var ITEM_TAG_BASIC = 1000;
|
||||
|
||||
var TEST_NOTIFICATIONCENTER = 0;
|
||||
var TEST_CCCONTROLBUTTON = 1;
|
||||
var TEST_COCOSBUILDER = 2;
|
||||
var TEST_HTTPCLIENT = 3;
|
||||
|
||||
var extensionsTestItemNames = [
|
||||
/* {
|
||||
itemTitle:"NotificationCenterTest",
|
||||
testScene:function () {
|
||||
//runNotificationCenterTest();
|
||||
cc.log("not implement");
|
||||
}
|
||||
},*/
|
||||
{
|
||||
itemTitle:"CCControlButtonTest",
|
||||
testScene:function () {
|
||||
var pManager = ControlSceneManager.getInstance();
|
||||
var pScene = pManager.currentControlScene();
|
||||
cc.Director.getInstance().replaceScene(pScene);
|
||||
}
|
||||
},
|
||||
{
|
||||
itemTitle:"CocosBuilderTest",
|
||||
testScene:function () {
|
||||
var pScene = new CocosBuilderTestScene();
|
||||
if (pScene) {
|
||||
pScene.runThisTest();
|
||||
}
|
||||
}
|
||||
},
|
||||
/* {
|
||||
itemTitle:"HttpClientTest",
|
||||
testScene:function () {
|
||||
//runHttpClientTest();
|
||||
cc.log("not implement");
|
||||
}
|
||||
},*/
|
||||
{
|
||||
itemTitle:"TableViewTest",
|
||||
testScene:function () {
|
||||
runTableViewTest();
|
||||
}
|
||||
}
|
||||
/* {
|
||||
itemTitle:"EditBoxTest",
|
||||
testScene:function () {
|
||||
//runEditBoxTest();
|
||||
}
|
||||
}*/
|
||||
];
|
||||
|
||||
var ExtensionsMainLayer = cc.Layer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var winSize = cc.Director.getInstance().getWinSize();
|
||||
|
||||
var pMenu = cc.Menu.create();
|
||||
pMenu.setPosition(cc.p(0,0));
|
||||
cc.MenuItemFont.setFontName("Arial");
|
||||
cc.MenuItemFont.setFontSize(24);
|
||||
for (var i = 0; i < extensionsTestItemNames.length; ++i){
|
||||
var selItem = extensionsTestItemNames[i];
|
||||
var pItem = cc.MenuItemFont.create(selItem.itemTitle, this,
|
||||
this.menuCallback);
|
||||
pItem.setPosition(cc.p(winSize.width / 2, winSize.height - (i + 1) * LINE_SPACE));
|
||||
pMenu.addChild(pItem, ITEM_TAG_BASIC + i);
|
||||
}
|
||||
this.addChild(pMenu);
|
||||
},
|
||||
|
||||
menuCallback:function (sender) {
|
||||
var nIndex = sender.getZOrder() - ITEM_TAG_BASIC;
|
||||
extensionsTestItemNames[nIndex].testScene();
|
||||
}
|
||||
});
|
||||
|
||||
var ExtensionsTestScene = TestScene.extend({
|
||||
runThisTest:function () {
|
||||
var pLayer = new ExtensionsMainLayer();
|
||||
this.addChild(pLayer);
|
||||
cc.Director.getInstance().replaceScene(this);
|
||||
}
|
||||
});
|
|
@ -0,0 +1,137 @@
|
|||
/****************************************************************************
|
||||
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_LABEL1 = 550;
|
||||
var TAG_LABEL2 = 551;
|
||||
var TAG_LABEL3 = 552;
|
||||
var TAG_LABEL4 = 553;
|
||||
|
||||
var fontIdx = 0;
|
||||
|
||||
var fontList = [
|
||||
"Verdana",
|
||||
"Lucida Sans Unicode",
|
||||
"Bookman Old Style",
|
||||
"Symbol",
|
||||
"Georgia",
|
||||
"Trebuchet MS",
|
||||
"Comic Sans MS",
|
||||
"Arial Black",
|
||||
"Tahoma",
|
||||
"Impact"
|
||||
];
|
||||
|
||||
|
||||
function nextFontTestAction() {
|
||||
fontIdx++;
|
||||
fontIdx = fontIdx % fontList.length;
|
||||
return fontList[fontIdx]
|
||||
}
|
||||
|
||||
function backFontTestAction() {
|
||||
fontIdx--;
|
||||
if (fontIdx < 0) {
|
||||
fontIdx += fontList.length;
|
||||
}
|
||||
|
||||
return fontList[fontIdx];
|
||||
}
|
||||
|
||||
function restartFontTestAction() {
|
||||
return fontList[fontIdx];
|
||||
}
|
||||
FontTestScene = TestScene.extend({
|
||||
|
||||
runThisTest:function () {
|
||||
var layer = FontTest.node();
|
||||
this.addChild(layer);
|
||||
|
||||
cc.Director.getInstance().replaceScene(this);
|
||||
}
|
||||
});
|
||||
|
||||
FontTest = cc.Layer.extend({
|
||||
ctor:function () {
|
||||
var size = cc.Director.getInstance().getWinSize();
|
||||
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);
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3, null);
|
||||
menu.setPosition(cc.p(0,0));
|
||||
item1.setPosition(cc.p(size.width / 2 - 100, 30));
|
||||
item2.setPosition(cc.p(size.width / 2, 30));
|
||||
item3.setPosition(cc.p(size.width / 2 + 100, 30));
|
||||
this.addChild(menu, 1);
|
||||
|
||||
this.showFont(restartFontTestAction());
|
||||
|
||||
},
|
||||
showFont:function (pFont) {
|
||||
this.removeChildByTag(TAG_LABEL1, true);
|
||||
this.removeChildByTag(TAG_LABEL2, true);
|
||||
this.removeChildByTag(TAG_LABEL3, true);
|
||||
this.removeChildByTag(TAG_LABEL4, true);
|
||||
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
var top = cc.LabelTTF.create(pFont, pFont, 24);
|
||||
var left = cc.LabelTTF.create("alignment left", pFont, 32, cc.size(s.width, 50), cc.TEXT_ALIGNMENT_LEFT);
|
||||
var center = cc.LabelTTF.create("alignment center", pFont, 32, cc.size(s.width, 50), cc.TEXT_ALIGNMENT_CENTER);
|
||||
var right = cc.LabelTTF.create("alignment right", pFont, 32, cc.size(s.width, 50), cc.TEXT_ALIGNMENT_RIGHT);
|
||||
|
||||
top.setPosition(cc.p(s.width / 2, s.height * 3 / 4));
|
||||
left.setPosition(cc.p(s.width / 2, s.height / 2));
|
||||
center.setPosition(cc.p(s.width / 2, s.height * 3 / 8));
|
||||
right.setPosition(cc.p(s.width / 2, s.height / 4));
|
||||
|
||||
this.addChild(left, 0, TAG_LABEL1);
|
||||
this.addChild(right, 0, TAG_LABEL2);
|
||||
this.addChild(center, 0, TAG_LABEL3);
|
||||
this.addChild(top, 0, TAG_LABEL4);
|
||||
|
||||
},
|
||||
|
||||
restartCallback:function (sender) {
|
||||
this.showFont(restartFontTestAction());
|
||||
},
|
||||
nextCallback:function (sender) {
|
||||
this.showFont(nextFontTestAction());
|
||||
},
|
||||
backCallback:function (sender) {
|
||||
this.showFont(backFontTestAction());
|
||||
},
|
||||
title:function () {
|
||||
return "Font test";
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
FontTest.node = function () {
|
||||
var ret = new FontTest();
|
||||
ret.init();
|
||||
return ret;
|
||||
};
|
|
@ -0,0 +1,141 @@
|
|||
/****************************************************************************
|
||||
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 HelloCocosBuilderLayer = cc.Layer.extend({
|
||||
_burstSprite:null,
|
||||
_testTitleLableTTF:null,
|
||||
|
||||
openTest:function(ccbFileName, nodeName,nodeLoader){
|
||||
/* Create an autorelease CCNodeLoaderLibrary. */
|
||||
var ccNodeLoaderLibrary = cc.NodeLoaderLibrary.newDefaultCCNodeLoaderLibrary();
|
||||
|
||||
ccNodeLoaderLibrary.registerCCNodeLoader("TestHeaderLayer", new TestHeaderLayerLoader());
|
||||
if(nodeName != null && nodeLoader != null) {
|
||||
ccNodeLoaderLibrary.registerCCNodeLoader(nodeName, nodeLoader);
|
||||
}
|
||||
|
||||
/* Create an autorelease CCBReader. */
|
||||
var ccbReader = new cc.CCBReader(ccNodeLoaderLibrary);
|
||||
|
||||
/* Read a ccbi file. */
|
||||
// Load the scene from the ccbi-file, setting this class as
|
||||
// the owner will cause lblTestTitle to be set by the CCBReader.
|
||||
// lblTestTitle is in the TestHeader.ccbi, which is referenced
|
||||
// from each of the test scenes.
|
||||
var node = ccbReader.readNodeGraphFromFile("res/ccb/official/pub/", ccbFileName, this);
|
||||
|
||||
this._testTitleLableTTF.setString(ccbFileName);
|
||||
var scene = cc.Scene.create();
|
||||
if(node != null)
|
||||
scene.addChild(node);
|
||||
|
||||
/* Push the new scene with a fancy transition. */
|
||||
cc.Director.getInstance().pushScene(cc.TransitionFade.create(0.5, scene, cc.black()));
|
||||
},
|
||||
|
||||
onResolveCCBCCMenuItemSelector:function(target,selectorName){
|
||||
return null;
|
||||
},
|
||||
onResolveCCBCCControlSelector:function(target,selectorName){
|
||||
if(this == target && "onMenuTestClicked" == selectorName){
|
||||
return this.onMenuTestClicked;
|
||||
}
|
||||
if(this == target && "onSpriteTestClicked" == selectorName){
|
||||
return this.onSpriteTestClicked;
|
||||
}
|
||||
if(this == target && "onButtonTestClicked" == selectorName){
|
||||
return this.onButtonTestClicked;
|
||||
}
|
||||
if(this == target && "onLabelTestClicked" == selectorName){
|
||||
return this.onLabelTestClicked;
|
||||
}
|
||||
if(this == target && "onParticleSystemTestClicked" == selectorName){
|
||||
return this.onParticleSystemTestClicked;
|
||||
}
|
||||
if(this == target && "onScrollViewTestClicked" == selectorName){
|
||||
return this.onScrollViewTestClicked;
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
onAssignCCBMemberVariable:function(target,memberVariableName,node){
|
||||
if(target == this && memberVariableName == "mBurstSprite"){
|
||||
if(node instanceof cc.Sprite){
|
||||
this._burstSprite = node;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if(target == this && memberVariableName == "mTestTitleLabelTTF"){
|
||||
if(node instanceof cc.LabelTTF){
|
||||
this.mTestTitleLabelTTF = node;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
onNodeLoaded:function(node,nodeLoader){
|
||||
var ccRotateBy = cc.RotateBy.create(0.5, 10);
|
||||
var ccRepeatForever = cc.RepeatForever.create(ccRotateBy);
|
||||
this._burstSprite.runAction(ccRepeatForever);
|
||||
},
|
||||
|
||||
onMenuTestClicked:function(sender,controlEvent){
|
||||
this.openTest("ccb/MenuTest.ccbi", "MenuTestLayer", MenuTestLayerLoader.loader());
|
||||
},
|
||||
|
||||
onSpriteTestClicked:function(sender,controlEvent){
|
||||
this.openTest("ccb/SpriteTest.ccbi", "SpriteTestLayer", SpriteTestLayerLoader.loader());
|
||||
},
|
||||
onButtonTestClicked:function(sender,controlEvent){
|
||||
this.openTest("ccb/ButtonTest.ccbi", "ButtonTestLayer", ButtonTestLayerLoader.loader());
|
||||
},
|
||||
onLabelTestClicked:function(sender,controlEvent){
|
||||
this.openTest("ccb/LabelTest.ccbi", "LabelTestLayer", LabelTestLayerLoader.loader());
|
||||
},
|
||||
onParticleSystemTestClicked:function(sender,controlEvent){
|
||||
this.openTest("ccb/ParticleSystemTest.ccbi", "ParticleSystemTestLayer", ParticleSystemTestLayerLoader.loader());
|
||||
},
|
||||
onScrollViewTestClicked:function(sender,controlEvent){
|
||||
this.openTest("ccb/ScrollViewTest.ccbi", "ScrollViewTestLayer", ScrollViewTestLayerLoader.loader());
|
||||
}
|
||||
});
|
||||
|
||||
HelloCocosBuilderLayer.create = function(){
|
||||
var retLayer = new HelloCocosBuilderLayer();
|
||||
if(retLayer && retLayer.init()){
|
||||
return retLayer;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
var HelloCocosBuilderLayerLoader = cc.LayerLoader.extend({
|
||||
_createCCNode:function(parent,ccbReader){
|
||||
return HelloCocosBuilderLayer.create();
|
||||
}
|
||||
});
|
|
@ -0,0 +1,147 @@
|
|||
/****************************************************************************
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
IntervalLayer = cc.Layer.extend({
|
||||
|
||||
label0:null,
|
||||
label1:null,
|
||||
label2:null,
|
||||
label3:null,
|
||||
label4:null,
|
||||
|
||||
time0:null,
|
||||
time1:null,
|
||||
time2:null,
|
||||
time3:null,
|
||||
time4:null,
|
||||
|
||||
ctor:function () {
|
||||
this.time0 = this.time1 = this.time2 = this.time3 = this.time4 = 0.0;
|
||||
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
// sun
|
||||
var sun = cc.ParticleSun.create();
|
||||
sun.setTexture(cc.TextureCache.getInstance().addImage(s_fire));
|
||||
sun.setPosition(cc.p(s.width - 32, s.height - 32));
|
||||
|
||||
sun.setTotalParticles(130);
|
||||
sun.setLife(0.6);
|
||||
this.addChild(sun);
|
||||
|
||||
// timers
|
||||
this.label0 = cc.LabelTTF.create("0", "Arial", 24);
|
||||
this.label1 = cc.LabelTTF.create("0", "Arial", 24);
|
||||
this.label2 = cc.LabelTTF.create("0", "Arial", 24);
|
||||
this.label3 = cc.LabelTTF.create("0", "Arial", 24);
|
||||
this.label4 = cc.LabelTTF.create("0", "Arial", 24);
|
||||
|
||||
this.scheduleUpdate();
|
||||
this.schedule(this.step1);
|
||||
this.schedule(this.step2, 0);
|
||||
this.schedule(this.step3, 1.0);
|
||||
this.schedule(this.step4, 2.0);
|
||||
|
||||
this.label0.setPosition(cc.p(s.width * 1 / 6, s.height / 2));
|
||||
this.label1.setPosition(cc.p(s.width * 2 / 6, s.height / 2));
|
||||
this.label2.setPosition(cc.p(s.width * 3 / 6, s.height / 2));
|
||||
this.label3.setPosition(cc.p(s.width * 4 / 6, s.height / 2));
|
||||
this.label4.setPosition(cc.p(s.width * 5 / 6, s.height / 2));
|
||||
|
||||
this.addChild(this.label0);
|
||||
this.addChild(this.label1);
|
||||
this.addChild(this.label2);
|
||||
this.addChild(this.label3);
|
||||
this.addChild(this.label4);
|
||||
|
||||
// Sprite
|
||||
var sprite = cc.Sprite.create(s_pathGrossini);
|
||||
sprite.setPosition(cc.p(40, 50));
|
||||
|
||||
var jump = cc.JumpBy.create(3, cc.p(s.width - 80, 0), 50, 4);
|
||||
|
||||
this.addChild(sprite);
|
||||
sprite.runAction(cc.RepeatForever.create(cc.Sequence.create(jump, jump.reverse(), null)));
|
||||
|
||||
// pause button
|
||||
var item1 = cc.MenuItemFont.create("Pause", this, this.onPause);
|
||||
var menu = cc.Menu.create(item1, null);
|
||||
menu.setPosition(cc.p(s.width / 2, s.height - 50));
|
||||
|
||||
this.addChild(menu);
|
||||
|
||||
},
|
||||
|
||||
onPause:function (sender) {
|
||||
if (cc.Director.getInstance().isPaused()) {
|
||||
cc.Director.getInstance().resume();
|
||||
} else {
|
||||
cc.Director.getInstance().pause();
|
||||
}
|
||||
},
|
||||
|
||||
onExit:function () {
|
||||
if (cc.Director.getInstance().isPaused()) {
|
||||
cc.Director.getInstance().resume();
|
||||
}
|
||||
this._super();
|
||||
},
|
||||
|
||||
step1:function (dt) {
|
||||
this.time1 += dt;
|
||||
this.label1.setString(this.time1.toFixed(1));
|
||||
},
|
||||
step2:function (dt) {
|
||||
this.time2 += dt;
|
||||
this.label2.setString(this.time2.toFixed(1));
|
||||
},
|
||||
step3:function (dt) {
|
||||
this.time3 += dt;
|
||||
this.label3.setString(this.time3.toFixed(1));
|
||||
},
|
||||
step4:function (dt) {
|
||||
this.time4 += dt;
|
||||
this.label4.setString(this.time4.toFixed(1));
|
||||
},
|
||||
update:function (dt) {
|
||||
this.time0 += dt;
|
||||
|
||||
this.label0.setString(this.time0.toFixed(1));
|
||||
}
|
||||
|
||||
//CREATE_NODE(IntervalLayer);
|
||||
});
|
||||
|
||||
IntervalTestScene = TestScene.extend({
|
||||
|
||||
runThisTest:function () {
|
||||
var layer = new IntervalLayer();
|
||||
this.addChild(layer);
|
||||
cc.Director.getInstance().replaceScene(this);
|
||||
}
|
||||
});
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,405 @@
|
|||
/****************************************************************************
|
||||
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.
|
||||
****************************************************************************/
|
||||
cc.TAG_LAYER = 1;
|
||||
|
||||
var LayerTestScene = TestScene.extend({
|
||||
runThisTest:function () {
|
||||
sceneIdx = -1;
|
||||
this.addChild(nextLayerTest());
|
||||
director.replaceScene(this);
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// LayerTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var LayerTest = cc.Layer.extend({
|
||||
_title:null,
|
||||
|
||||
ctor:function() {
|
||||
cc.associateWithNative( this, cc.Layer );
|
||||
this.init();
|
||||
},
|
||||
|
||||
init:function() {
|
||||
this._super();
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "No title";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "";
|
||||
},
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
var s = director.getWinSize();
|
||||
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 32);
|
||||
this.addChild(label, 1);
|
||||
label.setPosition(cc.p(s.width / 2, s.height - 50));
|
||||
|
||||
var subtitle_ = this.subtitle();
|
||||
if (subtitle_) {
|
||||
var l = cc.LabelTTF.create(subtitle_, "Thonburi", 16, cc.size(400, 16), cc.TEXT_ALIGNMENT_CENTER);
|
||||
this.addChild(l, 1);
|
||||
l.setPosition(cc.p(s.width / 2, s.height - 80));
|
||||
}
|
||||
|
||||
var item1 = cc.MenuItemImage.create(s_pathB1, s_pathB2, this, this.onBackCallback);
|
||||
var item2 = cc.MenuItemImage.create(s_pathR1, s_pathR2, this, this.onRestartCallback);
|
||||
var item3 = cc.MenuItemImage.create(s_pathF1, s_pathF2, this, this.onNextCallback);
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3);
|
||||
|
||||
menu.setPosition(cc.p(0,0));
|
||||
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));
|
||||
|
||||
this.addChild(menu, 1);
|
||||
},
|
||||
|
||||
onRestartCallback:function (sender) {
|
||||
var s = new LayerTestScene();
|
||||
s.addChild(restartLayerTest());
|
||||
director.replaceScene(s);
|
||||
|
||||
},
|
||||
onNextCallback:function (sender) {
|
||||
var s = new LayerTestScene();
|
||||
s.addChild(nextLayerTest());
|
||||
director.replaceScene(s);
|
||||
|
||||
},
|
||||
onBackCallback:function (sender) {
|
||||
var s = new LayerTestScene();
|
||||
s.addChild(previousLayerTest());
|
||||
director.replaceScene(s);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// LayerTest1
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var LayerTest1 = LayerTest.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var t = cc.config.deviceType;
|
||||
if( t == 'browser' ) {
|
||||
this.setTouchEnabled(true);
|
||||
// this.setKeyboardEnabled(true);
|
||||
} else if( t == 'desktop' ) {
|
||||
this.setMouseEnabled(true);
|
||||
} else if( t == 'mobile' ) {
|
||||
this.setTouchEnabled(true);
|
||||
}
|
||||
|
||||
var s = director.getWinSize();
|
||||
var layer = cc.LayerColor.create(cc.c4b(255, 0, 0, 128), 200, 200);
|
||||
|
||||
layer.ignoreAnchorPointForPosition(false);
|
||||
layer.setPosition(cc.p(s.width / 2, s.height / 2));
|
||||
this.addChild(layer, 1, cc.TAG_LAYER);
|
||||
},
|
||||
title:function () {
|
||||
return "ColorLayer resize (tap & move)";
|
||||
},
|
||||
|
||||
updateSize:function (location) {
|
||||
var newSize = cc.size(Math.abs(location.x - winSize.width / 2) * 2, Math.abs(location.y - winSize.height / 2) * 2);
|
||||
var l = this.getChildByTag(cc.TAG_LAYER);
|
||||
|
||||
l.setContentSize(newSize);
|
||||
},
|
||||
|
||||
// events
|
||||
onMouseDragged : function( event ) {
|
||||
var location = event.getLocation();
|
||||
this.updateSize(location);
|
||||
return true;
|
||||
},
|
||||
onTouchesMoved:function (touches, event) {
|
||||
this.updateSize( touches[0].getLocation() );
|
||||
}
|
||||
});
|
||||
|
||||
var IgnoreAnchorpointTest1 = LayerTest.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
//create layer
|
||||
var ws = director.getWinSize();
|
||||
var layer1 = cc.LayerColor.create(cc.c4b(255, 100, 100, 128), ws.width / 2, ws.height / 2);
|
||||
layer1.ignoreAnchorPointForPosition(true);
|
||||
var layer2 = cc.LayerColor.create(cc.c4b(100, 255, 100, 128), ws.width / 4, ws.height / 4);
|
||||
layer2.ignoreAnchorPointForPosition(true);
|
||||
layer1.addChild(layer2);
|
||||
layer1.setPosition(ws.width / 2, ws.height / 2);
|
||||
this.addChild(layer1);
|
||||
},
|
||||
title:function () {
|
||||
return "ignore Anchorpoint Test";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "red:true green:true";
|
||||
}
|
||||
});
|
||||
var IgnoreAnchorpointTest2 = LayerTest.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
//create layer
|
||||
var ws = director.getWinSize();
|
||||
var layer1 = cc.LayerColor.create(cc.c4b(255, 100, 100, 128), ws.width / 2, ws.height / 2);
|
||||
layer1.ignoreAnchorPointForPosition(true);
|
||||
var layer2 = cc.LayerColor.create(cc.c4b(100, 255, 100, 128), ws.width / 4, ws.height / 4);
|
||||
layer2.ignoreAnchorPointForPosition(false);
|
||||
layer1.addChild(layer2);
|
||||
layer1.setPosition(ws.width / 2, ws.height / 2);
|
||||
this.addChild(layer1);
|
||||
},
|
||||
title:function () {
|
||||
return "ignore Anchorpoint Test";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "red:true green:false";
|
||||
}
|
||||
});
|
||||
var IgnoreAnchorpointTest3 = LayerTest.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
//create layer
|
||||
var ws = director.getWinSize();
|
||||
var layer1 = cc.LayerColor.create(cc.c4b(255, 100, 100, 128), ws.width / 2, ws.height / 2);
|
||||
layer1.ignoreAnchorPointForPosition(false);
|
||||
var layer2 = cc.LayerColor.create(cc.c4b(100, 255, 100, 128), ws.width / 4, ws.height / 4);
|
||||
layer2.ignoreAnchorPointForPosition(false);
|
||||
layer1.addChild(layer2);
|
||||
layer1.setPosition(ws.width / 2, ws.height / 2);
|
||||
this.addChild(layer1);
|
||||
},
|
||||
title:function () {
|
||||
return "ignore Anchorpoint Test";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "red:false green:false";
|
||||
}
|
||||
});
|
||||
var IgnoreAnchorpointTest4 = LayerTest.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
//create layer
|
||||
var ws = director.getWinSize();
|
||||
var layer1 = cc.LayerColor.create(cc.c4b(255, 100, 100, 128), ws.width / 2, ws.height / 2);
|
||||
layer1.ignoreAnchorPointForPosition(false);
|
||||
var layer2 = cc.LayerColor.create(cc.c4b(100, 255, 100, 128), ws.width / 4, ws.height / 4);
|
||||
layer2.ignoreAnchorPointForPosition(true);
|
||||
layer1.addChild(layer2);
|
||||
layer1.setPosition(ws.width / 2, ws.height / 2);
|
||||
this.addChild(layer1);
|
||||
},
|
||||
title:function () {
|
||||
return "ignore Anchorpoint Test";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "red:false green:true";
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// LayerTest2
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var LayerTest2 = LayerTest.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var s = director.getWinSize();
|
||||
var layer1 = cc.LayerColor.create(cc.c4b(255, 255, 0, 80), 100, 300);
|
||||
layer1.setPosition(cc.p(s.width / 3, s.height / 2));
|
||||
layer1.ignoreAnchorPointForPosition(false);
|
||||
this.addChild(layer1, 1);
|
||||
|
||||
var layer2 = cc.LayerColor.create(cc.c4b(0, 0, 255, 255), 100, 300);
|
||||
layer2.setPosition(cc.p((s.width / 3) * 2, s.height / 2));
|
||||
layer2.ignoreAnchorPointForPosition(false);
|
||||
this.addChild(layer2, 1);
|
||||
|
||||
var actionTint = cc.TintBy.create(2, -255, -127, 0);
|
||||
var actionTintBack = actionTint.reverse();
|
||||
var seq1 = cc.Sequence.create(actionTint, actionTintBack);
|
||||
layer1.runAction(seq1);
|
||||
|
||||
var actionFade = cc.FadeOut.create(2.0);
|
||||
var actionFadeBack = actionFade.reverse();
|
||||
var seq2 = cc.Sequence.create(actionFade, actionFadeBack);
|
||||
layer2.runAction(seq2);
|
||||
},
|
||||
title:function () {
|
||||
return "ColorLayer: fade and tint";
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// LayerTestBlend
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var LayerTestBlend = LayerTest.extend({
|
||||
_blend:true,
|
||||
|
||||
init:function () {
|
||||
this._super();
|
||||
var layer1 = cc.LayerColor.create(cc.c4b(255, 255, 255, 80));
|
||||
|
||||
var sister1 = cc.Sprite.create(s_pathSister1);
|
||||
var sister2 = cc.Sprite.create(s_pathSister2);
|
||||
|
||||
this.addChild(sister1);
|
||||
this.addChild(sister2);
|
||||
this.addChild(layer1, 100, cc.TAG_LAYER);
|
||||
|
||||
sister1.setPosition(cc.p(160, winSize.height / 2));
|
||||
sister2.setPosition(cc.p(320, winSize.height / 2));
|
||||
|
||||
this.schedule(this.onNewBlend, 1.0);
|
||||
this._blend = true;
|
||||
},
|
||||
onNewBlend:function (dt) {
|
||||
var layer = this.getChildByTag(cc.TAG_LAYER);
|
||||
|
||||
var src;
|
||||
var dst;
|
||||
|
||||
if (this._blend) {
|
||||
src = gl.SRC_ALPHA;
|
||||
dst = gl.ONE_MINUS_SRC_ALPHA;
|
||||
} else {
|
||||
src = gl.ONE_MINUS_DST_COLOR;
|
||||
dst = gl.ZERO;
|
||||
}
|
||||
layer.setBlendFunc( src, dst );
|
||||
this._blend = ! this._blend;
|
||||
},
|
||||
title:function () {
|
||||
return "ColorLayer: blend";
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// LayerGradient
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var LayerGradient = LayerTest.extend({
|
||||
init:function () {
|
||||
this._super();
|
||||
var layer1 = cc.LayerGradient.create(cc.c4b(255, 0, 0, 255), cc.c4b(0, 255, 0, 255), cc.p(0.9, 0.9));
|
||||
this.addChild(layer1, 0, cc.TAG_LAYER);
|
||||
|
||||
var t = cc.config.deviceType;
|
||||
if( t == 'browser' ) {
|
||||
this.setTouchEnabled(true);
|
||||
// this.setKeyboardEnabled(true);
|
||||
} else if( t == 'desktop' ) {
|
||||
this.setMouseEnabled(true);
|
||||
} else if( t == 'mobile' ) {
|
||||
this.setTouchEnabled(true);
|
||||
}
|
||||
|
||||
var label1 = cc.LabelTTF.create("Compressed Interpolation: Enabled", "Marker Felt", 26);
|
||||
var label2 = cc.LabelTTF.create("Compressed Interpolation: Disabled", "Marker Felt", 26);
|
||||
var item1 = cc.MenuItemLabel.create(label1);
|
||||
var item2 = cc.MenuItemLabel.create(label2);
|
||||
var item = cc.MenuItemToggle.create(item1, item2, this, this.onToggleItem);
|
||||
|
||||
var menu = cc.Menu.create(item);
|
||||
this.addChild(menu);
|
||||
menu.setPosition(cc.p(winSize.width / 2, 100) );
|
||||
},
|
||||
|
||||
updateGradient:function(pos) {
|
||||
var diff = cc.pSub(cc.p(winSize.width / 2, winSize.height / 2), pos);
|
||||
diff = cc.pNormalize(diff);
|
||||
|
||||
var gradient = this.getChildByTag(1);
|
||||
gradient.setVector(diff);
|
||||
},
|
||||
onTouchesMoved:function (touches, event) {
|
||||
var start = touches[0].getLocation();
|
||||
this.updateGradient(start);
|
||||
},
|
||||
onMouseDragged : function( event ) {
|
||||
var location = event.getLocation();
|
||||
this.updateGradient(location);
|
||||
return true;
|
||||
},
|
||||
onToggleItem:function (sender) {
|
||||
var gradient = this.getChildByTag(cc.TAG_LAYER);
|
||||
gradient.setCompressedInterpolation(!gradient.isCompressedInterpolation());
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "LayerGradient";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "Touch the screen and move your finger";
|
||||
}
|
||||
});
|
||||
|
||||
var arrayOfLayerTest = [
|
||||
LayerTest1,
|
||||
LayerTest2,
|
||||
LayerTestBlend,
|
||||
LayerGradient,
|
||||
IgnoreAnchorpointTest1,
|
||||
IgnoreAnchorpointTest2,
|
||||
IgnoreAnchorpointTest3,
|
||||
IgnoreAnchorpointTest4
|
||||
];
|
||||
|
||||
var nextLayerTest = function () {
|
||||
sceneIdx++;
|
||||
sceneIdx = sceneIdx % arrayOfLayerTest.length;
|
||||
|
||||
return new arrayOfLayerTest[sceneIdx]();
|
||||
};
|
||||
var previousLayerTest = function () {
|
||||
sceneIdx--;
|
||||
if (sceneIdx < 0)
|
||||
sceneIdx += arrayOfLayerTest.length;
|
||||
|
||||
return new arrayOfLayerTest[sceneIdx]();
|
||||
};
|
||||
var restartLayerTest = function () {
|
||||
return new arrayOfLayerTest[sceneIdx]();
|
||||
};
|
|
@ -0,0 +1,417 @@
|
|||
/****************************************************************************
|
||||
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_MENU = 77771;
|
||||
var TAG_MENU0 = 77770;
|
||||
var TAG_MENU1 = 77771;
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// LayerMainMenu
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var LayerMainMenu = cc.Layer.extend({
|
||||
ctor:function() {
|
||||
cc.associateWithNative( this, cc.Layer );
|
||||
this.init();
|
||||
},
|
||||
init:function () {
|
||||
this._super();
|
||||
cc.MenuItemFont.setFontSize(30);
|
||||
cc.MenuItemFont.setFontName("Courier New");
|
||||
|
||||
var t = cc.config.deviceType;
|
||||
if( t == 'browser' ) {
|
||||
this.setTouchEnabled(true);
|
||||
// this.setKeyboardEnabled(true);
|
||||
} else if( t == 'desktop' ) {
|
||||
this.setMouseEnabled(true);
|
||||
} else if( t == 'mobile' ) {
|
||||
this.setTouchEnabled(true);
|
||||
}
|
||||
|
||||
// Font Item
|
||||
|
||||
var spriteNormal = cc.Sprite.create(s_menuItem, cc.rect(0, 23 * 2, 115, 23));
|
||||
var spriteSelected = cc.Sprite.create(s_menuItem, cc.rect(0, 23, 115, 23));
|
||||
var spriteDisabled = cc.Sprite.create(s_menuItem, cc.rect(0, 0, 115, 23));
|
||||
|
||||
var item1 = cc.MenuItemSprite.create(spriteNormal, spriteSelected, spriteDisabled, this, this.onMenuCallback);
|
||||
|
||||
// Image Item
|
||||
var item2 = cc.MenuItemImage.create(s_sendScore, s_pressSendScore, this, this.onMenuCallback2);
|
||||
|
||||
// Label Item (LabelAtlas)
|
||||
var labelAtlas = cc.LabelAtlas.create("0123456789", s_fpsImages, 16, 24, '.'.charCodeAt(0));
|
||||
var item3 = cc.MenuItemLabel.create(labelAtlas, this, this.onMenuCallbackDisabled);
|
||||
item3.setDisabledColor(cc.c3b(32, 32, 64));
|
||||
item3.setColor(cc.c3b(200, 200, 255));
|
||||
|
||||
// Font Item
|
||||
var item4 = cc.MenuItemFont.create("I toggle enable items", this, this.onMenuCallbackEnabled);
|
||||
|
||||
item4.setFontSize(20);
|
||||
cc.MenuItemFont.setFontName("Marker Felt");
|
||||
|
||||
// Label Item (CCLabelBMFont)
|
||||
var label = cc.LabelBMFont.create("configuration", s_bitmapFontTest3_fnt);
|
||||
var item5 = cc.MenuItemLabel.create(label, this, this.onMenuCallbackConfig);
|
||||
|
||||
// Testing issue #500
|
||||
item5.setScale(0.8);
|
||||
|
||||
// Font Item
|
||||
var item6 = cc.MenuItemFont.create("Quit", this, this.onQuit);
|
||||
|
||||
var color_action = cc.TintBy.create(0.5, 0, -255, -255);
|
||||
var color_back = color_action.reverse();
|
||||
var seq = cc.Sequence.create(color_action, color_back);
|
||||
item6.runAction(cc.RepeatForever.create(seq));
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3, item4, item5, item6);
|
||||
menu.alignItemsVertically();
|
||||
|
||||
// elastic effect
|
||||
var s = director.getWinSize();
|
||||
|
||||
var child;
|
||||
var array = menu.getChildren();
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
if (array[i] === null)
|
||||
break;
|
||||
|
||||
child = array[i];
|
||||
|
||||
var dstPoint = child.getPosition();
|
||||
var offset = (s.width / 2 + 50);
|
||||
if (i % 2 === 0)
|
||||
offset = -offset;
|
||||
|
||||
child.setPosition(cc.p(dstPoint.x + offset, dstPoint.y));
|
||||
child.runAction(
|
||||
cc.EaseElasticOut.create(cc.MoveBy.create(2, cc.p(dstPoint.x - offset, 0)), 0.35)
|
||||
);
|
||||
}
|
||||
this._disabledItem = item3;
|
||||
this._disabledItem.setEnabled(false);
|
||||
|
||||
this.addChild(menu);
|
||||
},
|
||||
registerWithTouchDispatcher:function () {
|
||||
director.getTouchDispatcher().addTargetedDelegate(this, cc.MENU_HANDLER_PRIORITY + 1, true);
|
||||
},
|
||||
onTouchBegan:function () {
|
||||
return true;
|
||||
},
|
||||
onMenuCallback:function (sender) {
|
||||
var scene = cc.Scene.create();
|
||||
var layer = new MenuLayer2();
|
||||
scene.addChild( layer );
|
||||
director.pushScene( scene );
|
||||
},
|
||||
onMenuCallbackConfig:function (sender) {
|
||||
var scene = cc.Scene.create();
|
||||
var layer = new MenuLayer4();
|
||||
scene.addChild( layer );
|
||||
director.pushScene( scene );
|
||||
},
|
||||
onAllowTouches:function (dt) {
|
||||
director.getTouchDispatcher().setPriority(cc.MENU_HANDLER_PRIORITY + 1, this);
|
||||
this.unscheduleAllSelectors();
|
||||
cc.log("Touches allowed again!");
|
||||
},
|
||||
onMenuCallbackDisabled:function (sender) {
|
||||
// hijack all touch events for 5 seconds
|
||||
director.getTouchDispatcher().setPriority(cc.MENU_HANDLER_PRIORITY - 1, this);
|
||||
this.schedule(this.allowTouches, 5.0);
|
||||
cc.log("TOUCHES DISABLED FOR 5 SECONDS");
|
||||
},
|
||||
onMenuCallbackEnabled:function (sender) {
|
||||
this._disabledItem.setEnabled(!this._disabledItem.isEnabled());
|
||||
},
|
||||
onMenuCallback2:function (sender) {
|
||||
var scene = cc.Scene.create();
|
||||
var layer = new MenuLayer3();
|
||||
scene.addChild( layer );
|
||||
director.pushScene( scene );
|
||||
},
|
||||
onQuit:function (sender) {
|
||||
cc.log("Quit called");
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// MenuLayer2
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var MenuLayer2 = cc.Layer.extend({
|
||||
ctor:function() {
|
||||
cc.associateWithNative( this, cc.Layer );
|
||||
this.init();
|
||||
},
|
||||
init:function () {
|
||||
this._super();
|
||||
for (var i = 0; i < 2; i++) {
|
||||
var item1 = cc.MenuItemImage.create(s_playNormal, s_playSelect, this, this.onMenuCallback);
|
||||
var item2 = cc.MenuItemImage.create(s_highNormal, s_highSelect, this, this.onMenuCallbackOpacity);
|
||||
var item3 = cc.MenuItemImage.create(s_aboutNormal, s_aboutSelect, this, this.onMenuCallbackAlign);
|
||||
item1.setScaleX(1.5);
|
||||
item2.setScaleX(0.5);
|
||||
item3.setScaleX(0.5);
|
||||
var menu = cc.Menu.create(item1, item2, item3);
|
||||
menu.setTag(TAG_MENU);
|
||||
this.addChild(menu, 0, 100 + i);
|
||||
this._centeredMenu = menu.getPosition();
|
||||
}
|
||||
this._alignedH = true;
|
||||
this.alignMenuH();
|
||||
},
|
||||
alignMenuH:function () {
|
||||
var p;
|
||||
for (var i = 0; i < 2; i++) {
|
||||
var menu = this.getChildByTag(100 + i);
|
||||
menu.setPosition(this._centeredMenu);
|
||||
if (i === 0) {
|
||||
menu.alignItemsHorizontally();
|
||||
p = menu.getPosition();
|
||||
menu.setPosition(cc.pAdd(p, cc.p(0, 30)));
|
||||
}
|
||||
else {
|
||||
menu.alignItemsHorizontallyWithPadding(40);
|
||||
p = menu.getPosition();
|
||||
menu.setPosition(cc.pSub(p, cc.p(0, 30)));
|
||||
}
|
||||
}
|
||||
},
|
||||
alignMenusV:function () {
|
||||
var p;
|
||||
for (var i = 0; i < 2; i++) {
|
||||
var menu = this.getChildByTag(100 + i);
|
||||
menu.setPosition(this._centeredMenu);
|
||||
if (i === 0) {
|
||||
menu.alignItemsVertically();
|
||||
p = menu.getPosition();
|
||||
menu.setPosition(cc.pAdd(p, cc.p(100, 0)));
|
||||
}
|
||||
else {
|
||||
menu.alignItemsVerticallyWithPadding(40);
|
||||
p = menu.getPosition();
|
||||
menu.setPosition(cc.pSub(p, cc.p(100, 0)));
|
||||
}
|
||||
}
|
||||
},
|
||||
// callbacks
|
||||
onMenuCallback:function (sender) {
|
||||
director.popScene();
|
||||
},
|
||||
onMenuCallbackOpacity:function (sender) {
|
||||
var menu = sender.getParent();
|
||||
var opacity = menu.getOpacity();
|
||||
if (opacity == 128)
|
||||
menu.setOpacity(255);
|
||||
else
|
||||
menu.setOpacity(128);
|
||||
},
|
||||
onMenuCallbackAlign:function (sender) {
|
||||
this._alignedH = !this._alignedH;
|
||||
if (this._alignedH)
|
||||
this.alignMenuH();
|
||||
else
|
||||
this.alignMenusV();
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// MenuLayer3
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
var MenuLayer3 = cc.Layer.extend({
|
||||
ctor:function() {
|
||||
cc.associateWithNative( this, cc.Layer );
|
||||
this.init();
|
||||
},
|
||||
init:function () {
|
||||
this._super();
|
||||
cc.MenuItemFont.setFontName("Marker Felt");
|
||||
cc.MenuItemFont.setFontSize(28);
|
||||
|
||||
var label = cc.LabelBMFont.create("Enable AtlasItem", s_bitmapFontTest3_fnt);
|
||||
var item1 = cc.MenuItemLabel.create(label, this, this.onMenuCallback2);
|
||||
var item2 = cc.MenuItemFont.create("--- Go Back ---", this, this.onMenuCallback);
|
||||
|
||||
var spriteNormal = cc.Sprite.create(s_menuItem, cc.rect(0, 23 * 2, 115, 23));
|
||||
var spriteSelected = cc.Sprite.create(s_menuItem, cc.rect(0, 23, 115, 23));
|
||||
var spriteDisabled = cc.Sprite.create(s_menuItem, cc.rect(0, 0, 115, 23));
|
||||
|
||||
|
||||
var item3 = cc.MenuItemSprite.create(spriteNormal, spriteSelected, spriteDisabled, this, this.onMenuCallback3);
|
||||
this._disabledItem = item3;
|
||||
this._disabledItem.setEnabled(false);
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3);
|
||||
menu.setPosition(cc.p(0, 0));
|
||||
|
||||
var s = director.getWinSize();
|
||||
|
||||
item1.setPosition(cc.p(s.width / 2 - 150, s.height / 2));
|
||||
item2.setPosition(cc.p(s.width / 2 - 200, s.height / 2));
|
||||
item3.setPosition(cc.p(s.width / 2, s.height / 2 - 100));
|
||||
|
||||
var jump = cc.JumpBy.create(3, cc.p(400, 0), 50, 4);
|
||||
item2.runAction(
|
||||
cc.RepeatForever.create(
|
||||
cc.Sequence.create(jump, jump.reverse())
|
||||
)
|
||||
);
|
||||
var spin1 = cc.RotateBy.create(3, 360);
|
||||
var spin2 = spin1.copy();
|
||||
var spin3 = spin1.copy();
|
||||
|
||||
item1.runAction(cc.RepeatForever.create(spin1));
|
||||
item2.runAction(cc.RepeatForever.create(spin2));
|
||||
item3.runAction(cc.RepeatForever.create(spin3));
|
||||
|
||||
this.addChild(menu);
|
||||
},
|
||||
// callbacks
|
||||
onMenuCallback:function (sender) {
|
||||
director.popScene();
|
||||
},
|
||||
onMenuCallback2:function (sender) {
|
||||
this._disabledItem.setEnabled(!this._disabledItem.isEnabled());
|
||||
this._disabledItem.stopAllActions();
|
||||
},
|
||||
onMenuCallback3:function () {
|
||||
cc.log("do something");
|
||||
}
|
||||
});
|
||||
|
||||
var MenuLayer4 = cc.Layer.extend({
|
||||
ctor:function () {
|
||||
cc.associateWithNative( this, cc.Layer );
|
||||
this.init();
|
||||
},
|
||||
init:function () {
|
||||
this._super();
|
||||
cc.MenuItemFont.setFontName("American Typewriter");
|
||||
cc.MenuItemFont.setFontSize(18);
|
||||
|
||||
var title1 = cc.MenuItemFont.create("Sound");
|
||||
title1.setEnabled(false);
|
||||
cc.MenuItemFont.setFontName("Marker Felt");
|
||||
cc.MenuItemFont.setFontSize(34);
|
||||
|
||||
// you can create a ToggleItem by passing the items
|
||||
// and later setting the callback
|
||||
var item1 = cc.MenuItemToggle.create(
|
||||
cc.MenuItemFont.create("On"),
|
||||
cc.MenuItemFont.create("Off") );
|
||||
item1.setCallback( this, this.onMenuCallback );
|
||||
|
||||
cc.MenuItemFont.setFontName("American Typewriter");
|
||||
cc.MenuItemFont.setFontSize(18);
|
||||
var title2 = cc.MenuItemFont.create("Music");
|
||||
title2.setEnabled(false);
|
||||
cc.MenuItemFont.setFontName("Marker Felt");
|
||||
cc.MenuItemFont.setFontSize(34);
|
||||
|
||||
// or you can create a ToggleItem by passing the items
|
||||
// an the callback at the last arguments.
|
||||
var item2 = cc.MenuItemToggle.create(
|
||||
cc.MenuItemFont.create("Off"),
|
||||
cc.MenuItemFont.create("33%"),
|
||||
cc.MenuItemFont.create("66%"),
|
||||
cc.MenuItemFont.create("On"),
|
||||
this,
|
||||
this.onMenuCallback
|
||||
);
|
||||
|
||||
cc.MenuItemFont.setFontName("American Typewriter");
|
||||
cc.MenuItemFont.setFontSize(18);
|
||||
var title3 = cc.MenuItemFont.create("Quality");
|
||||
title3.setEnabled(false);
|
||||
cc.MenuItemFont.setFontName("Marker Felt");
|
||||
cc.MenuItemFont.setFontSize(34);
|
||||
var item3 = cc.MenuItemToggle.create(
|
||||
cc.MenuItemFont.create("High"),
|
||||
cc.MenuItemFont.create("Low"),
|
||||
this,
|
||||
this.onMenuCallback
|
||||
);
|
||||
|
||||
cc.MenuItemFont.setFontName("American Typewriter");
|
||||
cc.MenuItemFont.setFontSize(18);
|
||||
var title4 = cc.MenuItemFont.create("Orientation");
|
||||
title4.setEnabled(false);
|
||||
cc.MenuItemFont.setFontName("Marker Felt");
|
||||
cc.MenuItemFont.setFontSize(34);
|
||||
var item4 = cc.MenuItemToggle.create(
|
||||
cc.MenuItemFont.create("Landscape Left"),
|
||||
cc.MenuItemFont.create("Landscape Right"),
|
||||
cc.MenuItemFont.create("Portrait"),
|
||||
this,
|
||||
this.onMenuCallback
|
||||
);
|
||||
|
||||
// you can change the one of the items by doing this
|
||||
item4.setSelectedIndex(2);
|
||||
|
||||
cc.MenuItemFont.setFontName("Marker Felt");
|
||||
cc.MenuItemFont.setFontSize(34);
|
||||
|
||||
var label = cc.LabelBMFont.create("go back", s_bitmapFontTest3_fnt);
|
||||
var back = cc.MenuItemLabel.create(label, this, this.onBackCallback);
|
||||
|
||||
var menu = cc.Menu.create(
|
||||
title1, title2,
|
||||
item1, item2,
|
||||
title3, title4,
|
||||
item3, item4,
|
||||
back); // 9 items.
|
||||
|
||||
menu.alignItemsInColumns(2, 2, 2, 2, 1);
|
||||
|
||||
this.addChild(menu);
|
||||
},
|
||||
onMenuCallback:function (sender) {
|
||||
cc.log("Callback called");
|
||||
},
|
||||
onBackCallback:function (sender) {
|
||||
director.popScene();
|
||||
}
|
||||
});
|
||||
|
||||
var MenuTestScene = TestScene.extend({
|
||||
runThisTest:function () {
|
||||
var mainLayer = new LayerMainMenu();
|
||||
this.addChild(mainLayer, 0);
|
||||
director.replaceScene(mainLayer);
|
||||
}
|
||||
});
|
|
@ -0,0 +1,164 @@
|
|||
/****************************************************************************
|
||||
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 touchColors = [
|
||||
cc.yellow(),
|
||||
cc.c3b(0,0,255),
|
||||
cc.c3b(0,255,0),
|
||||
cc.c3b(255,0,0),
|
||||
cc.magenta()
|
||||
];
|
||||
|
||||
var TouchPoint = cc.Node.extend({
|
||||
_touchPoint:null,
|
||||
_tonchColor:null,
|
||||
_styleStr:null,
|
||||
|
||||
ctor:function () {
|
||||
this._touchPoint = cc.p(0, 0);
|
||||
this._tonchColor = new cc.Color3B(255, 255, 255);
|
||||
this._styleStr = "rgba(" + this._tonchColor.r + "," + this._tonchColor.g + "," + this._tonchColor.b + ", 1)";
|
||||
//this.setShaderProgram(cc.ShaderCache.getInstance().programForKey(kCCShader_PositionTextureColor));
|
||||
},
|
||||
|
||||
draw:function () {
|
||||
var context = cc.renderContext;
|
||||
context.save();
|
||||
context.fillStyle = this._styleStr;
|
||||
context.strokeStyle = this._styleStr;
|
||||
context.lineWidth = "10";
|
||||
var size = this.getContentSize();
|
||||
cc.drawingUtil.drawLine(cc.p(0, this._touchPoint.y), cc.p(size.width, this._touchPoint.y));
|
||||
cc.drawingUtil.drawLine(cc.p(this._touchPoint.x, 0), cc.p(this._touchPoint.x, size.height));
|
||||
cc.drawingUtil.drawPoint(this._touchPoint, 15);
|
||||
context.restore();
|
||||
},
|
||||
|
||||
setTouchPos:function (pt) {
|
||||
this._touchPoint = pt;
|
||||
},
|
||||
|
||||
setTouchColor:function (color) {
|
||||
this._tonchColor = color;
|
||||
this._styleStr = "rgba(" + this._tonchColor.r + "," + this._tonchColor.g + "," + this._tonchColor.b + ", 1)";
|
||||
}
|
||||
});
|
||||
|
||||
TouchPoint.touchPointWithParent = function (parent) {
|
||||
var ret = new TouchPoint();
|
||||
ret.setContentSize(parent.getContentSize());
|
||||
ret.setAnchorPoint(cc.p(0, 0));
|
||||
return ret;
|
||||
};
|
||||
|
||||
var MultiTouchTestLayer = cc.Layer.extend({
|
||||
init:function () {
|
||||
if (this._super()) {
|
||||
this.setTouchEnabled(true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
registerWithTouchDispatcher:function () {
|
||||
cc.Director.getInstance().getTouchDispatcher().addStandardDelegate(this, 0);
|
||||
},
|
||||
|
||||
_savePointArr:[],
|
||||
_isPressed:false,
|
||||
onTouchesBegan:function (touches, event) {
|
||||
this._isPressed = true;
|
||||
if (!touches)
|
||||
return;
|
||||
|
||||
this._clearSavePointArr();
|
||||
|
||||
for (var i = 0; i < touches.length; i++) {
|
||||
var touch = touches[i];
|
||||
var touchPoint = TouchPoint.touchPointWithParent(this);
|
||||
var location = touch.getLocation();
|
||||
|
||||
touchPoint.setTouchPos(location);
|
||||
touchPoint.setTouchColor(touchColors[i]);
|
||||
|
||||
this.addChild(touchPoint);
|
||||
this._savePointArr.push(touchPoint);
|
||||
}
|
||||
},
|
||||
|
||||
_clearSavePointArr:function () {
|
||||
for (var i = 0; i < this._savePointArr.length; i++) {
|
||||
this._savePointArr[i].removeFromParentAndCleanup(true);
|
||||
}
|
||||
},
|
||||
|
||||
onTouchesMoved:function (touches, event) {
|
||||
this._clearSavePointArr();
|
||||
if (!cc.Browser.isMobile) {
|
||||
if (!this._isPressed) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < touches.length; i++) {
|
||||
var touch = touches[i];
|
||||
var touchPoint = TouchPoint.touchPointWithParent(this);
|
||||
var location = touch.getLocation();
|
||||
|
||||
touchPoint.setTouchPos(location);
|
||||
touchPoint.setTouchColor(touchColors[i]);
|
||||
|
||||
this.addChild(touchPoint);
|
||||
this._savePointArr.push(touchPoint);
|
||||
}
|
||||
},
|
||||
|
||||
onTouchesEnded:function (touches, event) {
|
||||
this._isPressed = false;
|
||||
this._clearSavePointArr();
|
||||
},
|
||||
|
||||
onTouchesCancelled:function (touches, event) {
|
||||
this.onTouchesEnded(touches, event);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
MultiTouchTestLayer.create = function () {
|
||||
var ret = new MultiTouchTestLayer();
|
||||
if (ret && ret.init()) {
|
||||
return ret;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
var MultiTouchTestScene = TestScene.extend({
|
||||
runThisTest:function () {
|
||||
var layer = MultiTouchTestLayer.create();
|
||||
this.addChild(layer, 0);
|
||||
cc.Director.getInstance().replaceScene(this);
|
||||
}
|
||||
});
|
|
@ -0,0 +1,100 @@
|
|||
/****************************************************************************
|
||||
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 PADDLE_STATE_GRABBED = 0;
|
||||
var PADDLE_STATE_UNGRABBED = 1;
|
||||
|
||||
var Paddle = cc.Sprite.extend({
|
||||
_state:PADDLE_STATE_UNGRABBED,
|
||||
_rect:null,
|
||||
|
||||
rect:function () {
|
||||
return cc.rect(-this._rect.size.width / 2, -this._rect.size.height / 2, this._rect.size.width, this._rect.size.height);
|
||||
},
|
||||
initWithTexture:function (aTexture) {
|
||||
if (this._super(aTexture)) {
|
||||
this._state = PADDLE_STATE_UNGRABBED;
|
||||
}
|
||||
if (aTexture instanceof cc.Texture2D) {
|
||||
var s = aTexture.getContentSize();
|
||||
this._rect = cc.rect(0, 0, s.width, s.height);
|
||||
} else if ((aTexture instanceof HTMLImageElement) || (aTexture instanceof HTMLCanvasElement)) {
|
||||
this._rect = cc.rect(0, 0, aTexture.width, aTexture.height);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
onEnter:function () {
|
||||
cc.Director.getInstance().getTouchDispatcher().addTargetedDelegate(this, 0, true);
|
||||
this._super();
|
||||
},
|
||||
onExit:function () {
|
||||
cc.Director.getInstance().getTouchDispatcher().removeDelegate(this);
|
||||
this._super();
|
||||
},
|
||||
containsTouchLocation:function (touch) {
|
||||
var getPoint = touch.getLocation();
|
||||
var myRect = this.rect();
|
||||
|
||||
myRect.origin.x += this.getPosition().x;
|
||||
myRect.origin.y += this.getPosition().y;
|
||||
return cc.Rect.CCRectContainsPoint(myRect, getPoint);//this.convertTouchToNodeSpaceAR(touch));
|
||||
},
|
||||
|
||||
onTouchBegan:function (touch, event) {
|
||||
if (this._state != PADDLE_STATE_UNGRABBED) return false;
|
||||
if (!this.containsTouchLocation(touch)) return false;
|
||||
|
||||
this._state = PADDLE_STATE_GRABBED;
|
||||
return true;
|
||||
},
|
||||
onTouchMoved:function (touch, event) {
|
||||
// If it weren't for the TouchDispatcher, you would need to keep a reference
|
||||
// to the touch from touchBegan and check that the current touch is the same
|
||||
// as that one.
|
||||
// Actually, it would be even more complicated since in the Cocos dispatcher
|
||||
// you get CCSets instead of 1 UITouch, so you'd need to loop through the set
|
||||
// in each touchXXX method.
|
||||
cc.Assert(this._state == PADDLE_STATE_GRABBED, "Paddle - Unexpected state!");
|
||||
|
||||
var touchPoint = touch.getLocation();
|
||||
//touchPoint = cc.Director.getInstance().convertToGL( touchPoint );
|
||||
|
||||
this.setPosition(cc.p(touchPoint.x, this.getPosition().y));
|
||||
},
|
||||
onTouchEnded:function (touch, event) {
|
||||
cc.Assert(this._state == PADDLE_STATE_GRABBED, "Paddle - Unexpected state!");
|
||||
this._state = PADDLE_STATE_UNGRABBED;
|
||||
},
|
||||
touchDelegateRetain:function () {
|
||||
},
|
||||
touchDelegateRelease:function () {
|
||||
}
|
||||
});
|
||||
Paddle.paddleWithTexture = function (aTexture) {
|
||||
var paddle = new Paddle();
|
||||
paddle.initWithTexture(aTexture);
|
||||
|
||||
return paddle;
|
||||
};
|
|
@ -0,0 +1,274 @@
|
|||
/****************************************************************************
|
||||
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_NODE = 9960;
|
||||
var TAG_GROSSINI = 9961;
|
||||
|
||||
var sceneIdx = -1;
|
||||
|
||||
var MAX_LAYER = 2;
|
||||
|
||||
|
||||
function createParallaxTestLayer(index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return new Parallax1();
|
||||
case 1:
|
||||
return new Parallax2();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function nextParallaxAction() {
|
||||
sceneIdx++;
|
||||
sceneIdx = sceneIdx % MAX_LAYER;
|
||||
|
||||
var layer = createParallaxTestLayer(sceneIdx);
|
||||
return layer;
|
||||
}
|
||||
|
||||
function backParallaxAction() {
|
||||
sceneIdx--;
|
||||
var total = MAX_LAYER;
|
||||
if (sceneIdx < 0)
|
||||
sceneIdx += total;
|
||||
|
||||
var layer = createParallaxTestLayer(sceneIdx);
|
||||
return layer;
|
||||
}
|
||||
|
||||
function restartParallaxAction() {
|
||||
var layer = createParallaxTestLayer(sceneIdx);
|
||||
return layer;
|
||||
}
|
||||
ParallaxDemo = cc.Layer.extend({
|
||||
|
||||
_atlas:null,
|
||||
|
||||
ctor:function () {
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "No title";
|
||||
},
|
||||
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 28);
|
||||
this.addChild(label, 1);
|
||||
label.setPosition(cc.p(s.width / 2, s.height - 50));
|
||||
|
||||
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);
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3, null);
|
||||
|
||||
menu.setPosition(cc.p(0,0));
|
||||
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));
|
||||
|
||||
this.addChild(menu, 1);
|
||||
|
||||
},
|
||||
|
||||
restartCallback:function (sender) {
|
||||
var s = new ParallaxTestScene();
|
||||
s.addChild(restartParallaxAction());
|
||||
|
||||
cc.Director.getInstance().replaceScene(s);
|
||||
},
|
||||
|
||||
nextCallback:function (sender) {
|
||||
var s = new ParallaxTestScene();
|
||||
s.addChild(nextParallaxAction());
|
||||
cc.Director.getInstance().replaceScene(s);
|
||||
|
||||
},
|
||||
|
||||
backCallback:function (sender) {
|
||||
var s = new ParallaxTestScene();
|
||||
s.addChild(backParallaxAction());
|
||||
cc.Director.getInstance().replaceScene(s);
|
||||
}
|
||||
});
|
||||
|
||||
Parallax1 = ParallaxDemo.extend({
|
||||
|
||||
_root:null,
|
||||
_target:null,
|
||||
_streak:null,
|
||||
|
||||
|
||||
ctor:function () {
|
||||
// Top Layer, a simple image
|
||||
var cocosImage = cc.Sprite.create(s_power);
|
||||
// scale the image (optional)
|
||||
cocosImage.setScale(0.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(s_tilesPng, s_levelMapTga, 16, 16);
|
||||
var tilemap = cc.TMXTiledMap.create("res/TileMaps/orthogonal-test2.tmx");
|
||||
|
||||
|
||||
// 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(s_back);
|
||||
// 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, 0));
|
||||
|
||||
// top image is moved at a ratio of 3.0x, 2.5y
|
||||
voidNode.addChild(cocosImage, 2, cc.p(3.0, 2.5), cc.p(0, 0));
|
||||
|
||||
|
||||
// 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, 100));
|
||||
var goDown = goUp.reverse();
|
||||
var go = cc.MoveBy.create(8, cc.p(200, 0));
|
||||
var goBack = go.reverse();
|
||||
var seq = cc.Sequence.create(goUp, go, goDown, goBack, null);
|
||||
voidNode.runAction((cc.RepeatForever.create(seq) ));
|
||||
|
||||
this.addChild(voidNode);
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "Parallax: parent and 3 children";
|
||||
}
|
||||
});
|
||||
|
||||
Parallax2 = ParallaxDemo.extend({
|
||||
|
||||
_root:null,
|
||||
_target:null,
|
||||
_streak:null,
|
||||
|
||||
|
||||
ctor:function () {
|
||||
this.setTouchEnabled(true);
|
||||
|
||||
// Top Layer, a simple image
|
||||
var cocosImage = cc.Sprite.create(s_power);
|
||||
// scale the image (optional)
|
||||
cocosImage.setScale(0.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(s_tilesPng, s_levelMapTga, 16, 16);
|
||||
var tilemap = cc.TMXTiledMap.create("res/TileMaps/orthogonal-test2.tmx");
|
||||
|
||||
// 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(s_back);
|
||||
// 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 1.0, 1.0y
|
||||
voidNode.addChild(tilemap, 1, cc.p(1.0, 1.0), cc.p(0, 0));
|
||||
|
||||
// top image is moved at a ratio of 3.0x, 2.5y
|
||||
voidNode.addChild(cocosImage, 2, cc.p(3.0, 2.5), cc.p(0, 0));
|
||||
this.addChild(voidNode, 0, TAG_NODE);
|
||||
|
||||
},
|
||||
|
||||
registerWithTouchDispatcher:function () {
|
||||
cc.Director.getInstance().getTouchDispatcher().addTargetedDelegate(this, 0, true);
|
||||
},
|
||||
onTouchBegan:function (touch, event) {
|
||||
return true;
|
||||
},
|
||||
|
||||
onTouchMoved:function (touch, event) {
|
||||
var node = this.getChildByTag(TAG_NODE);
|
||||
var currentPos = node.getPosition();
|
||||
node.setPosition(cc.pAdd(currentPos, touch.getDelta() ));
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "Parallax: drag screen";
|
||||
}
|
||||
});
|
||||
|
||||
ParallaxTestScene = TestScene.extend({
|
||||
|
||||
runThisTest:function () {
|
||||
sceneIdx = -1;
|
||||
MAX_LAYER = 2;
|
||||
var layer = nextParallaxAction();
|
||||
|
||||
this.addChild(layer);
|
||||
cc.Director.getInstance().replaceScene(this);
|
||||
}
|
||||
});
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,510 @@
|
|||
/****************************************************************************
|
||||
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,
|
||||
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, 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 / 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(Math.random() * s.width, Math.random() * 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("res/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(Math.random() * s.width, Math.random() * 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("res/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);
|
||||
}
|
|
@ -0,0 +1,515 @@
|
|||
/****************************************************************************
|
||||
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);
|
||||
}
|
|
@ -0,0 +1,560 @@
|
|||
/****************************************************************************
|
||||
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_2D_PIXEL_FORMAT_RGBA8888);
|
||||
|
||||
var sprite = null;
|
||||
switch (this._subtestNumber) {
|
||||
case 1:
|
||||
{
|
||||
sprite = cc.Sprite.create("res/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(Math.random() * 14) + 1;
|
||||
idx = idx < 10 ? "0" + idx : idx.toString();
|
||||
var str = "res/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 | (Math.random() * 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 | (Math.random() * 64);
|
||||
|
||||
y = parseInt(r / 8);
|
||||
x = parseInt(r % 8);
|
||||
|
||||
var str = "res/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 | (Math.random() * 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_2D_PIXEL_FORMAT_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
|
||||
var mgr = cc.TextureCache.getInstance();
|
||||
// [mgr removeAllTextures];
|
||||
mgr.removeTexture(mgr.addImage("res/Images/grossinis_sister1.png"));
|
||||
mgr.removeTexture(mgr.addImage("res/Images/grossini_dance_atlas.png"));
|
||||
mgr.removeTexture(mgr.addImage("res/Images/spritesheet1.png"));
|
||||
|
||||
switch (this._subtestNumber) {
|
||||
case 1:
|
||||
case 4:
|
||||
case 7:
|
||||
break;
|
||||
///
|
||||
case 2:
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_2D_PIXEL_FORMAT_RGBA8888);
|
||||
this._batchNode = cc.SpriteBatchNode.create("res/Images/grossinis_sister1.png", 100);
|
||||
p.addChild(this._batchNode, 0);
|
||||
break;
|
||||
case 3:
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_2D_PIXEL_FORMAT_RGBA4444);
|
||||
this._batchNode = cc.SpriteBatchNode.create("res/Images/grossinis_sister1.png", 100);
|
||||
p.addChild(this._batchNode, 0);
|
||||
break;
|
||||
|
||||
///
|
||||
case 5:
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_2D_PIXEL_FORMAT_RGBA8888);
|
||||
this._batchNode = cc.SpriteBatchNode.create("res/Images/grossini_dance_atlas.png", 100);
|
||||
p.addChild(this._batchNode, 0);
|
||||
break;
|
||||
case 6:
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_2D_PIXEL_FORMAT_RGBA4444);
|
||||
this._batchNode = cc.SpriteBatchNode.create("res/Images/grossini_dance_atlas.png", 100);
|
||||
p.addChild(this._batchNode, 0);
|
||||
break;
|
||||
|
||||
///
|
||||
case 8:
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_2D_PIXEL_FORMAT_RGBA8888);
|
||||
this._batchNode = cc.SpriteBatchNode.create("res/Images/spritesheet1.png", 100);
|
||||
p.addChild(this._batchNode, 0);
|
||||
break;
|
||||
case 9:
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_2D_PIXEL_FORMAT_RGBA4444);
|
||||
this._batchNode = cc.SpriteBatchNode.create("res/Images/spritesheet1.png", 100);
|
||||
p.addChild(this._batchNode, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
cc.Texture2D.setDefaultAlphaPixelFormat(cc.TEXTURE_2D_PIXEL_FORMAT_DEFAULT);
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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,
|
||||
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, null);
|
||||
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(null);
|
||||
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 * Math.random());
|
||||
var rot_back = rot.reverse();
|
||||
var permanentRotation = cc.RepeatForever.create(cc.Sequence.create(rot, rot_back, null));
|
||||
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._actionOneTwo(grow, grow.reverse()));
|
||||
sprite.runAction(permanentScaleLoop);
|
||||
}
|
||||
|
||||
function performanceActions20(sprite) {
|
||||
var size = cc.Director.getInstance().getWinSize();
|
||||
if (Math.random() < 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 * Math.random());
|
||||
var rot_back = rot.reverse();
|
||||
var permanentRotation = cc.RepeatForever.create(cc.Sequence.create(rot, rot_back, null));
|
||||
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._actionOneTwo(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(Math.random() * 360);
|
||||
sprite.setScale(Math.random() * 2);
|
||||
}
|
||||
|
||||
function performancePosition(sprite) {
|
||||
var size = cc.Director.getInstance().getWinSize();
|
||||
sprite.setPosition(cc.p(parseInt(Math.random() * size.width), parseInt(Math.random() * size.height)));
|
||||
}
|
||||
|
||||
function performanceout20(sprite) {
|
||||
var size = cc.Director.getInstance().getWinSize();
|
||||
|
||||
if (Math.random() < 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(Math.random() * 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() {
|
||||
var scene = new SpritePerformTest1;
|
||||
scene.initWithSubTest(1, 50);
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
}
|
|
@ -0,0 +1,160 @@
|
|||
/****************************************************************************
|
||||
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 ITEM_TAG_BASIC = 1000;
|
||||
var nCurCase = 0;
|
||||
|
||||
var PerformanceTests = [
|
||||
"PerformanceNodeChildrenTest",
|
||||
"PerformanceParticleTest",
|
||||
"PerformanceSpriteTest",
|
||||
"PerformanceTextureTest",
|
||||
"PerformanceTouchesTest"
|
||||
];
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// PerformanceMainLayer
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
var PerformanceMainLayer = cc.Layer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
var menu = cc.Menu.create(null);
|
||||
menu.setPosition(cc.p(0,0));
|
||||
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:
|
||||
runNodeChildrenTest();
|
||||
break;
|
||||
case 1:
|
||||
runParticleTest();
|
||||
break;
|
||||
case 2:
|
||||
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;
|
||||
},
|
||||
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, null);
|
||||
menu.setPosition(cc.p(0,0));
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
|
@ -0,0 +1,171 @@
|
|||
/****************************************************************************
|
||||
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;
|
||||
}
|
|
@ -0,0 +1,162 @@
|
|||
/****************************************************************************
|
||||
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);
|
||||
}
|
|
@ -0,0 +1,419 @@
|
|||
/****************************************************************************
|
||||
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 sceneIdx_Progress = -1;
|
||||
var MAX_LAYER_Progress = 7;
|
||||
|
||||
var nextProgressAction = function () {
|
||||
sceneIdx_Progress++;
|
||||
sceneIdx_Progress = sceneIdx_Progress % MAX_LAYER_Progress;
|
||||
|
||||
return createLayer(sceneIdx_Progress);
|
||||
};
|
||||
var backProgressAction = function () {
|
||||
sceneIdx_Progress--;
|
||||
if (sceneIdx_Progress < 0)
|
||||
sceneIdx_Progress += MAX_LAYER_Progress;
|
||||
|
||||
return createLayer(sceneIdx_Progress);
|
||||
};
|
||||
var restartProgressAction = function () {
|
||||
return createLayer(sceneIdx_Progress);
|
||||
};
|
||||
|
||||
var createLayer = function (index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return new SpriteProgressToRadial();
|
||||
case 1:
|
||||
return new SpriteProgressToHorizontal();
|
||||
case 2:
|
||||
return new SpriteProgressToVertical();
|
||||
case 3:
|
||||
return new SpriteProgressToRadialMidpointChanged();
|
||||
case 4:
|
||||
return new SpriteProgressBarVarious();
|
||||
case 5:
|
||||
return new SpriteProgressBarTintAndFade();
|
||||
case 6:
|
||||
return new SpriteProgressWithSpriteFrame();
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
var SpriteDemo = cc.Layer.extend({
|
||||
ctor:function () {
|
||||
this._super();
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "ProgressActionsTest";
|
||||
},
|
||||
|
||||
subtitle:function () {
|
||||
return "";
|
||||
},
|
||||
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var winSize = cc.Director.getInstance().getWinSize();
|
||||
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 18);
|
||||
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", 22);
|
||||
this.addChild(l, 1);
|
||||
l.setPosition(cc.p(winSize.width / 2, winSize.height - 80));
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3);
|
||||
|
||||
menu.setPosition(cc.p(0,0));
|
||||
item1.setPosition(cc.p(winSize.width / 2 - item2.getContentSize().width * 2, item2.getContentSize().height / 2));
|
||||
item2.setPosition(cc.p(winSize.width / 2, item2.getContentSize().height / 2));
|
||||
item3.setPosition(cc.p(winSize.width / 2 + item2.getContentSize().width * 2, item2.getContentSize().height / 2));
|
||||
|
||||
this.addChild(menu, 1);
|
||||
var background = cc.LayerColor.create(cc.c4b(0, 125, 0, 255));
|
||||
this.addChild(background, -10);
|
||||
},
|
||||
|
||||
restartCallback:function (sender) {
|
||||
var scene = new ProgressActionsTestScene();
|
||||
scene.addChild(restartProgressAction());
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
},
|
||||
|
||||
nextCallback:function (sender) {
|
||||
var scene = new ProgressActionsTestScene();
|
||||
scene.addChild(nextProgressAction());
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
},
|
||||
|
||||
backCallback:function (sender) {
|
||||
var scene = new ProgressActionsTestScene();
|
||||
scene.addChild(backProgressAction());
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
}
|
||||
});
|
||||
|
||||
var SpriteProgressToRadial = SpriteDemo.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
var winSize = cc.Director.getInstance().getWinSize();
|
||||
|
||||
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 = SpriteDemo.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var winSize = cc.Director.getInstance().getWinSize();
|
||||
|
||||
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 = SpriteDemo.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var winSize = cc.Director.getInstance().getWinSize();
|
||||
|
||||
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 = SpriteDemo.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var winSize = cc.Director.getInstance().getWinSize();
|
||||
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 = SpriteDemo.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
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, s.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(s.width / 2, s.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(s.width - 150, s.height / 2));
|
||||
right.runAction(cc.RepeatForever.create(to.copy()));
|
||||
},
|
||||
|
||||
subtitle:function () {
|
||||
return "ProgressTo Bar Mid";
|
||||
}
|
||||
});
|
||||
|
||||
var SpriteProgressBarTintAndFade = SpriteDemo.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var winSize = cc.Director.getInstance().getWinSize();
|
||||
|
||||
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 = SpriteDemo.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var winSize = cc.Director.getInstance().getWinSize();
|
||||
var to = cc.ProgressTo.create(6, 100);
|
||||
|
||||
cc.SpriteFrameCache.getInstance().addSpriteFrames(s_grossiniPlist);
|
||||
|
||||
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";
|
||||
}
|
||||
});
|
||||
|
||||
var ProgressActionsTestScene = TestScene.extend({
|
||||
runThisTest:function () {
|
||||
sceneIdx_Progress = -1;
|
||||
MAX_LAYER_Progress = 7;
|
||||
this.addChild(nextProgressAction());
|
||||
cc.Director.getInstance().replaceScene(this);
|
||||
}
|
||||
});
|
|
@ -0,0 +1,156 @@
|
|||
/****************************************************************************
|
||||
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 RotateWorldTestScene = TestScene.extend({
|
||||
runThisTest:function () {
|
||||
var layer = RotateWorldMainLayer.node();
|
||||
this.addChild(layer);
|
||||
this.runAction(cc.RotateBy.create(4, -360));
|
||||
cc.Director.getInstance().replaceScene(this);
|
||||
}
|
||||
});
|
||||
|
||||
var SpriteLayer = cc.Layer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var x, y;
|
||||
|
||||
var size = cc.Director.getInstance().getWinSize();
|
||||
x = size.width;
|
||||
y = size.height;
|
||||
|
||||
var sprite = cc.Sprite.create(s_pathGrossini);
|
||||
var spriteSister1 = cc.Sprite.create(s_pathSister1);
|
||||
var spriteSister2 = cc.Sprite.create(s_pathSister2);
|
||||
|
||||
sprite.setScale(1.5);
|
||||
spriteSister1.setScale(1.5);
|
||||
spriteSister2.setScale(1.5);
|
||||
|
||||
sprite.setPosition(cc.p(x / 2, y / 2));
|
||||
spriteSister1.setPosition(cc.p(40, y / 2));
|
||||
spriteSister2.setPosition(cc.p(x - 40, y / 2));
|
||||
|
||||
var rot = cc.RotateBy.create(16, -3600);
|
||||
|
||||
this.addChild(sprite);
|
||||
this.addChild(spriteSister1);
|
||||
this.addChild(spriteSister2);
|
||||
|
||||
sprite.runAction(rot);
|
||||
|
||||
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();
|
||||
|
||||
spriteSister1.runAction(cc.Repeat.create(cc.Sequence.create(jump2, jump1, null), 5));
|
||||
spriteSister2.runAction(cc.Repeat.create(cc.Sequence.create(jump1.copy(), jump2.copy(), null), 5));
|
||||
|
||||
spriteSister1.runAction(cc.Repeat.create(cc.Sequence.create(rot1, rot2, null), 5));
|
||||
spriteSister2.runAction(cc.Repeat.create(cc.Sequence.create(rot2.copy(), rot1.copy(), null), 5));
|
||||
}
|
||||
});
|
||||
|
||||
SpriteLayer.node = function () {
|
||||
var node = new SpriteLayer();
|
||||
return node;
|
||||
};
|
||||
|
||||
var TestLayer = cc.Layer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var x, y;
|
||||
|
||||
var size = cc.Director.getInstance().getWinSize();
|
||||
x = size.width;
|
||||
y = size.height;
|
||||
|
||||
//cc.MutableArray *array = [UIFont familyNames];
|
||||
//for( cc.String *s in array )
|
||||
// NSLog( s );
|
||||
var label = cc.LabelTTF.create("cocos2d", "Tahoma", 64);
|
||||
|
||||
label.setPosition(cc.p(x / 2, y / 2));
|
||||
|
||||
this.addChild(label);
|
||||
}
|
||||
});
|
||||
|
||||
TestLayer.node = function () {
|
||||
var node = new TestLayer();
|
||||
return node;
|
||||
};
|
||||
|
||||
var RotateWorldMainLayer = cc.Layer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
var x, y;
|
||||
|
||||
var size = cc.Director.getInstance().getWinSize();
|
||||
x = size.width;
|
||||
y = size.height;
|
||||
|
||||
var blue = cc.LayerColor.create(cc.c4b(0, 0, 255, 255));
|
||||
var red = cc.LayerColor.create(cc.c4b(255, 0, 0, 255));
|
||||
var green = cc.LayerColor.create(cc.c4b(0, 255, 0, 255));
|
||||
var white = cc.LayerColor.create(cc.c4b(255, 255, 255, 255));
|
||||
|
||||
blue.setScale(0.5);
|
||||
blue.setPosition(cc.p(-x / 4, -y / 4));
|
||||
blue.addChild(SpriteLayer.node());
|
||||
|
||||
red.setScale(0.5);
|
||||
red.setPosition(cc.p(x / 4, -y / 4));
|
||||
|
||||
green.setScale(0.5);
|
||||
green.setPosition(cc.p(-x / 4, y / 4));
|
||||
green.addChild(TestLayer.node());
|
||||
|
||||
white.setScale(0.5);
|
||||
white.setPosition(cc.p(x / 4, y / 4));
|
||||
|
||||
this.addChild(blue, -1);
|
||||
this.addChild(white);
|
||||
this.addChild(green);
|
||||
this.addChild(red);
|
||||
|
||||
var rot = cc.RotateBy.create(8, 720);
|
||||
|
||||
blue.runAction(rot);
|
||||
red.runAction(rot.copy());
|
||||
green.runAction(rot.copy());
|
||||
white.runAction(rot.copy());
|
||||
}
|
||||
});
|
||||
|
||||
RotateWorldMainLayer.node = function () {
|
||||
var node = new RotateWorldMainLayer();
|
||||
return node;
|
||||
};
|
|
@ -0,0 +1,192 @@
|
|||
/****************************************************************************
|
||||
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 MID_PUSHSCENE = 100;
|
||||
var MID_PUSHSCENETRAN = 101;
|
||||
var MID_QUIT = 102;
|
||||
var MID_REPLACESCENE = 103;
|
||||
var MID_REPLACESCENETRAN = 104;
|
||||
var MID_GOBACK = 105;
|
||||
|
||||
SceneTestLayer1 = cc.Layer.extend({
|
||||
|
||||
ctor:function () {
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
var item1 = cc.MenuItemFont.create("Test pushScene", this, this.onPushScene);
|
||||
var item2 = cc.MenuItemFont.create("Test pushScene w/transition", this, this.onPushSceneTran);
|
||||
var item3 = cc.MenuItemFont.create("Quit", this, function () {
|
||||
alert("quit")
|
||||
});
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3);
|
||||
menu.alignItemsVertically();
|
||||
this.addChild(menu);
|
||||
|
||||
var sprite = cc.Sprite.create(s_pathGrossini);
|
||||
this.addChild(sprite);
|
||||
sprite.setPosition(cc.p(s.width - 40, s.height / 2));
|
||||
var rotate = cc.RotateBy.create(2, 360);
|
||||
var repeat = cc.RepeatForever.create(rotate);
|
||||
sprite.runAction(repeat);
|
||||
this._super();
|
||||
//cc.schedule(this.testDealloc);
|
||||
},
|
||||
|
||||
|
||||
onEnter:function () {
|
||||
cc.log("SceneTestLayer1#onEnter");
|
||||
this._super();
|
||||
},
|
||||
|
||||
onEnterTransitionDidFinish:function () {
|
||||
cc.log("SceneTestLayer1#onEnterTransitionDidFinish");
|
||||
this._super();
|
||||
},
|
||||
|
||||
testDealloc:function (dt) {
|
||||
//cc.log("SceneTestLayer1:testDealloc");
|
||||
},
|
||||
|
||||
onPushScene:function (sender) {
|
||||
var scene = new SceneTestScene();
|
||||
var layer = new SceneTestLayer2();
|
||||
scene.addChild(layer, 0);
|
||||
cc.Director.getInstance().pushScene(scene);
|
||||
},
|
||||
|
||||
onPushSceneTran:function (sender) {
|
||||
var scene = new SceneTestScene();
|
||||
var layer = new SceneTestLayer2();
|
||||
scene.addChild(layer, 0);
|
||||
|
||||
cc.Director.getInstance().pushScene(cc.TransitionSlideInT.create(1, scene));
|
||||
},
|
||||
onQuit:function (sender) {
|
||||
|
||||
}
|
||||
|
||||
//CREATE_NODE(SceneTestLayer1);
|
||||
});
|
||||
|
||||
SceneTestLayer2 = cc.Layer.extend({
|
||||
|
||||
timeCounter:0,
|
||||
|
||||
ctor:function () {
|
||||
this.timeCounter = 0;
|
||||
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
var item1 = cc.MenuItemFont.create("replaceScene", this, this.onReplaceScene);
|
||||
var item2 = cc.MenuItemFont.create("replaceScene w/transition", this, this.onReplaceSceneTran);
|
||||
var item3 = cc.MenuItemFont.create("Go Back", this, this.onGoBack);
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3, null);
|
||||
menu.alignItemsVertically();
|
||||
this.addChild(menu);
|
||||
|
||||
var sprite = cc.Sprite.create(s_pathGrossini);
|
||||
this.addChild(sprite);
|
||||
|
||||
sprite.setPosition(cc.p(s.width - 40, s.height / 2));
|
||||
var rotate = cc.RotateBy.create(2, 360);
|
||||
var repeat = cc.RepeatForever.create(rotate);
|
||||
sprite.runAction(repeat);
|
||||
|
||||
//cc.schedule(this.testDealloc);
|
||||
this._super();
|
||||
|
||||
|
||||
},
|
||||
|
||||
testDealloc:function (dt) {
|
||||
|
||||
},
|
||||
|
||||
onGoBack:function (sender) {
|
||||
cc.Director.getInstance().popScene();
|
||||
},
|
||||
|
||||
onReplaceScene:function (sender) {
|
||||
var scene = new SceneTestScene();
|
||||
var layer = new SceneTestLayer3();
|
||||
scene.addChild(layer, 0);
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
|
||||
},
|
||||
|
||||
onReplaceSceneTran:function (sender) {
|
||||
var scene = new SceneTestScene();
|
||||
var layer = new SceneTestLayer3();
|
||||
scene.addChild(layer, 0);
|
||||
cc.Director.getInstance().replaceScene(cc.TransitionSlideInT.create(2, scene));
|
||||
|
||||
}
|
||||
|
||||
//CREATE_NODE(SceneTestLayer2);
|
||||
});
|
||||
|
||||
SceneTestLayer3 = cc.LayerColor.extend({
|
||||
|
||||
|
||||
ctor:function () {
|
||||
this._super();
|
||||
this.setTouchEnabled(true);
|
||||
var label = cc.LabelTTF.create("Touch to popScene", "Arial", 28);
|
||||
this.addChild(label);
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
label.setPosition(cc.p(s.width / 2, s.height / 2));
|
||||
|
||||
var sprite = cc.Sprite.create(s_pathGrossini);
|
||||
this.addChild(sprite);
|
||||
|
||||
sprite.setPosition(cc.p(s.width - 40, s.height / 2));
|
||||
var rotate = cc.RotateBy.create(2, 360);
|
||||
var repeat = cc.RepeatForever.create(rotate);
|
||||
sprite.runAction(repeat);
|
||||
},
|
||||
|
||||
testDealloc:function (dt) {
|
||||
|
||||
},
|
||||
|
||||
onTouchesEnded:function (touches, event) {
|
||||
cc.Director.getInstance().popScene();
|
||||
}
|
||||
|
||||
//CREATE_NODE(SceneTestLayer3);
|
||||
});
|
||||
|
||||
SceneTestScene = TestScene.extend({
|
||||
|
||||
runThisTest:function () {
|
||||
var layer = new SceneTestLayer1();
|
||||
this.addChild(layer);
|
||||
|
||||
cc.Director.getInstance().replaceScene(this);
|
||||
|
||||
}
|
||||
});
|
|
@ -0,0 +1,461 @@
|
|||
/****************************************************************************
|
||||
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_ANIMATION_DANCE = 1;
|
||||
var MAX_TESTS = 8;
|
||||
var sceneIdx = -1;
|
||||
|
||||
var createSchedulerTest = function (index) {
|
||||
var layer = null;
|
||||
|
||||
switch (index) {
|
||||
case 0:
|
||||
layer = new SchedulerAutoremove();
|
||||
break;
|
||||
case 1:
|
||||
layer = new SchedulerPauseResume();
|
||||
break;
|
||||
case 2:
|
||||
layer = new SchedulerUnscheduleAll();
|
||||
break;
|
||||
case 3:
|
||||
layer = new SchedulerUnscheduleAllHard();
|
||||
break;
|
||||
case 4:
|
||||
layer = new SchedulerSchedulesAndRemove();
|
||||
break;
|
||||
case 5:
|
||||
layer = new SchedulerUpdate();
|
||||
break;
|
||||
case 6:
|
||||
layer = new SchedulerUpdateAndCustom();
|
||||
break;
|
||||
case 7:
|
||||
layer = new SchedulerUpdateFromCustom();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return layer;
|
||||
};
|
||||
|
||||
var nextSchedulerTest = function () {
|
||||
sceneIdx++;
|
||||
sceneIdx = sceneIdx % MAX_TESTS;
|
||||
|
||||
return createSchedulerTest(sceneIdx);
|
||||
};
|
||||
|
||||
var backSchedulerTest = function () {
|
||||
sceneIdx--;
|
||||
if (sceneIdx < 0)
|
||||
sceneIdx += MAX_TESTS;
|
||||
|
||||
return createSchedulerTest(sceneIdx);
|
||||
};
|
||||
|
||||
var restartSchedulerTest = function () {
|
||||
return createSchedulerTest(sceneIdx);
|
||||
};
|
||||
|
||||
var SchedulerTestLayer = cc.Layer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 30);
|
||||
this.addChild(label);
|
||||
label.setPosition(cc.p(s.width / 2, s.height - 50));
|
||||
|
||||
var subTitle = this.subtitle();
|
||||
if (subTitle != "") {
|
||||
var subLabel = cc.LabelTTF.create(subTitle, "Thonburi", 13);
|
||||
this.addChild(subLabel, 1);
|
||||
subLabel.setPosition(cc.p(s.width / 2, s.height - 80));
|
||||
}
|
||||
|
||||
var item1 = cc.MenuItemImage.create("res/Images/b1.png", "res/Images/b2.png", this, this.backCallback);
|
||||
var item2 = cc.MenuItemImage.create("res/Images/r1.png", "res/Images/r2.png", this, this.restartCallback);
|
||||
var item3 = cc.MenuItemImage.create("res/Images/f1.png", "res/Images/f2.png", this, this.nextCallback);
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3, null);
|
||||
menu.setPosition(cc.p(0,0));
|
||||
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));
|
||||
|
||||
this.addChild(menu, 1)
|
||||
},
|
||||
title:function () {
|
||||
return "No title";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "";
|
||||
},
|
||||
|
||||
backCallback:function (sender) {
|
||||
var scene = new SchedulerTestScene();
|
||||
var layer = backSchedulerTest();
|
||||
|
||||
scene.addChild(layer);
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
},
|
||||
nextCallback:function (sender) {
|
||||
var scene = new SchedulerTestScene();
|
||||
var layer = nextSchedulerTest();
|
||||
|
||||
scene.addChild(layer);
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
},
|
||||
restartCallback:function (sender) {
|
||||
var scene = new SchedulerTestScene();
|
||||
var layer = restartSchedulerTest();
|
||||
|
||||
scene.addChild(layer);
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
}
|
||||
});
|
||||
|
||||
var SchedulerAutoremove = SchedulerTestLayer.extend({
|
||||
_accum:0,
|
||||
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
this.schedule(this.autoremove, 0.5);
|
||||
this.schedule(this.tick, 0.5);
|
||||
this._accum = 0;
|
||||
},
|
||||
title:function () {
|
||||
return "Self-remove an scheduler";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "1 scheduler will be autoremoved in 3 seconds. See console";
|
||||
},
|
||||
|
||||
autoremove:function (dt) {
|
||||
this._accum += dt;
|
||||
cc.log("Time: " + this._accum);
|
||||
|
||||
if (this._accum > 3) {
|
||||
this.unschedule(this.autoremove);
|
||||
cc.log("scheduler removed");
|
||||
}
|
||||
},
|
||||
tick:function (dt) {
|
||||
cc.log("This scheduler should not be removed");
|
||||
}
|
||||
});
|
||||
|
||||
var SchedulerPauseResume = SchedulerTestLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
this.schedule(this.tick1, 0.5);
|
||||
this.schedule(this.tick2, 0.5);
|
||||
this.schedule(this.pause, 0.5);
|
||||
},
|
||||
title:function () {
|
||||
return "Pause / Resume";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "Scheduler should be paused after 3 seconds. See console";
|
||||
},
|
||||
|
||||
tick1:function (dt) {
|
||||
cc.log("tick1");
|
||||
},
|
||||
tick2:function (dt) {
|
||||
cc.log("tick2");
|
||||
},
|
||||
pause:function (dt) {
|
||||
cc.Director.getInstance().getScheduler().pauseTarget(this);
|
||||
}
|
||||
});
|
||||
|
||||
var SchedulerUnscheduleAll = SchedulerTestLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
this.schedule(this.tick1, 0.5);
|
||||
this.schedule(this.tick2, 1.0);
|
||||
this.schedule(this.tick3, 1.5);
|
||||
this.schedule(this.tick4, 1.5);
|
||||
this.schedule(this.unscheduleAll, 4);
|
||||
},
|
||||
title:function () {
|
||||
return "Unschedule All selectors";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "All scheduled selectors will be unscheduled in 4 seconds. See console";
|
||||
},
|
||||
|
||||
tick1:function (dt) {
|
||||
cc.log("tick1");
|
||||
},
|
||||
tick2:function (dt) {
|
||||
cc.log("tick2");
|
||||
},
|
||||
tick3:function (dt) {
|
||||
cc.log("tick3");
|
||||
},
|
||||
tick4:function (dt) {
|
||||
cc.log("tick4");
|
||||
},
|
||||
unscheduleAll:function (dt) {
|
||||
this.unscheduleAllSelectors();
|
||||
}
|
||||
});
|
||||
|
||||
var SchedulerUnscheduleAllHard = SchedulerTestLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
this.schedule(this.tick1, 0.5);
|
||||
this.schedule(this.tick2, 1.0);
|
||||
this.schedule(this.tick3, 1.5);
|
||||
this.schedule(this.tick4, 1.5);
|
||||
this.schedule(this.unscheduleAll, 4);
|
||||
},
|
||||
title:function () {
|
||||
return "Unschedule All selectors #2";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "Unschedules all selectors after 4s. Uses CCScheduler. See console";
|
||||
},
|
||||
|
||||
tick1:function (dt) {
|
||||
cc.log("tick1");
|
||||
},
|
||||
tick2:function (dt) {
|
||||
cc.log("tick2");
|
||||
},
|
||||
tick3:function (dt) {
|
||||
cc.log("tick3");
|
||||
},
|
||||
tick4:function (dt) {
|
||||
cc.log("tick4");
|
||||
},
|
||||
unscheduleAll:function (dt) {
|
||||
cc.Director.getInstance().getScheduler().unscheduleAllSelectors();
|
||||
}
|
||||
});
|
||||
|
||||
var SchedulerSchedulesAndRemove = SchedulerTestLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
this.schedule(this.tick1, 0.5);
|
||||
this.schedule(this.tick2, 1.0);
|
||||
this.schedule(this.scheduleAndUnschedule, 4.0);
|
||||
},
|
||||
title:function () {
|
||||
return "Schedule from Schedule";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "Will unschedule and schedule selectors in 4s. See console";
|
||||
},
|
||||
|
||||
tick1:function (dt) {
|
||||
cc.log("tick1");
|
||||
},
|
||||
tick2:function (dt) {
|
||||
cc.log("tick2");
|
||||
},
|
||||
tick3:function (dt) {
|
||||
cc.log("tick3");
|
||||
},
|
||||
tick4:function (dt) {
|
||||
cc.log("tick4");
|
||||
},
|
||||
scheduleAndUnschedule:function (dt) {
|
||||
this.unschedule(this.tick1);
|
||||
this.unschedule(this.tick2);
|
||||
this.unschedule(this.scheduleAndUnschedule);
|
||||
|
||||
this.schedule(this.tick3, 1.0);
|
||||
this.schedule(this.tick4, 1.0);
|
||||
}
|
||||
});
|
||||
|
||||
var TestNode = cc.Node.extend({
|
||||
_pString:"",
|
||||
|
||||
initWithString:function (str, priority) {
|
||||
this._pString = str;
|
||||
this.scheduleUpdateWithPriority(priority);
|
||||
}
|
||||
});
|
||||
|
||||
var SchedulerUpdate = SchedulerTestLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var d = new TestNode();
|
||||
var str = "---";
|
||||
d.initWithString(str, 50);
|
||||
this.addChild(d);
|
||||
|
||||
|
||||
var b = new TestNode();
|
||||
str = "3rd";
|
||||
b.initWithString(str, 0);
|
||||
this.addChild(b);
|
||||
|
||||
var a = new TestNode();
|
||||
str = "1st";
|
||||
a.initWithString(str, -10);
|
||||
this.addChild(a);
|
||||
|
||||
var c = new TestNode();
|
||||
str = "4th";
|
||||
c.initWithString(str, 10);
|
||||
this.addChild(c);
|
||||
|
||||
var e = new TestNode();
|
||||
str = "5th";
|
||||
e.initWithString(str, 20);
|
||||
this.addChild(e);
|
||||
|
||||
var f = new TestNode();
|
||||
str = "2nd";
|
||||
f.initWithString(str, -5);
|
||||
this.addChild(f);
|
||||
|
||||
this.schedule(this.removeUpdates, 4.0);
|
||||
},
|
||||
title:function () {
|
||||
return "Schedule update with priority";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "3 scheduled updates. Priority should work. Stops in 4s. See console";
|
||||
},
|
||||
|
||||
removeUpdates:function (dt) {
|
||||
var children = this.getChildren();
|
||||
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var node = children[i];
|
||||
if (node) {
|
||||
node.unscheduleAllSelectors();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var SchedulerUpdateAndCustom = SchedulerTestLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
this.scheduleUpdate();
|
||||
this.schedule(this.tick);
|
||||
this.schedule(this.stopSelectors, 0.4);
|
||||
},
|
||||
title:function () {
|
||||
return "Schedule Update + custom selector";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "Update + custom selector at the same time. Stops in 4s. See console";
|
||||
},
|
||||
|
||||
update:function (dt) {
|
||||
cc.log("update called:" + dt);
|
||||
},
|
||||
tick:function (dt) {
|
||||
cc.log("custom selector called:" + dt);
|
||||
},
|
||||
stopSelectors:function (dt) {
|
||||
this.unscheduleAllSelectors();
|
||||
}
|
||||
});
|
||||
|
||||
var SchedulerUpdateFromCustom = SchedulerTestLayer.extend({
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
this.schedule(this.schedUpdate, 2.0);
|
||||
},
|
||||
title:function () {
|
||||
return "Schedule Update in 2 sec";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "Update schedules in 2 secs. Stops 2 sec later. See console";
|
||||
},
|
||||
|
||||
update:function (dt) {
|
||||
cc.log("update called:" + dt);
|
||||
},
|
||||
schedUpdate:function (dt) {
|
||||
this.unschedule(this.schedUpdate);
|
||||
this.scheduleUpdate();
|
||||
this.schedule(this.stopUpdate, 2.0);
|
||||
},
|
||||
stopUpdate:function (dt) {
|
||||
this.unscheduleUpdate();
|
||||
this.unschedule(this.stopUpdate);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
var RescheduleSelector = SchedulerTestLayer.extend({
|
||||
_interval:1.0,
|
||||
_ticks:0,
|
||||
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
this._interval = 1.0;
|
||||
this._ticks = 0;
|
||||
this.schedule(this.schedUpdate, this._interval);
|
||||
},
|
||||
title:function () {
|
||||
return "Reschedule Selector";
|
||||
},
|
||||
subtitle:function () {
|
||||
return "Interval is 1 second, then 2, then 3...";
|
||||
},
|
||||
|
||||
schedUpdate:function (dt) {
|
||||
this._ticks++;
|
||||
|
||||
cc.log("schedUpdate: " + dt.toFixed(2));
|
||||
if (this._ticks > 3) {
|
||||
this._interval += 1.0;
|
||||
this.schedule(this.schedUpdate, this._interval);
|
||||
this._ticks = 0;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var SchedulerTestScene = TestScene.extend({
|
||||
runThisTest:function () {
|
||||
var layer = nextSchedulerTest();
|
||||
this.addChild(layer);
|
||||
|
||||
cc.Director.getInstance().replaceScene(this);
|
||||
}
|
||||
});
|
|
@ -0,0 +1 @@
|
|||
060f4e7b441575496d875cf27a0928d53a3806dc
|
|
@ -0,0 +1,126 @@
|
|||
/****************************************************************************
|
||||
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 CustomTableViewCell = cc.TableViewCell.extend({
|
||||
draw:function (ctx) {
|
||||
this._super(ctx);
|
||||
}
|
||||
});
|
||||
|
||||
var TableViewTestLayer = cc.Layer.extend({
|
||||
init:function () {
|
||||
if (!this._super()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var winSize = cc.Director.getInstance().getWinSize();
|
||||
|
||||
var tableView = cc.TableView.create(this, cc.SizeMake(600, 60));
|
||||
tableView.setDirection(cc.SCROLLVIEW_DIRECTION_HORIZONTAL);
|
||||
tableView.setPosition(cc.p(20, winSize.height / 2 - 150));
|
||||
tableView.setDelegate(this);
|
||||
this.addChild(tableView);
|
||||
tableView.reloadData();
|
||||
|
||||
tableView = cc.TableView.create(this, cc.SizeMake(60, 350));
|
||||
tableView.setDirection(cc.SCROLLVIEW_DIRECTION_VERTICAL);
|
||||
tableView.setPosition(cc.p(winSize.width - 150, winSize.height / 2 - 150));
|
||||
tableView.setDelegate(this);
|
||||
tableView.setVerticalFillOrder(cc.TABLEVIEW_FILL_TOPDOWN);
|
||||
this.addChild(tableView);
|
||||
tableView.reloadData();
|
||||
|
||||
// Back Menu
|
||||
var itemBack = cc.MenuItemFont.create("Back", this, this.toExtensionsMainLayer);
|
||||
itemBack.setPosition(cc.p(winSize.width - 50, 25));
|
||||
var menuBack = cc.Menu.create(itemBack);
|
||||
menuBack.setPosition(cc.p(0,0));
|
||||
this.addChild(menuBack);
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
toExtensionsMainLayer:function (sender) {
|
||||
var scene = new ExtensionsTestScene();
|
||||
scene.runThisTest();
|
||||
},
|
||||
|
||||
scrollViewDidScroll:function (view) {
|
||||
},
|
||||
scrollViewDidZoom:function (view) {
|
||||
},
|
||||
|
||||
tableCellTouched:function (table, cell) {
|
||||
cc.log("cell touched at index: " + cell.getIdx());
|
||||
},
|
||||
|
||||
cellSizeForTable:function (table) {
|
||||
return cc.SizeMake(60, 60);
|
||||
},
|
||||
|
||||
tableCellAtIndex:function (table, idx) {
|
||||
var strValue = idx.toFixed(0);
|
||||
var cell = table.dequeueCell();
|
||||
var label;
|
||||
if (!cell) {
|
||||
cell = new CustomTableViewCell();
|
||||
var sprite = cc.Sprite.create(s_image_icon);
|
||||
sprite.setAnchorPoint(cc.p(0,0));
|
||||
sprite.setPosition(cc.p(0, 0));
|
||||
cell.addChild(sprite);
|
||||
|
||||
label = cc.LabelTTF.create(strValue, "Helvetica", 20.0);
|
||||
label.setPosition(cc.p(0,0));
|
||||
label.setAnchorPoint(cc.p(0,0));
|
||||
label.setTag(123);
|
||||
cell.addChild(label);
|
||||
} else {
|
||||
label = cell.getChildByTag(123);
|
||||
label.setString(strValue);
|
||||
}
|
||||
|
||||
return cell;
|
||||
},
|
||||
|
||||
numberOfCellsInTableView:function (table) {
|
||||
return 25;
|
||||
}
|
||||
});
|
||||
|
||||
TableViewTestLayer.create = function () {
|
||||
var retObj = new TableViewTestLayer();
|
||||
if (retObj && retObj.init()) {
|
||||
return retObj;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
var runTableViewTest = function () {
|
||||
var pScene = cc.Scene.create();
|
||||
var pLayer = TableViewTestLayer.create();
|
||||
pScene.addChild(pLayer);
|
||||
cc.Director.getInstance().replaceScene(pScene);
|
||||
};
|
|
@ -0,0 +1,56 @@
|
|||
/****************************************************************************
|
||||
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 TestHeaderLayer = cc.Layer.extend({
|
||||
onResolveCCBCCMenuItemSelector:function(target, selectorName){
|
||||
if(this == target && "onBackClicked" == selectorName){
|
||||
return this.onBackClicked;
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
onResolveCCBCCControlSelector:function(target,selectorName){
|
||||
return null;
|
||||
},
|
||||
|
||||
onBackClicked:function(sender){
|
||||
cc.Director.getInstance().popScene();
|
||||
}
|
||||
});
|
||||
|
||||
TestHeaderLayer.create = function(){
|
||||
var retObj = new TestHeaderLayer();
|
||||
if(retObj && retObj.init()){
|
||||
return retObj;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
var TestHeaderLayerLoader = cc.LayerLoader.extend({
|
||||
_createCCNode:function(parent,ccbReader){
|
||||
return TestHeaderLayer.create();
|
||||
}
|
||||
});
|
|
@ -0,0 +1,422 @@
|
|||
/****************************************************************************
|
||||
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 TEXT_FIELD_TTF_DEFAULT_TEST = 0;
|
||||
var TEXT_FIELD_TTF_ACTION_TEST = 1;
|
||||
var TEXT_INPUT_TESTS_COUNT = 2;
|
||||
|
||||
var TEXT_INPUT_FONT_NAME = "Thonburi";
|
||||
var TEXT_INPUT_FONT_SIZE = 36;
|
||||
|
||||
var inputTestIdx = -1;
|
||||
|
||||
var createTextInputTest = function (index) {
|
||||
switch (index) {
|
||||
case TEXT_FIELD_TTF_DEFAULT_TEST:
|
||||
return new TextFieldTTFDefaultTest();
|
||||
case TEXT_FIELD_TTF_ACTION_TEST:
|
||||
return new TextFieldTTFActionTest();
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
var restartTextInputTest = function () {
|
||||
var containerLayer = new TextInputTest();
|
||||
|
||||
var testLayer = createTextInputTest(inputTestIdx);
|
||||
containerLayer.addKeyboardNotificationLayer(testLayer);
|
||||
|
||||
return containerLayer;
|
||||
};
|
||||
|
||||
var nextTextInputTest = function () {
|
||||
inputTestIdx++;
|
||||
inputTestIdx = inputTestIdx % TEXT_INPUT_TESTS_COUNT;
|
||||
|
||||
return restartTextInputTest();
|
||||
};
|
||||
|
||||
var backTextInputTest = function () {
|
||||
inputTestIdx--;
|
||||
if (inputTestIdx < 0)
|
||||
inputTestIdx += TEXT_INPUT_TESTS_COUNT;
|
||||
|
||||
return restartTextInputTest();
|
||||
};
|
||||
|
||||
var textInputGetRect = function (node) {
|
||||
var rc = cc.rect(node.getPosition().x, node.getPosition().y, node.getContentSize().width, node.getContentSize().height);
|
||||
rc.origin.x -= rc.size.width / 2;
|
||||
rc.origin.y -= rc.size.height / 2;
|
||||
return rc;
|
||||
};
|
||||
|
||||
/**
|
||||
@brief TextInputTest for retain prev, reset, next, main menu buttons.
|
||||
*/
|
||||
var TextInputTest = cc.Layer.extend({
|
||||
notificationLayer:null,
|
||||
ctor:function () {
|
||||
},
|
||||
|
||||
restartCallback:function (sender) {
|
||||
var s = new TextInputTestScene();
|
||||
s.addChild(restartTextInputTest());
|
||||
cc.Director.getInstance().replaceScene(s);
|
||||
},
|
||||
nextCallback:function (sender) {
|
||||
var s = new TextInputTestScene();
|
||||
s.addChild(nextTextInputTest());
|
||||
cc.Director.getInstance().replaceScene(s);
|
||||
},
|
||||
backCallback:function (sender) {
|
||||
var s = new TextInputTestScene();
|
||||
s.addChild(backTextInputTest());
|
||||
cc.Director.getInstance().replaceScene(s);
|
||||
},
|
||||
|
||||
title:function () {
|
||||
return "text input test";
|
||||
},
|
||||
addKeyboardNotificationLayer:function (layer) {
|
||||
this.notificationLayer = layer;
|
||||
this.addChild(layer);
|
||||
},
|
||||
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
var label = cc.LabelTTF.create(this.title(), "Arial", 24);
|
||||
this.addChild(label);
|
||||
label.setPosition(cc.p(s.width / 2, s.height - 50));
|
||||
|
||||
var subTitle = this.notificationLayer.subtitle();
|
||||
if (subTitle && subTitle != "") {
|
||||
var l = cc.LabelTTF.create(subTitle, "Thonburi", 16);
|
||||
this.addChild(l, 1);
|
||||
l.setPosition(cc.p(s.width / 2, s.height - 80));
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3);
|
||||
menu.setPosition(cc.p(0,0));
|
||||
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));
|
||||
|
||||
this.addChild(menu, 1);
|
||||
}
|
||||
});
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// KeyboardNotificationLayer for test IME keyboard notification.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
var KeyboardNotificationLayer = cc.Layer.extend({
|
||||
_pTrackNode:null,
|
||||
_beginPos:null,
|
||||
|
||||
ctor:function () {
|
||||
this.setTouchEnabled(true);
|
||||
},
|
||||
|
||||
subtitle:function () {
|
||||
return "";
|
||||
},
|
||||
onClickTrackNode:function (clicked) {
|
||||
},
|
||||
|
||||
registerWithTouchDispatcher:function () {
|
||||
cc.Director.getInstance().getTouchDispatcher().addTargetedDelegate(this, 0, false);
|
||||
},
|
||||
keyboardWillShow:function (info) {
|
||||
cc.log("TextInputTest:keyboardWillShowAt(origin:" + info.end.origin.x + "," + info.end.origin.y
|
||||
+ ", size:" + info.end.size.width + "," + info.end.size.height + ")");
|
||||
|
||||
if (!this._pTrackNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
var rectTracked = textInputGetRect(this._pTrackNode);
|
||||
cc.log("TextInputTest:trackingNodeAt(origin:" + info.end.origin.x + "," + info.end.origin.y
|
||||
+ ", size:" + info.end.size.width + "," + info.end.size.height + ")");
|
||||
|
||||
// if the keyboard area doesn't intersect with the tracking node area, nothing need to do.
|
||||
if (!cc.Rect.CCRectIntersectsRect(rectTracked, info.end)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// assume keyboard at the bottom of screen, calculate the vertical adjustment.
|
||||
var adjustVert = cc.Rect.CCRectGetMaxY(info.end) - cc.Rect.CCRectGetMinY(rectTracked);
|
||||
cc.log("TextInputTest:needAdjustVerticalPosition(" + adjustVert + ")");
|
||||
|
||||
// move all the children node of KeyboardNotificationLayer
|
||||
var children = this.getChildren();
|
||||
for (var i = 0; i < children.length; ++i) {
|
||||
var node = children[i];
|
||||
var pos = node.getPosition();
|
||||
pos.y += adjustVert;
|
||||
node.setPosition(pos);
|
||||
}
|
||||
},
|
||||
|
||||
onTouchBegan:function (touch, event) {
|
||||
cc.log("++++++++++++++++++++++++++++++++++++++++++++");
|
||||
this._beginPos = touch.getLocation();
|
||||
this._beginPos = cc.Director.getInstance().convertToGL(this._beginPos);
|
||||
return true;
|
||||
},
|
||||
|
||||
onTouchEnded:function (touch, event) {
|
||||
if (!this._pTrackNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
var endPos = touch.getLocation();
|
||||
endPos = cc.Director.getInstance().convertToGL(endPos);
|
||||
|
||||
var delta = 5.0;
|
||||
if (Math.abs(endPos.x - this._beginPos.x) > delta
|
||||
|| Math.abs(endPos.y - this._beginPos.y) > delta) {
|
||||
// not click
|
||||
this._beginPos.x = this._beginPos.y = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
// decide the trackNode is clicked.
|
||||
var point = this.convertTouchToNodeSpaceAR(touch);
|
||||
//var point = endPos;
|
||||
cc.log("KeyboardNotificationLayer:clickedAt(" + point.x + "," + point.y + ")");
|
||||
|
||||
var rect = textInputGetRect(this._pTrackNode);
|
||||
cc.log("KeyboardNotificationLayer:TrackNode at(origin:" + rect.origin.x + "," + rect.origin.y
|
||||
+ ", size:" + rect.size.width + "," + rect.size.height + ")");
|
||||
|
||||
this.onClickTrackNode(cc.Rect.CCRectContainsPoint(rect, point));
|
||||
cc.log("----------------------------------");
|
||||
}
|
||||
});
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// TextFieldTTFDefaultTest for test TextFieldTTF default behavior.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
var TextFieldTTFDefaultTest = KeyboardNotificationLayer.extend({
|
||||
subtitle:function () {
|
||||
return "TextFieldTTF with default behavior test";
|
||||
},
|
||||
onClickTrackNode:function (clicked) {
|
||||
var textField = this._pTrackNode;
|
||||
if (clicked) {
|
||||
// TextFieldTTFTest be clicked
|
||||
cc.log("TextFieldTTFDefaultTest:CCTextFieldTTF attachWithIME");
|
||||
textField.attachWithIME();
|
||||
}
|
||||
else {
|
||||
// TextFieldTTFTest not be clicked
|
||||
cc.log("TextFieldTTFDefaultTest:CCTextFieldTTF detachWithIME");
|
||||
textField.detachWithIME();
|
||||
}
|
||||
},
|
||||
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
// add CCTextFieldTTF
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
var textField = cc.TextFieldTTF.create("<click here for input>",
|
||||
TEXT_INPUT_FONT_NAME,
|
||||
TEXT_INPUT_FONT_SIZE);
|
||||
this.addChild(textField);
|
||||
textField.setPosition(cc.p(s.width / 2, s.height / 2));
|
||||
|
||||
this._pTrackNode = textField;
|
||||
}
|
||||
});
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// TextFieldTTFActionTest
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
var TextFieldTTFActionTest = KeyboardNotificationLayer.extend({
|
||||
_pTextField:null,
|
||||
_pTextFieldAction:null,
|
||||
_bAction:false,
|
||||
_nCharLimit:0, // the textfield max char limit
|
||||
|
||||
ctor:function () {
|
||||
this._super();
|
||||
},
|
||||
|
||||
callbackRemoveNodeWhenDidAction:function (node) {
|
||||
this.removeChild(node, true);
|
||||
},
|
||||
|
||||
// KeyboardNotificationLayer
|
||||
subtitle:function () {
|
||||
return "CCTextFieldTTF with action and char limit test";
|
||||
},
|
||||
onClickTrackNode:function (clicked) {
|
||||
var textField = this._pTrackNode;
|
||||
if (clicked) {
|
||||
// TextFieldTTFTest be clicked
|
||||
cc.log("TextFieldTTFActionTest:CCTextFieldTTF attachWithIME");
|
||||
textField.attachWithIME();
|
||||
} else {
|
||||
// TextFieldTTFTest not be clicked
|
||||
cc.log("TextFieldTTFActionTest:CCTextFieldTTF detachWithIME");
|
||||
textField.detachWithIME();
|
||||
}
|
||||
},
|
||||
|
||||
//CCLayer
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
|
||||
this._nCharLimit = 20;
|
||||
this._pTextFieldAction = cc.RepeatForever.create(
|
||||
cc.Sequence.create(
|
||||
cc.FadeOut.create(0.25),
|
||||
cc.FadeIn.create(0.25)));
|
||||
this._bAction = false;
|
||||
|
||||
// add CCTextFieldTTF
|
||||
var s = cc.Director.getInstance().getWinSize();
|
||||
|
||||
this._pTextField = cc.TextFieldTTF.create("<click here for input>",
|
||||
TEXT_INPUT_FONT_NAME,
|
||||
TEXT_INPUT_FONT_SIZE);
|
||||
this.addChild(this._pTextField);
|
||||
this._pTextField.setDelegate(this);
|
||||
|
||||
this._pTextField.setPosition(cc.p(s.width / 2, s.height / 2));
|
||||
this._pTrackNode = this._pTextField;
|
||||
},
|
||||
onExit:function () {
|
||||
this._super();
|
||||
},
|
||||
|
||||
//CCTextFieldDelegate
|
||||
onTextFieldAttachWithIME:function (sender) {
|
||||
if (!this._bAction) {
|
||||
this._pTextField.runAction(this._pTextFieldAction);
|
||||
this._bAction = true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
onTextFieldDetachWithIME:function (sender) {
|
||||
if (this._bAction) {
|
||||
this._pTextField.stopAction(this._pTextFieldAction);
|
||||
this._pTextField.setOpacity(255);
|
||||
this._bAction = false;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
onTextFieldInsertText:function (sender, text, len) {
|
||||
// if insert enter, treat as default to detach with ime
|
||||
if ('\n' == text) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// if the textfield's char count more than m_nCharLimit, doesn't insert text anymore.
|
||||
if (sender.getCharCount() >= this._nCharLimit) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// create a insert text sprite and do some action
|
||||
var label = cc.LabelTTF.create(text, TEXT_INPUT_FONT_NAME, TEXT_INPUT_FONT_SIZE);
|
||||
this.addChild(label);
|
||||
var color = new cc.Color3B(226, 121, 7);
|
||||
label.setColor(color);
|
||||
|
||||
// move the sprite from top to position
|
||||
var endPos = cc.p(sender.getPositionX(), sender.getPositionY());
|
||||
if (sender.getCharCount()) {
|
||||
endPos.x += sender.getContentSize().width / 2;
|
||||
}
|
||||
var inputTextSize = label.getContentSize();
|
||||
var beginPos = cc.p(endPos.x, cc.Director.getInstance().getWinSize().height - inputTextSize.height * 2);
|
||||
|
||||
var duration = 0.5;
|
||||
label.setPosition(beginPos);
|
||||
label.setScale(8);
|
||||
|
||||
var seq = cc.Sequence.create(
|
||||
cc.Spawn.create(
|
||||
cc.MoveTo.create(duration, endPos),
|
||||
cc.ScaleTo.create(duration, 1),
|
||||
cc.FadeOut.create(duration)),
|
||||
cc.CallFunc.create(this, this.callbackRemoveNodeWhenDidAction));
|
||||
label.runAction(seq);
|
||||
return false;
|
||||
},
|
||||
|
||||
onTextFieldDeleteBackward:function (sender, delText, len) {
|
||||
// create a delete text sprite and do some action
|
||||
var label = cc.LabelTTF.create(delText, TEXT_INPUT_FONT_NAME, TEXT_INPUT_FONT_SIZE);
|
||||
this.addChild(label);
|
||||
|
||||
// move the sprite to fly out
|
||||
var beginPos = cc.p(sender.getPositionX(), sender.getPositionY());
|
||||
var textfieldSize = sender.getContentSize();
|
||||
var labelSize = label.getContentSize();
|
||||
beginPos.x += (textfieldSize.width - labelSize.width) / 2.0;
|
||||
|
||||
var winSize = cc.Director.getInstance().getWinSize();
|
||||
var endPos = cc.p(-winSize.width / 4.0, winSize.height * (0.5 + Math.random() / 2.0));
|
||||
|
||||
var duration = 1;
|
||||
var rotateDuration = 0.2;
|
||||
var repeatTime = 5;
|
||||
label.setPosition(beginPos);
|
||||
|
||||
var seq = cc.Sequence.create(
|
||||
cc.Spawn.create(
|
||||
cc.MoveTo.create(duration, endPos),
|
||||
cc.Repeat.create(
|
||||
cc.RotateBy.create(rotateDuration, (Math.random() % 2) ? 360 : -360),
|
||||
repeatTime),
|
||||
cc.FadeOut.create(duration)),
|
||||
cc.CallFunc.create(this, this.callbackRemoveNodeWhenDidAction));
|
||||
label.runAction(seq);
|
||||
return false;
|
||||
},
|
||||
onDraw:function (sender) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
var TextInputTestScene = TestScene.extend({
|
||||
runThisTest:function () {
|
||||
var layer = nextTextInputTest();
|
||||
this.addChild(layer);
|
||||
cc.Director.getInstance().replaceScene(this);
|
||||
}
|
||||
});
|
|
@ -0,0 +1,149 @@
|
|||
/****************************************************************************
|
||||
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 TextureCacheTest = cc.Layer.extend({
|
||||
_labelLoading:null,
|
||||
_labelPercent:null,
|
||||
_numberOfSprites:20,
|
||||
_numberOfLoadedSprites:0,
|
||||
ctor:function () {
|
||||
var size = cc.Director.getInstance().getWinSize();
|
||||
|
||||
this._labelLoading = cc.LabelTTF.create("loading...", "Arial", 15);
|
||||
this._labelPercent = cc.LabelTTF.create("%0", "Arial", 15);
|
||||
|
||||
this._labelLoading.setPosition(cc.p(size.width / 2, size.height / 2 - 20));
|
||||
this._labelPercent.setPosition(cc.p(size.width / 2, size.height / 2 + 20));
|
||||
|
||||
this.addChild(this._labelLoading);
|
||||
this.addChild(this._labelPercent);
|
||||
|
||||
// load textrues
|
||||
cc.TextureCache.getInstance().addImageAsync("res/Images/HelloWorld.png", this, this.loadingCallBack);
|
||||
cc.TextureCache.getInstance().addImageAsync("res/Images/grossini.png", this, this.loadingCallBack);
|
||||
cc.TextureCache.getInstance().addImageAsync("res/Images/grossini_dance_01.png", this, this.loadingCallBack);
|
||||
cc.TextureCache.getInstance().addImageAsync("res/Images/grossini_dance_02.png", this, this.loadingCallBack);
|
||||
cc.TextureCache.getInstance().addImageAsync("res/Images/grossini_dance_03.png", this, this.loadingCallBack);
|
||||
cc.TextureCache.getInstance().addImageAsync("res/Images/grossini_dance_04.png", this, this.loadingCallBack);
|
||||
cc.TextureCache.getInstance().addImageAsync("res/Images/grossini_dance_05.png", this, this.loadingCallBack);
|
||||
cc.TextureCache.getInstance().addImageAsync("res/Images/grossini_dance_06.png", this, this.loadingCallBack);
|
||||
cc.TextureCache.getInstance().addImageAsync("res/Images/grossini_dance_07.png", this, this.loadingCallBack);
|
||||
cc.TextureCache.getInstance().addImageAsync("res/Images/grossini_dance_08.png", this, this.loadingCallBack);
|
||||
cc.TextureCache.getInstance().addImageAsync("res/Images/grossini_dance_09.png", this, this.loadingCallBack);
|
||||
cc.TextureCache.getInstance().addImageAsync("res/Images/grossini_dance_10.png", this, this.loadingCallBack);
|
||||
cc.TextureCache.getInstance().addImageAsync("res/Images/grossini_dance_11.png", this, this.loadingCallBack);
|
||||
cc.TextureCache.getInstance().addImageAsync("res/Images/grossini_dance_12.png", this, this.loadingCallBack);
|
||||
cc.TextureCache.getInstance().addImageAsync("res/Images/grossini_dance_13.png", this, this.loadingCallBack);
|
||||
cc.TextureCache.getInstance().addImageAsync("res/Images/grossini_dance_14.png", this, this.loadingCallBack);
|
||||
cc.TextureCache.getInstance().addImageAsync("res/Images/background1.png", this, this.loadingCallBack);
|
||||
cc.TextureCache.getInstance().addImageAsync("res/Images/background2.png", this, this.loadingCallBack);
|
||||
cc.TextureCache.getInstance().addImageAsync("res/Images/background3.png", this, this.loadingCallBack);
|
||||
cc.TextureCache.getInstance().addImageAsync("res/Images/blocks.png", this, this.loadingCallBack);
|
||||
},
|
||||
addSprite:function () {
|
||||
var size = cc.Director.getInstance().getWinSize();
|
||||
|
||||
// create sprites
|
||||
var bg = cc.Sprite.create("res/Images/HelloWorld.png");
|
||||
bg.setPosition(cc.p(size.width / 2, size.height / 2));
|
||||
//bg.setScale(1.7);
|
||||
|
||||
var s1 = cc.Sprite.create("res/Images/grossini.png");
|
||||
var s2 = cc.Sprite.create("res/Images/grossini_dance_01.png");
|
||||
var s3 = cc.Sprite.create("res/Images/grossini_dance_02.png");
|
||||
var s4 = cc.Sprite.create("res/Images/grossini_dance_03.png");
|
||||
var s5 = cc.Sprite.create("res/Images/grossini_dance_04.png");
|
||||
var s6 = cc.Sprite.create("res/Images/grossini_dance_05.png");
|
||||
var s7 = cc.Sprite.create("res/Images/grossini_dance_06.png");
|
||||
var s8 = cc.Sprite.create("res/Images/grossini_dance_07.png");
|
||||
var s9 = cc.Sprite.create("res/Images/grossini_dance_08.png");
|
||||
var s10 = cc.Sprite.create("res/Images/grossini_dance_09.png");
|
||||
var s11 = cc.Sprite.create("res/Images/grossini_dance_10.png");
|
||||
var s12 = cc.Sprite.create("res/Images/grossini_dance_11.png");
|
||||
var s13 = cc.Sprite.create("res/Images/grossini_dance_12.png");
|
||||
var s14 = cc.Sprite.create("res/Images/grossini_dance_13.png");
|
||||
var s15 = cc.Sprite.create("res/Images/grossini_dance_14.png");
|
||||
|
||||
// just loading textures to slow down
|
||||
var s16 = cc.Sprite.create("res/Images/background1.png");
|
||||
var s17 = cc.Sprite.create("res/Images/background2.png");
|
||||
var s18 = cc.Sprite.create("res/Images/background3.png");
|
||||
var s19 = cc.Sprite.create("res/Images/blocks.png");
|
||||
|
||||
s1.setPosition(cc.p(50, 50));
|
||||
s2.setPosition(cc.p(60, 50));
|
||||
s3.setPosition(cc.p(70, 50));
|
||||
s4.setPosition(cc.p(80, 50));
|
||||
s5.setPosition(cc.p(90, 50));
|
||||
s6.setPosition(cc.p(100, 50));
|
||||
|
||||
s7.setPosition(cc.p(50, 180));
|
||||
s8.setPosition(cc.p(60, 180));
|
||||
s9.setPosition(cc.p(70, 180));
|
||||
s10.setPosition(cc.p(80, 180));
|
||||
s11.setPosition(cc.p(90, 180));
|
||||
s12.setPosition(cc.p(100, 180));
|
||||
|
||||
s13.setPosition(cc.p(50, 270));
|
||||
s14.setPosition(cc.p(60, 270));
|
||||
s15.setPosition(cc.p(70, 270));
|
||||
|
||||
this.addChild(bg);
|
||||
|
||||
this.addChild(s1);
|
||||
this.addChild(s2);
|
||||
this.addChild(s3);
|
||||
this.addChild(s4);
|
||||
this.addChild(s5);
|
||||
this.addChild(s6);
|
||||
this.addChild(s7);
|
||||
this.addChild(s8);
|
||||
this.addChild(s9);
|
||||
this.addChild(s10);
|
||||
this.addChild(s11);
|
||||
this.addChild(s12);
|
||||
this.addChild(s13);
|
||||
this.addChild(s14);
|
||||
this.addChild(s15);
|
||||
},
|
||||
loadingCallBack:function (obj) {
|
||||
++this._numberOfLoadedSprites;
|
||||
this._labelPercent = (this._numberOfLoadedSprites / this._numberOfSprites) * 100;
|
||||
if (this._numberOfLoadedSprites == this._numberOfSprites) {
|
||||
this.removeChild(this._labelLoading, true);
|
||||
this.removeChild(this._labelPercent, true);
|
||||
this.addSprite();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var TextureCacheTestScene = TestScene.extend({
|
||||
runThisTest:function () {
|
||||
var layer = new TextureCacheTest();
|
||||
this.addChild(layer);
|
||||
cc.Director.getInstance().replaceScene(this);
|
||||
}
|
||||
});
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,121 @@
|
|||
/****************************************************************************
|
||||
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 HIGH_PLAYER = 0;
|
||||
var LOW_PLAYER = 1;
|
||||
var STATUS_BAR_HEIGHT = 20.0;
|
||||
var SPRITE_TAG = 0;
|
||||
|
||||
var TouchesTestScene = TestScene.extend({
|
||||
ctor:function () {
|
||||
// this._super(true);
|
||||
var pongLayer = new PongLayer();
|
||||
this.addChild(pongLayer);
|
||||
},
|
||||
runThisTest:function () {
|
||||
cc.Director.getInstance().replaceScene(this);
|
||||
},
|
||||
MainMenuCallback:function (sender) {
|
||||
this._super(sender);
|
||||
}
|
||||
});
|
||||
|
||||
var PongLayer = cc.Layer.extend({
|
||||
_ball:null,
|
||||
_paddles:[],
|
||||
_ballStartingVelocity:cc.p(0,0),
|
||||
_winSize:null,
|
||||
|
||||
ctor:function () {
|
||||
cc.associateWithNative( this, cc.Layer );
|
||||
this.init();
|
||||
},
|
||||
init:function () {
|
||||
this._ballStartingVelocity = cc.p(20.0, -100.0);
|
||||
this._winSize = cc.Director.getInstance().getWinSize();
|
||||
log(Ball);
|
||||
|
||||
this._ball = Ball.ballWithTexture(cc.TextureCache.getInstance().addImage(s_ball));
|
||||
this._ball.setPosition(cc.p(this._winSize.width / 2, this._winSize.height / 2));
|
||||
this._ball.setVelocity(this._ballStartingVelocity);
|
||||
this.addChild(this._ball);
|
||||
|
||||
var paddleTexture = cc.TextureCache.getInstance().addImage(s_paddle);
|
||||
|
||||
this._paddles = [];
|
||||
|
||||
var paddle = Paddle.paddleWithTexture(paddleTexture);
|
||||
paddle.setPosition(cc.p(this._winSize.width / 2, 15));
|
||||
this._paddles.push(paddle);
|
||||
|
||||
paddle = Paddle.paddleWithTexture(paddleTexture);
|
||||
paddle.setPosition(cc.p(this._winSize.width / 2, this._winSize.height - STATUS_BAR_HEIGHT - 15));
|
||||
this._paddles.push(paddle);
|
||||
|
||||
paddle = Paddle.paddleWithTexture(paddleTexture);
|
||||
paddle.setPosition(cc.p(this._winSize.width / 2, 100));
|
||||
this._paddles.push(paddle);
|
||||
|
||||
paddle = Paddle.paddleWithTexture(paddleTexture);
|
||||
paddle.setPosition(cc.p(this._winSize.width / 2, this._winSize.height - STATUS_BAR_HEIGHT - 100));
|
||||
this._paddles.push(paddle);
|
||||
|
||||
for (var i = 0; i < this._paddles.length; i++) {
|
||||
if (!this._paddles[i])
|
||||
break;
|
||||
|
||||
this.addChild(this._paddles[i]);
|
||||
}
|
||||
|
||||
this.schedule(this.doStep);
|
||||
},
|
||||
resetAndScoreBallForPlayer:function (player) {
|
||||
if (Math.abs(this._ball.getVelocity().y) < 300) {
|
||||
this._ballStartingVelocity = cc.pMult(this._ballStartingVelocity, -1.1);
|
||||
} else {
|
||||
this._ballStartingVelocity = cc.pMult(this._ballStartingVelocity, -1);
|
||||
}
|
||||
this._ball.setVelocity(this._ballStartingVelocity);
|
||||
this._ball.setPosition(cc.p(this._winSize.width / 2, this._winSize.height / 2));
|
||||
|
||||
// TODO -- scoring
|
||||
},
|
||||
doStep:function (delta) {
|
||||
this._ball.move(delta);
|
||||
|
||||
for (var i = 0; i < this._paddles.length; i++) {
|
||||
if (!this._paddles[i])
|
||||
break;
|
||||
|
||||
this._ball.collideWithPaddle(this._paddles[i]);
|
||||
}
|
||||
|
||||
if (this._ball.getPosition().y > this._winSize.height - STATUS_BAR_HEIGHT + this._ball.radius())
|
||||
this.resetAndScoreBallForPlayer(LOW_PLAYER);
|
||||
else if (this._ball.getPosition().y < -this._ball.radius())
|
||||
this.resetAndScoreBallForPlayer(HIGH_PLAYER);
|
||||
this._ball.draw();
|
||||
}
|
||||
});
|
|
@ -0,0 +1,491 @@
|
|||
/****************************************************************************
|
||||
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.
|
||||
****************************************************************************/
|
||||
TRANSITION_DURATION = 1.2;
|
||||
|
||||
var TransitionsTests = [
|
||||
{title:"JumpZoomTransition", transitionFunc:function (t, s) {
|
||||
return new JumpZoomTransition(t, s);
|
||||
}},
|
||||
|
||||
{title:"TransitionProgressRadialCCW", transitionFunc:function (t, s) {
|
||||
return cc.TransitionProgressRadialCCW.create(t, s);
|
||||
}},
|
||||
|
||||
{title:"TransitionProgressRadialCW", transitionFunc:function (t, s) {
|
||||
return cc.TransitionProgressRadialCW.create(t, s);
|
||||
}},
|
||||
|
||||
{title:"TransitionProgressHorizontal", transitionFunc:function (t, s) {
|
||||
return cc.TransitionProgressHorizontal.create(t, s);
|
||||
}},
|
||||
|
||||
{title:"TransitionProgressVertical", transitionFunc:function (t, s) {
|
||||
return cc.TransitionProgressVertical.create(t, s);
|
||||
}},
|
||||
|
||||
{title:"TransitionProgressInOut", transitionFunc:function (t, s) {
|
||||
return cc.TransitionProgressInOut.create(t, s);
|
||||
}},
|
||||
|
||||
{title:"TransitionProgressOutIn", transitionFunc:function (t, s) {
|
||||
return cc.TransitionProgressOutIn.create(t, s);
|
||||
}},
|
||||
|
||||
//ok
|
||||
{title:"FadeTransition", transitionFunc:function (t, s) {
|
||||
return new FadeTransition(t, s);
|
||||
}},
|
||||
{title:"FadeWhiteTransition", transitionFunc:function (t, s) {
|
||||
return new FadeWhiteTransition(t, s);
|
||||
}},
|
||||
|
||||
/*function(t,s){ return new FlipXLeftOver(t,s);},
|
||||
function(t,s){ return new FlipXRightOver(t,s);},
|
||||
function(t,s){ return new FlipYUpOver(t,s);},
|
||||
function(t,s){ return new FlipYDownOver(t,s);},
|
||||
function(t,s){ return new FlipAngularLeftOver(t,s);},
|
||||
function(t,s){ return new FlipAngularRightOver(t,s);},
|
||||
function(t,s){ return new ZoomFlipXLeftOver(t,s);},
|
||||
function(t,s){ return new ZoomFlipXRightOver(t,s);},
|
||||
function(t,s){ return new ZoomFlipYUpOver(t,s);},
|
||||
function(t,s){ return new ZoomFlipYDownOver(t,s);},
|
||||
function(t,s){ return new ZoomFlipAngularLeftOver(t,s);},
|
||||
function(t,s){ return new ZoomFlipAngularRightOver(t,s);},*/
|
||||
|
||||
{title:"ShrinkGrowTransition", transitionFunc:function (t, s) {
|
||||
return new ShrinkGrowTransition(t, s);
|
||||
}},
|
||||
{title:"RotoZoomTransition", transitionFunc:function (t, s) {
|
||||
return new RotoZoomTransition(t, s);
|
||||
}},
|
||||
{title:"MoveInLTransition", transitionFunc:function (t, s) {
|
||||
return new MoveInLTransition(t, s);
|
||||
}},
|
||||
{title:"MoveInRTransition", transitionFunc:function (t, s) {
|
||||
return new MoveInRTransition(t, s);
|
||||
}},
|
||||
{title:"MoveInTTransition", transitionFunc:function (t, s) {
|
||||
return new MoveInTTransition(t, s);
|
||||
}},
|
||||
{title:"MoveInBTransition", transitionFunc:function (t, s) {
|
||||
return new MoveInBTransition(t, s);
|
||||
}},
|
||||
{title:"SlideInLTransition", transitionFunc:function (t, s) {
|
||||
return new SlideInLTransition(t, s);
|
||||
}},
|
||||
{title:"SlideInRTransition", transitionFunc:function (t, s) {
|
||||
return new SlideInRTransition(t, s);
|
||||
}},
|
||||
{title:"SlideInTTransition", transitionFunc:function (t, s) {
|
||||
return new SlideInTTransition(t, s);
|
||||
}},
|
||||
{title:"SlideInBTransition", transitionFunc:function (t, s) {
|
||||
return new SlideInBTransition(t, s);
|
||||
}}
|
||||
|
||||
/*function(t,s){ return new CCTransitionCrossFade(t,s);},
|
||||
function(t,s){ return new CCTransitionRadialCCW(t,s);},
|
||||
function(t,s){ return new CCTransitionRadialCW(t,s);},*/
|
||||
|
||||
/*function(t,s){ return new PageTransitionForward(t,s);},
|
||||
function(t,s){ return new PageTransitionBackward(t,s);},
|
||||
function(t,s){ return new FadeTRTransition(t,s);},
|
||||
function(t,s){ return new FadeBLTransition(t,s);},
|
||||
function(t,s){ return new FadeUpTransition(t,s);},
|
||||
function(t,s){ return new FadeDownTransition(t,s);},
|
||||
function(t,s){ return new TurnOffTilesTransition(t,s);},
|
||||
function(t,s){ return new SplitRowsTransition(t,s);},
|
||||
function(t,s){ return new SplitColsTransition(t,s);}*/
|
||||
];
|
||||
|
||||
var transitionsIdx = 0;
|
||||
|
||||
// the class inherit from TestScene
|
||||
// every .Scene each test used must inherit from TestScene,
|
||||
// make sure the test have the menu item for back to main menu
|
||||
var TransitionsTestScene = TestScene.extend({
|
||||
runThisTest:function () {
|
||||
var layer = new TestLayer1();
|
||||
this.addChild(layer);
|
||||
cc.Director.getInstance().replaceScene(this);
|
||||
}
|
||||
});
|
||||
|
||||
var TestLayer1 = cc.Layer.extend({
|
||||
ctor:function () {
|
||||
this._super();
|
||||
//this.init();
|
||||
var x, y;
|
||||
var size = cc.Director.getInstance().getWinSize();
|
||||
x = size.width;
|
||||
y = size.height;
|
||||
|
||||
var bg1 = cc.Sprite.create(s_back1);
|
||||
bg1.setPosition(cc.p(size.width / 2, size.height / 2));
|
||||
bg1.setScale(1.7);
|
||||
this.addChild(bg1, -1);
|
||||
|
||||
var title = cc.LabelTTF.create(TransitionsTests[transitionsIdx].title, "Thonburi", 32);
|
||||
this.addChild(title);
|
||||
title.setColor(cc.c3b(255, 32, 32));
|
||||
title.setPosition(cc.p(x / 2, y - 100));
|
||||
|
||||
var label = cc.LabelTTF.create("SCENE 1", "Marker Felt", 38);
|
||||
label.setColor(cc.c3b(16, 16, 255));
|
||||
label.setPosition(cc.p(x / 2, y / 2));
|
||||
this.addChild(label);
|
||||
|
||||
// menu
|
||||
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);
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3, null);
|
||||
|
||||
menu.setPosition(cc.p(0,0));
|
||||
item1.setPosition(cc.p(size.width / 2 - item2.getContentSize().width * 2, item2.getContentSize().height / 2));
|
||||
item2.setPosition(cc.p(size.width / 2, item2.getContentSize().height / 2));
|
||||
item3.setPosition(cc.p(size.width / 2 + item2.getContentSize().width * 2, item2.getContentSize().height / 2));
|
||||
this.addChild(menu, 1);
|
||||
this.schedule(this.step, 1.0);
|
||||
|
||||
},
|
||||
restartCallback:function (sender) {
|
||||
var s = new TransitionsTestScene();
|
||||
|
||||
var layer = new TestLayer2();
|
||||
s.addChild(layer);
|
||||
var scene = TransitionsTests[transitionsIdx].transitionFunc(TRANSITION_DURATION, s);
|
||||
|
||||
if (scene) {
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
}
|
||||
},
|
||||
nextCallback:function (sender) {
|
||||
transitionsIdx++;
|
||||
transitionsIdx = transitionsIdx % TransitionsTests.length;
|
||||
|
||||
var s = new TransitionsTestScene();
|
||||
|
||||
var layer = new TestLayer2();
|
||||
s.addChild(layer);
|
||||
|
||||
var scene = TransitionsTests[transitionsIdx].transitionFunc(TRANSITION_DURATION, s);
|
||||
if (scene) {
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
}
|
||||
},
|
||||
backCallback:function (sender) {
|
||||
transitionsIdx--;
|
||||
if (transitionsIdx < 0)
|
||||
transitionsIdx += TransitionsTests.length;
|
||||
|
||||
var s = new TransitionsTestScene();
|
||||
var layer = new TestLayer2();
|
||||
s.addChild(layer);
|
||||
|
||||
var scene = TransitionsTests[transitionsIdx].transitionFunc(TRANSITION_DURATION, s);
|
||||
if (scene) {
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
}
|
||||
},
|
||||
|
||||
step:function (dt) {
|
||||
},
|
||||
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
cc.log("Scene 1 onEnter");
|
||||
},
|
||||
onEnterTransitionDidFinish:function () {
|
||||
this._super();
|
||||
cc.log("Scene 1 onEnterTransitionDidFinish");
|
||||
},
|
||||
|
||||
onExitTransitionDidStart:function () {
|
||||
this._super();
|
||||
cc.log("Scene 1 onExitTransitionDidStart");
|
||||
},
|
||||
|
||||
onExit:function () {
|
||||
this._super();
|
||||
cc.log("Scene 1 onExit");
|
||||
}
|
||||
});
|
||||
|
||||
var TestLayer2 = cc.Layer.extend({
|
||||
ctor:function () {
|
||||
this._super();
|
||||
//this.init();
|
||||
var x, y;
|
||||
var size = cc.Director.getInstance().getWinSize();
|
||||
x = size.width;
|
||||
y = size.height;
|
||||
|
||||
var bg1 = cc.Sprite.create(s_back2);
|
||||
bg1.setPosition(cc.p(size.width / 2, size.height / 2));
|
||||
bg1.setScale(1.7);
|
||||
this.addChild(bg1, -1);
|
||||
|
||||
var title = cc.LabelTTF.create(TransitionsTests[transitionsIdx].title, "Thonburi", 32);
|
||||
this.addChild(title);
|
||||
title.setColor(cc.c3b(255, 32, 32));
|
||||
title.setPosition(cc.p(x / 2, y - 100));
|
||||
|
||||
var label = cc.LabelTTF.create("SCENE 2", "Marker Felt", 38);
|
||||
label.setColor(cc.c3b(16, 16, 255));
|
||||
label.setPosition(cc.p(x / 2, y / 2));
|
||||
this.addChild(label);
|
||||
|
||||
// menu
|
||||
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);
|
||||
|
||||
var menu = cc.Menu.create(item1, item2, item3, null);
|
||||
|
||||
menu.setPosition(cc.p(0,0));
|
||||
item1.setPosition(cc.p(size.width / 2 - item2.getContentSize().width * 2, item2.getContentSize().height / 2));
|
||||
item2.setPosition(cc.p(size.width / 2, item2.getContentSize().height / 2));
|
||||
item3.setPosition(cc.p(size.width / 2 + item2.getContentSize().width * 2, item2.getContentSize().height / 2));
|
||||
|
||||
this.addChild(menu, 1);
|
||||
|
||||
this.schedule(this.step, 1.0);
|
||||
},
|
||||
restartCallback:function (sender) {
|
||||
var s = new TransitionsTestScene();
|
||||
|
||||
var layer = new TestLayer1();
|
||||
s.addChild(layer);
|
||||
|
||||
var scene = TransitionsTests[transitionsIdx].transitionFunc(TRANSITION_DURATION, s);
|
||||
if (scene) {
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
}
|
||||
},
|
||||
nextCallback:function (sender) {
|
||||
transitionsIdx++;
|
||||
transitionsIdx = transitionsIdx % TransitionsTests.length;
|
||||
|
||||
var s = new TransitionsTestScene();
|
||||
|
||||
var layer = new TestLayer1();
|
||||
s.addChild(layer);
|
||||
|
||||
var scene = TransitionsTests[transitionsIdx].transitionFunc(TRANSITION_DURATION, s);
|
||||
if (scene) {
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
}
|
||||
},
|
||||
backCallback:function (sender) {
|
||||
transitionsIdx--;
|
||||
if (transitionsIdx < 0)
|
||||
transitionsIdx += TransitionsTests.length;
|
||||
|
||||
var s = new TransitionsTestScene();
|
||||
|
||||
var layer = new TestLayer1();
|
||||
s.addChild(layer);
|
||||
|
||||
var scene = TransitionsTests[transitionsIdx].transitionFunc(TRANSITION_DURATION, s);
|
||||
if (scene) {
|
||||
cc.Director.getInstance().replaceScene(scene);
|
||||
}
|
||||
},
|
||||
|
||||
step:function (dt) {
|
||||
|
||||
},
|
||||
|
||||
onEnter:function () {
|
||||
this._super();
|
||||
cc.log("Scene 2 onEnter");
|
||||
},
|
||||
onEnterTransitionDidFinish:function () {
|
||||
this._super();
|
||||
cc.log("Scene 2 onEnterTransitionDidFinish");
|
||||
},
|
||||
|
||||
onExitTransitionDidStart:function () {
|
||||
this._super();
|
||||
cc.log("Scene 2 onExitTransitionDidStart");
|
||||
},
|
||||
|
||||
onExit:function () {
|
||||
this._super();
|
||||
cc.log("Scene 2 onExit");
|
||||
}
|
||||
});
|
||||
|
||||
var JumpZoomTransition = function (t, s) {
|
||||
return cc.TransitionJumpZoom.create(t, s);
|
||||
};
|
||||
var FadeTransition = function (t, s) {
|
||||
return cc.TransitionFade.create(t, s);
|
||||
};
|
||||
|
||||
var FadeWhiteTransition = function (t, s) {
|
||||
return cc.TransitionFade.create(t, s, cc.white());
|
||||
};
|
||||
|
||||
var FlipXLeftOver = function (t, s) {
|
||||
return cc.TransitionFlipX.create(t, s, cc.ORIENTATION_LEFT_OVER);
|
||||
};
|
||||
|
||||
var FlipXRightOver = function (t, s) {
|
||||
return cc.TransitionFlipX.create(t, s, cc.ORIENTATION_RIGHT_OVER);
|
||||
};
|
||||
|
||||
var FlipYUpOver = function (t, s) {
|
||||
return cc.TransitionFlipY.create(t, s, cc.ORIENTATION_UP_OVER);
|
||||
};
|
||||
|
||||
var FlipYDownOver = function (t, s) {
|
||||
return cc.TransitionFlipY.create(t, s, cc.ORIENTATION_DOWN_OVER);
|
||||
};
|
||||
|
||||
var FlipAngularLeftOver = function (t, s) {
|
||||
return cc.TransitionFlipAngular.create(t, s, cc.ORIENTATION_LEFT_OVER);
|
||||
};
|
||||
|
||||
var FlipAngularRightOver = function (t, s) {
|
||||
return cc.TransitionFlipAngular.create(t, s, cc.ORIENTATION_RIGHT_OVER);
|
||||
};
|
||||
|
||||
var ZoomFlipXLeftOver = function (t, s) {
|
||||
return cc.TransitionZoomFlipX.create(t, s, cc.ORIENTATION_LEFT_OVER);
|
||||
};
|
||||
|
||||
var ZoomFlipXRightOver = function (t, s) {
|
||||
return cc.TransitionZoomFlipX.create(t, s, cc.ORIENTATION_RIGHT_OVER);
|
||||
};
|
||||
|
||||
var ZoomFlipYUpOver = function (t, s) {
|
||||
return cc.TransitionZoomFlipY.create(t, s, cc.ORIENTATION_UP_OVER);
|
||||
};
|
||||
|
||||
var ZoomFlipYDownOver = function (t, s) {
|
||||
return cc.TransitionZoomFlipY.create(t, s, cc.ORIENTATION_DOWN_OVER);
|
||||
};
|
||||
|
||||
var ZoomFlipAngularLeftOver = function (t, s) {
|
||||
return cc.TransitionZoomFlipAngular.create(t, s, cc.ORIENTATION_LEFT_OVER);
|
||||
};
|
||||
|
||||
var ZoomFlipAngularRightOver = function (t, s) {
|
||||
return cc.TransitionZoomFlipAngular.create(t, s, cc.ORIENTATION_RIGHT_OVER);
|
||||
};
|
||||
|
||||
var ShrinkGrowTransition = function (t, s) {
|
||||
return cc.TransitionShrinkGrow.create(t, s);
|
||||
};
|
||||
|
||||
var RotoZoomTransition = function (t, s) {
|
||||
return cc.TransitionRotoZoom.create(t, s);
|
||||
};
|
||||
|
||||
var MoveInLTransition = function (t, s) {
|
||||
return cc.TransitionMoveInL.create(t, s);
|
||||
};
|
||||
|
||||
var MoveInRTransition = function (t, s) {
|
||||
return cc.TransitionMoveInR.create(t, s);
|
||||
};
|
||||
|
||||
var MoveInTTransition = function (t, s) {
|
||||
return cc.TransitionMoveInT.create(t, s);
|
||||
};
|
||||
|
||||
var MoveInBTransition = function (t, s) {
|
||||
return cc.TransitionMoveInB.create(t, s);
|
||||
};
|
||||
|
||||
var SlideInLTransition = function (t, s) {
|
||||
return cc.TransitionSlideInL.create(t, s);
|
||||
};
|
||||
|
||||
var SlideInRTransition = function (t, s) {
|
||||
return cc.TransitionSlideInR.create(t, s);
|
||||
};
|
||||
|
||||
var SlideInTTransition = function (t, s) {
|
||||
return cc.TransitionSlideInT.create(t, s);
|
||||
};
|
||||
|
||||
var SlideInBTransition = function (t, s) {
|
||||
return cc.TransitionSlideInB.create(t, s);
|
||||
};
|
||||
|
||||
var CCTransitionCrossFade = function (t, s) {
|
||||
return cc.TransitionCrossFade.create(t, s);
|
||||
};
|
||||
|
||||
var CCTransitionRadialCCW = function (t, s) {
|
||||
return cc.TransitionRadialCCW.create(t, s);
|
||||
};
|
||||
|
||||
var CCTransitionRadialCW = function (t, s) {
|
||||
return cc.TransitionRadialCW.create(t, s);
|
||||
};
|
||||
|
||||
var PageTransitionForward = function (t, s) {
|
||||
cc.Director.getInstance().setDepthTest(true);
|
||||
return cc.TransitionPageTurn.create(t, s, false);
|
||||
};
|
||||
|
||||
var PageTransitionBackward = function (t, s) {
|
||||
cc.Director.getInstance().setDepthTest(true);
|
||||
return cc.TransitionPageTurn.create(t, s, true);
|
||||
};
|
||||
|
||||
var FadeTRTransition = function (t, s) {
|
||||
return cc.TransitionFadeTR.create(t, s);
|
||||
};
|
||||
|
||||
var FadeBLTransition = function (t, s) {
|
||||
return cc.TransitionFadeBL.create(t, s);
|
||||
};
|
||||
|
||||
var FadeUpTransition = function (t, s) {
|
||||
return cc.TransitionFadeUp.create(t, s);
|
||||
};
|
||||
|
||||
var FadeDownTransition = function (t, s) {
|
||||
return cc.TransitionFadeDown.create(t, s);
|
||||
};
|
||||
|
||||
var TurnOffTilesTransition = function (t, s) {
|
||||
return cc.TransitionTurnOffTiles.create(t, s);
|
||||
};
|
||||
|
||||
var SplitRowsTransition = function (t, s) {
|
||||
return cc.TransitionSplitRows.create(t, s);
|
||||
};
|
||||
|
||||
var SplitColsTransition = function (t, s) {
|
||||
return cc.TransitionSplitCols.create(t, s);
|
||||
};
|
|
@ -0,0 +1,9 @@
|
|||
//
|
||||
// Javascript Bindigns helper file
|
||||
//
|
||||
|
||||
// DO NOT ALTER THE ORDER
|
||||
require('jsb_constants_cocos2d.js');
|
||||
//require('jsb_constants_chipmunk.js');
|
||||
require('jsb_constants_gl.js');
|
||||
//require('jsb_constants_cocosbuilder.js');
|
|
@ -0,0 +1,253 @@
|
|||
//
|
||||
// Chipmunk defines
|
||||
//
|
||||
|
||||
cp.v = cc.p;
|
||||
cp._v = cc._p;
|
||||
cp.vzero = cp.v(0,0);
|
||||
|
||||
// Vector: Compatibility with Chipmunk-JS
|
||||
cp.v.add = cp.vadd;
|
||||
cp.v.clamp = cp.vclamp;
|
||||
cp.v.cross = cp.vcross;
|
||||
cp.v.dist = cp.vdist;
|
||||
cp.v.distsq = cp.vdistsq;
|
||||
cp.v.dot = cp.vdot;
|
||||
cp.v.eql = cp.veql;
|
||||
cp.v.forangle = cp.vforangle;
|
||||
cp.v.len = cp.vlength;
|
||||
cp.v.lengthsq = cp.vlengthsq;
|
||||
cp.v.lerp = cp.vlerp;
|
||||
cp.v.lerpconst = cp.vlerpconst;
|
||||
cp.v.mult = cp.vmult;
|
||||
cp.v.near = cp.vnear;
|
||||
cp.v.neg = cp.vneg;
|
||||
cp.v.normalize = cp.vnormalize;
|
||||
cp.v.normalize_safe = cp.vnormalize_safe;
|
||||
cp.v.perp = cp.vperp;
|
||||
cp.v.project = cp.vproject;
|
||||
cp.v.rotate = cp.vrotate;
|
||||
cp.v.rperp = cp.vrperp;
|
||||
cp.v.slerp = cp.vslerp;
|
||||
cp.v.slerpconst = cp.vslerpconst;
|
||||
cp.v.sub = cp.vsub;
|
||||
cp.v.toangle = cp.vtoangle;
|
||||
cp.v.unrotate = cp.vunrotate;
|
||||
|
||||
|
||||
|
||||
/// Initialize an offset box shaped polygon shape.
|
||||
cp.BoxShape2 = function(body, box)
|
||||
{
|
||||
var verts = [
|
||||
box.l, box.b,
|
||||
box.l, box.t,
|
||||
box.r, box.t,
|
||||
box.r, box.b
|
||||
];
|
||||
|
||||
return new cp.PolyShape(body, verts, cp.vzero);
|
||||
};
|
||||
|
||||
/// Initialize a box shaped polygon shape.
|
||||
cp.BoxShape = function(body, width, height)
|
||||
{
|
||||
var hw = width/2;
|
||||
var hh = height/2;
|
||||
|
||||
return cp.BoxShape2(body, new cp.BB(-hw, -hh, hw, hh));
|
||||
};
|
||||
|
||||
|
||||
/// Initialize an static body
|
||||
cp.BodyStatic = function()
|
||||
{
|
||||
return new cp.Body(Infinity, Infinity);
|
||||
};
|
||||
|
||||
|
||||
// "Bounding Box" compatibility with Chipmunk-JS
|
||||
cp.BB = function(l, b, r, t)
|
||||
{
|
||||
return {l:l, b:b, r:r, t:t};
|
||||
};
|
||||
|
||||
// helper function to create a BB
|
||||
cp.bb = function(l, b, r, t) {
|
||||
return new cp.BB(l, b, r, t);
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Some properties
|
||||
//
|
||||
// "handle" needed in some cases
|
||||
Object.defineProperties(cp.Base.prototype,
|
||||
{
|
||||
"handle" : {
|
||||
get : function(){
|
||||
return this.getHandle();
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
}
|
||||
});
|
||||
|
||||
// Properties, for Chipmunk-JS compatibility
|
||||
// Space properties
|
||||
Object.defineProperties(cp.Space.prototype,
|
||||
{
|
||||
"gravity" : {
|
||||
get : function(){
|
||||
return this.getGravity();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setGravity(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"iterations" : {
|
||||
get : function(){
|
||||
return this.getIterations();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setIterations(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"damping" : {
|
||||
get : function(){
|
||||
return this.getDamping();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setDamping(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"staticBody" : {
|
||||
get : function(){
|
||||
return this.getStaticBody();
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"idleSpeedThreshold" : {
|
||||
get : function(){
|
||||
return this.getIdleSpeedThreshold();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setIdleSpeedThreshold(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"sleepTimeThreshold": {
|
||||
get : function(){
|
||||
return this.getSleepTimeThreshold();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setSleepTimeThreshold(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"collisionSlop": {
|
||||
get : function(){
|
||||
return this.getCollisionSlop();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setCollisionSlop(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"collisionBias": {
|
||||
get : function(){
|
||||
return this.getCollisionBias();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setCollisionBias(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"collisionPersistence": {
|
||||
get : function(){
|
||||
return this.getCollisionPersistence();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setCollisionPersistence(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"enableContactGraph": {
|
||||
get : function(){
|
||||
return this.getEnableContactGraph();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setEnableContactGraph(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
}
|
||||
});
|
||||
|
||||
// Body properties
|
||||
Object.defineProperties(cp.Body.prototype,
|
||||
{
|
||||
"a" : {
|
||||
get : function(){
|
||||
return this.getAngle();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setAngle(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"w" : {
|
||||
get : function(){
|
||||
return this.getAngVel();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setAngVel(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"p" : {
|
||||
get : function(){
|
||||
return this.getPos();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setPos(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"v" : {
|
||||
get : function(){
|
||||
return this.getVel();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setVel(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"i" : {
|
||||
get : function(){
|
||||
return this.getMoment();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setMoment(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
}
|
||||
|
||||
});
|
|
@ -0,0 +1,344 @@
|
|||
//
|
||||
// cocos2d constants
|
||||
//
|
||||
|
||||
//
|
||||
// Point
|
||||
//
|
||||
cc.p = function( x, y )
|
||||
{
|
||||
return {x:x, y:y};
|
||||
};
|
||||
cc.g = cc.p;
|
||||
cc.log = cc.log || log;
|
||||
cc.DIRECTOR_PROJECTION_2D = 0;
|
||||
cc.DIRECTOR_PROJECTION_3D = 1;
|
||||
|
||||
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 = {r:255, g:0, b:0};
|
||||
cc.GREEN = {r:0, g:255, b:0};
|
||||
cc.BLUE = {r:0, g:0, b:255};
|
||||
cc.BLACK = {r:0, g:0, b:0};
|
||||
cc.WHITE = {r:255, g:255, b: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 = {r:255, g:255, b:255 };
|
||||
cc._reuse_color4b = {r:255, g:255, b:255, a:255 };
|
||||
cc._reuse_grid = cc.g(0,0);
|
||||
|
||||
//
|
||||
// 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;
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Color 4F
|
||||
//
|
||||
cc.c4f = function( r, g, b, a )
|
||||
{
|
||||
return {r:r, g:g, b:b, a:a };
|
||||
};
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Grid
|
||||
//
|
||||
cc._g = function( x, y )
|
||||
{
|
||||
cc._reuse_grid.x = x;
|
||||
cc._reuse_grid.y = y;
|
||||
return cc._reuse_grid;
|
||||
};
|
||||
|
||||
//
|
||||
// Size
|
||||
//
|
||||
cc.size = function(w,h)
|
||||
{
|
||||
return {width:w, height:h};
|
||||
};
|
||||
|
||||
//
|
||||
// Rect
|
||||
//
|
||||
cc.rect = function(x,y,w,h)
|
||||
{
|
||||
return {x:x, y:y, width:w, height:h};
|
||||
};
|
||||
|
||||
|
||||
// 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] );
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// MenuItemToggle
|
||||
//
|
||||
cc.MenuItemToggle.create = function( /* var args */) {
|
||||
|
||||
var n = arguments.length;
|
||||
|
||||
if (typeof arguments[n-1] === 'function') {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var func = args.pop();
|
||||
var obj = args.pop();
|
||||
|
||||
// create it with arguments,
|
||||
var item = cc.MenuItemToggle._create.apply(this, args);
|
||||
|
||||
// then set the callback
|
||||
item.setCallback(obj, func);
|
||||
return item;
|
||||
} else {
|
||||
return cc.MenuItemToggle._create.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Associates a base class with a native superclass
|
||||
* @function
|
||||
* @param {object} jsobj subclass
|
||||
* @param {object} klass superclass
|
||||
*/
|
||||
cc.associateWithNative = function( jsobj, superclass ) {
|
||||
var native = new superclass();
|
||||
__associateObjWithNative( jsobj, native );
|
||||
};
|
||||
|
||||
|
||||
// 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-html5 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.Node.extend = cc.Class.extend;
|
||||
cc.Layer.extend = cc.Class.extend;
|
||||
cc.LayerGradient.extend = cc.Class.extend;
|
||||
cc.LayerColor.extend = cc.Class.extend;
|
||||
cc.Sprite.extend = cc.Class.extend;
|
||||
cc.MenuItemFont.extend = cc.Class.extend;
|
||||
cc.Scene.extend = cc.Class.extend;
|
|
@ -0,0 +1,118 @@
|
|||
//
|
||||
// CocosBuilder definitions
|
||||
//
|
||||
|
||||
cc.Reader = {};
|
||||
|
||||
var _ccbGlobalContext = this;
|
||||
|
||||
cc.Reader.load = function(file, owner, parentSize)
|
||||
{
|
||||
// Load the node graph using the correct function
|
||||
var reader = cc._Reader.create();
|
||||
var node;
|
||||
|
||||
if (owner && parentSize)
|
||||
{
|
||||
node = reader.load(file, owner, parentSize);
|
||||
}
|
||||
else if (owner)
|
||||
{
|
||||
node = reader.load(file,owner);
|
||||
}
|
||||
else
|
||||
{
|
||||
node = reader.load(file);
|
||||
}
|
||||
|
||||
// Assign owner callbacks & member variables
|
||||
if (owner)
|
||||
{
|
||||
// Callbacks
|
||||
var ownerCallbackNames = reader.getOwnerCallbackNames();
|
||||
var ownerCallbackNodes = reader.getOwnerCallbackNodes();
|
||||
|
||||
for (var i = 0; i < ownerCallbackNames.length; i++)
|
||||
{
|
||||
var callbackName = ownerCallbackNames[i];
|
||||
var callbackNode = ownerCallbackNodes[i];
|
||||
|
||||
callbackNode.setCallback(owner, owner[callbackName]);
|
||||
}
|
||||
|
||||
// Variables
|
||||
var ownerOutletNames = reader.getOwnerOutletNames();
|
||||
var ownerOutletNodes = reader.getOwnerOutletNodes();
|
||||
|
||||
for (var i = 0; i < ownerOutletNames.length; i++)
|
||||
{
|
||||
var outletName = ownerOutletNames[i];
|
||||
var outletNode = ownerOutletNodes[i];
|
||||
|
||||
owner[outletName] = outletNode;
|
||||
}
|
||||
}
|
||||
|
||||
var nodesWithAnimationManagers = reader.getNodesWithAnimationManagers();
|
||||
var animationManagersForNodes = reader.getAnimationManagersForNodes();
|
||||
|
||||
// Attach animation managers to nodes and assign root node callbacks and member variables
|
||||
for (var i = 0; i < nodesWithAnimationManagers.length; i++)
|
||||
{
|
||||
var innerNode = nodesWithAnimationManagers[i];
|
||||
var animationManager = animationManagersForNodes[i];
|
||||
|
||||
innerNode.animationManager = animationManager;
|
||||
|
||||
var documentControllerName = animationManager.getDocumentControllerName();
|
||||
if (!documentControllerName) continue;
|
||||
|
||||
// Create a document controller
|
||||
var controller = new _ccbGlobalContext[documentControllerName]();
|
||||
controller.controllerName = documentControllerName;
|
||||
|
||||
innerNode.controller = controller;
|
||||
controller.rootNode = innerNode;
|
||||
|
||||
// Callbacks
|
||||
var documentCallbackNames = animationManager.getDocumentCallbackNames();
|
||||
var documentCallbackNodes = animationManager.getDocumentCallbackNodes();
|
||||
|
||||
for (var j = 0; j < documentCallbackNames.length; j++)
|
||||
{
|
||||
var callbackName = documentCallbackNames[j];
|
||||
var callbackNode = documentCallbackNodes[j];
|
||||
|
||||
callbackNode.setCallback(controller, controller[callbackName]);
|
||||
}
|
||||
|
||||
|
||||
// Variables
|
||||
var documentOutletNames = animationManager.getDocumentOutletNames();
|
||||
var documentOutletNodes = animationManager.getDocumentOutletNodes();
|
||||
|
||||
for (var j = 0; j < documentOutletNames.length; j++)
|
||||
{
|
||||
var outletName = documentOutletNames[j];
|
||||
var outletNode = documentOutletNodes[j];
|
||||
|
||||
controller[outletName] = outletNode;
|
||||
}
|
||||
|
||||
if (typeof(controller.onDidLoadFromCCB) == "function")
|
||||
{
|
||||
controller.onDidLoadFromCCB();
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
cc.Reader.loadAsScene = function(file, owner, parentSize)
|
||||
{
|
||||
var node = cc.Reader.load(file, owner, parentSize);
|
||||
var scene = cc.Scene.create();
|
||||
scene.addChild( node );
|
||||
|
||||
return scene;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
//
|
||||
// OpenGL defines
|
||||
//
|
||||
|
||||
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;
|
|
@ -0,0 +1 @@
|
|||
3a20f2538a26a05776e330b00abbf48ef1dc42cc
|
|
@ -0,0 +1 @@
|
|||
2aaf84affb08908ea5aa5fd7ce5de973b88109bc
|
|
@ -0,0 +1 @@
|
|||
d19440ea298cab294dea34a8daa96a6067490b25
|
|
@ -0,0 +1 @@
|
|||
a71a0b77382bfe31a77a6a8fd89ca75e71f921bf
|
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
|
@ -0,0 +1 @@
|
|||
0a08f47624fb92eef7de9fed051d92a25e3c6ff8
|
|
@ -0,0 +1 @@
|
|||
365a14b28310b73a048597cc8d87609975705172
|
|
@ -0,0 +1 @@
|
|||
9246a8bc975c764e4aa71f54a50d5f4e4bce7a18
|
|
@ -0,0 +1 @@
|
|||
6869c5352bc6510dba54803f5f4459b0a6a3fcf2
|
|
@ -0,0 +1 @@
|
|||
d13ddb0931c1772127b38010990140adce837bc8
|
|
@ -0,0 +1,282 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>texture</key>
|
||||
<dict>
|
||||
<key>width</key>
|
||||
<integer>512</integer>
|
||||
<key>height</key>
|
||||
<integer>256</integer>
|
||||
</dict>
|
||||
<key>frames</key>
|
||||
<dict>
|
||||
<key>grossini_dance_01.png</key>
|
||||
<dict>
|
||||
<key>x</key>
|
||||
<integer>347</integer>
|
||||
<key>y</key>
|
||||
<integer>1</integer>
|
||||
<key>width</key>
|
||||
<integer>51</integer>
|
||||
<key>height</key>
|
||||
<integer>109</integer>
|
||||
<key>offsetX</key>
|
||||
<real>0</real>
|
||||
<key>offsetY</key>
|
||||
<real>-1</real>
|
||||
<key>originalWidth</key>
|
||||
<integer>85</integer>
|
||||
<key>originalHeight</key>
|
||||
<integer>-121</integer>
|
||||
</dict>
|
||||
<key>grossini_dance_02.png</key>
|
||||
<dict>
|
||||
<key>x</key>
|
||||
<integer>215</integer>
|
||||
<key>y</key>
|
||||
<integer>111</integer>
|
||||
<key>width</key>
|
||||
<integer>63</integer>
|
||||
<key>height</key>
|
||||
<integer>109</integer>
|
||||
<key>offsetX</key>
|
||||
<real>-6</real>
|
||||
<key>offsetY</key>
|
||||
<real>-1</real>
|
||||
<key>originalWidth</key>
|
||||
<integer>85</integer>
|
||||
<key>originalHeight</key>
|
||||
<integer>-121</integer>
|
||||
</dict>
|
||||
<key>grossini_dance_03.png</key>
|
||||
<dict>
|
||||
<key>x</key>
|
||||
<integer>151</integer>
|
||||
<key>y</key>
|
||||
<integer>111</integer>
|
||||
<key>width</key>
|
||||
<integer>63</integer>
|
||||
<key>height</key>
|
||||
<integer>109</integer>
|
||||
<key>offsetX</key>
|
||||
<real>-6</real>
|
||||
<key>offsetY</key>
|
||||
<real>-1</real>
|
||||
<key>originalWidth</key>
|
||||
<integer>85</integer>
|
||||
<key>originalHeight</key>
|
||||
<integer>-121</integer>
|
||||
</dict>
|
||||
<key>grossini_dance_04.png</key>
|
||||
<dict>
|
||||
<key>x</key>
|
||||
<integer>1</integer>
|
||||
<key>y</key>
|
||||
<integer>111</integer>
|
||||
<key>width</key>
|
||||
<integer>74</integer>
|
||||
<key>height</key>
|
||||
<integer>109</integer>
|
||||
<key>offsetX</key>
|
||||
<real>-0.5</real>
|
||||
<key>offsetY</key>
|
||||
<real>-1</real>
|
||||
<key>originalWidth</key>
|
||||
<integer>85</integer>
|
||||
<key>originalHeight</key>
|
||||
<integer>-121</integer>
|
||||
</dict>
|
||||
<key>grossini_dance_05.png</key>
|
||||
<dict>
|
||||
<key>x</key>
|
||||
<integer>76</integer>
|
||||
<key>y</key>
|
||||
<integer>111</integer>
|
||||
<key>width</key>
|
||||
<integer>74</integer>
|
||||
<key>height</key>
|
||||
<integer>109</integer>
|
||||
<key>offsetX</key>
|
||||
<real>-0.5</real>
|
||||
<key>offsetY</key>
|
||||
<real>-1</real>
|
||||
<key>originalWidth</key>
|
||||
<integer>85</integer>
|
||||
<key>originalHeight</key>
|
||||
<integer>-121</integer>
|
||||
</dict>
|
||||
<key>grossini_dance_06.png</key>
|
||||
<dict>
|
||||
<key>x</key>
|
||||
<integer>399</integer>
|
||||
<key>y</key>
|
||||
<integer>1</integer>
|
||||
<key>width</key>
|
||||
<integer>63</integer>
|
||||
<key>height</key>
|
||||
<integer>109</integer>
|
||||
<key>offsetX</key>
|
||||
<real>-6</real>
|
||||
<key>offsetY</key>
|
||||
<real>-1</real>
|
||||
<key>originalWidth</key>
|
||||
<integer>85</integer>
|
||||
<key>originalHeight</key>
|
||||
<integer>-121</integer>
|
||||
</dict>
|
||||
<key>grossini_dance_07.png</key>
|
||||
<dict>
|
||||
<key>x</key>
|
||||
<integer>105</integer>
|
||||
<key>y</key>
|
||||
<integer>1</integer>
|
||||
<key>width</key>
|
||||
<integer>63</integer>
|
||||
<key>height</key>
|
||||
<integer>109</integer>
|
||||
<key>offsetX</key>
|
||||
<real>-6</real>
|
||||
<key>offsetY</key>
|
||||
<real>-1</real>
|
||||
<key>originalWidth</key>
|
||||
<integer>85</integer>
|
||||
<key>originalHeight</key>
|
||||
<integer>-121</integer>
|
||||
</dict>
|
||||
<key>grossini_dance_08.png</key>
|
||||
<dict>
|
||||
<key>x</key>
|
||||
<integer>1</integer>
|
||||
<key>y</key>
|
||||
<integer>1</integer>
|
||||
<key>width</key>
|
||||
<integer>51</integer>
|
||||
<key>height</key>
|
||||
<integer>109</integer>
|
||||
<key>offsetX</key>
|
||||
<real>0</real>
|
||||
<key>offsetY</key>
|
||||
<real>-1</real>
|
||||
<key>originalWidth</key>
|
||||
<integer>85</integer>
|
||||
<key>originalHeight</key>
|
||||
<integer>-121</integer>
|
||||
</dict>
|
||||
<key>grossini_dance_09.png</key>
|
||||
<dict>
|
||||
<key>x</key>
|
||||
<integer>295</integer>
|
||||
<key>y</key>
|
||||
<integer>1</integer>
|
||||
<key>width</key>
|
||||
<integer>51</integer>
|
||||
<key>height</key>
|
||||
<integer>109</integer>
|
||||
<key>offsetX</key>
|
||||
<real>0</real>
|
||||
<key>offsetY</key>
|
||||
<real>-1</real>
|
||||
<key>originalWidth</key>
|
||||
<integer>85</integer>
|
||||
<key>originalHeight</key>
|
||||
<integer>-121</integer>
|
||||
</dict>
|
||||
<key>grossini_dance_10.png</key>
|
||||
<dict>
|
||||
<key>x</key>
|
||||
<integer>232</integer>
|
||||
<key>y</key>
|
||||
<integer>1</integer>
|
||||
<key>width</key>
|
||||
<integer>62</integer>
|
||||
<key>height</key>
|
||||
<integer>109</integer>
|
||||
<key>offsetX</key>
|
||||
<real>5.5</real>
|
||||
<key>offsetY</key>
|
||||
<real>-1</real>
|
||||
<key>originalWidth</key>
|
||||
<integer>85</integer>
|
||||
<key>originalHeight</key>
|
||||
<integer>-121</integer>
|
||||
</dict>
|
||||
<key>grossini_dance_11.png</key>
|
||||
<dict>
|
||||
<key>x</key>
|
||||
<integer>169</integer>
|
||||
<key>y</key>
|
||||
<integer>1</integer>
|
||||
<key>width</key>
|
||||
<integer>62</integer>
|
||||
<key>height</key>
|
||||
<integer>109</integer>
|
||||
<key>offsetX</key>
|
||||
<real>5.5</real>
|
||||
<key>offsetY</key>
|
||||
<real>-1</real>
|
||||
<key>originalWidth</key>
|
||||
<integer>85</integer>
|
||||
<key>originalHeight</key>
|
||||
<integer>-121</integer>
|
||||
</dict>
|
||||
<key>grossini_dance_12.png</key>
|
||||
<dict>
|
||||
<key>x</key>
|
||||
<integer>279</integer>
|
||||
<key>y</key>
|
||||
<integer>111</integer>
|
||||
<key>width</key>
|
||||
<integer>51</integer>
|
||||
<key>height</key>
|
||||
<integer>106</integer>
|
||||
<key>offsetX</key>
|
||||
<real>0</real>
|
||||
<key>offsetY</key>
|
||||
<real>-2.5</real>
|
||||
<key>originalWidth</key>
|
||||
<integer>85</integer>
|
||||
<key>originalHeight</key>
|
||||
<integer>-121</integer>
|
||||
</dict>
|
||||
<key>grossini_dance_13.png</key>
|
||||
<dict>
|
||||
<key>x</key>
|
||||
<integer>53</integer>
|
||||
<key>y</key>
|
||||
<integer>1</integer>
|
||||
<key>width</key>
|
||||
<integer>51</integer>
|
||||
<key>height</key>
|
||||
<integer>109</integer>
|
||||
<key>offsetX</key>
|
||||
<real>0</real>
|
||||
<key>offsetY</key>
|
||||
<real>-1</real>
|
||||
<key>originalWidth</key>
|
||||
<integer>85</integer>
|
||||
<key>originalHeight</key>
|
||||
<integer>-121</integer>
|
||||
</dict>
|
||||
<key>grossini_dance_14.png</key>
|
||||
<dict>
|
||||
<key>x</key>
|
||||
<integer>331</integer>
|
||||
<key>y</key>
|
||||
<integer>111</integer>
|
||||
<key>width</key>
|
||||
<integer>51</integer>
|
||||
<key>height</key>
|
||||
<integer>106</integer>
|
||||
<key>offsetX</key>
|
||||
<real>0</real>
|
||||
<key>offsetY</key>
|
||||
<real>-2.5</real>
|
||||
<key>originalWidth</key>
|
||||
<integer>85</integer>
|
||||
<key>originalHeight</key>
|
||||
<integer>-121</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1 @@
|
|||
aec1c0a8c8068377fddca5ddd32084d8c3c3c419
|
|
@ -0,0 +1 @@
|
|||
38e3a5fabac55b5649842cb35930af7594f093ef
|
|
@ -0,0 +1 @@
|
|||
2685fbcab626d939a8e2ea65b05a8a82beb90afa
|
|
@ -0,0 +1 @@
|
|||
38e3a5fabac55b5649842cb35930af7594f093ef
|
|
@ -0,0 +1 @@
|
|||
2685fbcab626d939a8e2ea65b05a8a82beb90afa
|
|
@ -0,0 +1 @@
|
|||
197f4c7204f12af28120d3506524f0ac051b624d
|
|
@ -0,0 +1 @@
|
|||
197f4c7204f12af28120d3506524f0ac051b624d
|
|
@ -0,0 +1 @@
|
|||
500d95937f3fd81659da66d2099b6c80d988a6b5
|
|
@ -0,0 +1 @@
|
|||
ebb3361a7a53d63ab60931a48bedc3ec8ccfe206
|
|
@ -0,0 +1 @@
|
|||
ab579da81872bb45c6e102dc2dbf6ee9e8082f75
|
|
@ -0,0 +1 @@
|
|||
cce195a8ee10fc4fd7b5acf048ab3e04b0750685
|
|
@ -0,0 +1 @@
|
|||
c2eabd7cd8b62d39967387739fe05799de4ca764
|
|
@ -0,0 +1 @@
|
|||
abc899cd55086105f439df7a6d01db84168aebb5
|
|
@ -0,0 +1 @@
|
|||
9d2adf428a20b8facb57c0b3dc8dd782c74e27ea
|
|
@ -0,0 +1 @@
|
|||
112328fdb03b8966c8cb7b62a5fc51ce0d4570b1
|
|
@ -0,0 +1 @@
|
|||
9975e4961272d5bda6d5f3bbd61ea0fc02222199
|
|
@ -0,0 +1 @@
|
|||
796a33e41fb8a78b122fdf0d8a626510629bbb80
|
|
@ -0,0 +1 @@
|
|||
8d997c0f9ffd94aa8868b58c9edd1b0c667c468a
|
|
@ -0,0 +1 @@
|
|||
ee5dba70cef2d704598a1ada6e1ddce3bc6afb9f
|
|
@ -0,0 +1 @@
|
|||
3988cfdf6548eaab2f408422c470140b7e74f464
|
|
@ -0,0 +1 @@
|
|||
b62acc9fb494f76ea75df3ec90cb0e53a58b9348
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>chinese1</key>
|
||||
<string>美好的一天</string>
|
||||
<key>japanese</key>
|
||||
<string>良い一日を</string>
|
||||
<key>spanish</key>
|
||||
<string>Buen día</string>
|
||||
</dict>
|
||||
</plist>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue