Skip to content

Instantly share code, notes, and snippets.

@darkdukey
Created December 22, 2014 18:22
Show Gist options
  • Save darkdukey/cdbd195a4a8af8ff884c to your computer and use it in GitHub Desktop.
Save darkdukey/cdbd195a4a8af8ff884c to your computer and use it in GitHub Desktop.
Example for Cocos Studio
#include "HelloWorldScene.h"
#include "cocostudio/CocoStudio.h"
#include "ui/CocosGUI.h"
USING_NS_CC;
using namespace cocostudio::timeline;
Scene* HelloWorld::createScene()
{
// 'scene' is an autorelease object
auto scene = Scene::create();
// 'layer' is an autorelease object
auto layer = HelloWorld::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
auto rootNode = CSLoader::createNode("MainScene.csb");
addChild(rootNode);
auto closeItem = rootNode->getChildByName<ui::Button*>("Button_1");
closeItem->addTouchEventListener(CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
return true;
}
void HelloWorld::menuCloseCallback(Ref* pSender)
{
Sprite* testSprite;
addChild(testSprite);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment