示例#1
0
TestLayer2::TestLayer2(const std::string& transitionName)
{
    float x,y;

    auto size = Director::getInstance()->getWinSize();
    x = size.width;
    y = size.height;

    auto bg1 = Sprite::create(s_back2);
    bg1->setPosition( Vec2(size.width/2, size.height/2) );
    addChild(bg1, -1);

    auto title = Label::createWithTTF(transitionName, "fonts/Thonburi.ttf", 32);
    addChild(title);
    title->setColor( Color3B(255,32,32) );
    title->setPosition( Vec2(x/2, y-100) );

    auto label = Label::createWithTTF("SCENE 2", "fonts/Marker Felt.ttf", 38);
    label->setColor( Color3B(16,16,255));
    label->setPosition( Vec2(x/2,y/2));    
    addChild( label);

    schedule(CC_SCHEDULE_SELECTOR(TestLayer2::step), 1.0f);
}
示例#2
0
void ScrollView::onTouchEnded(Touch* touch, Event* event)
{
    if (!this->isVisible())
    {
        return;
    }
    
    auto touchIter = std::find(_touches.begin(), _touches.end(), touch);
    
    if (touchIter != _touches.end())
    {
        if (_touches.size() == 1 && _touchMoved)
        {
            this->schedule(CC_SCHEDULE_SELECTOR(ScrollView::deaccelerateScrolling));
        }
        _touches.erase(touchIter);
    } 

    if (_touches.size() == 0)
    {
        _dragging = false;    
        _touchMoved = false;
    }
}
示例#3
0
//------------------------------------------------------------------
//
// SchedulerUpdate
//
//------------------------------------------------------------------
void SchedulerUpdate::onEnter()
{
    SchedulerTestLayer::onEnter();

    auto d = new (std::nothrow) TestNode();
    d->initWithString("---", 50);
    addChild(d);
    d->release();

    auto b = new (std::nothrow) TestNode();
    b->initWithString("3rd", 0);
    addChild(b);
    b->release();

    auto a = new (std::nothrow) TestNode();
    a->initWithString("1st", -10);
    addChild(a);
    a->release();

    auto c = new (std::nothrow) TestNode();
    c->initWithString("4th", 10);
    addChild(c);
    c->release();

    auto e = new (std::nothrow) TestNode();
    e->initWithString("5th", 20);
    addChild(e);
    e->release();

    auto f = new (std::nothrow) TestNode();
    f->initWithString("2nd", -5);
    addChild(f);
    f->release();

    schedule(CC_SCHEDULE_SELECTOR(SchedulerUpdate::removeUpdates), 4.0f);
}
示例#4
0
//------------------------------------------------------------------
//
// TMXIsoZorderNew
//
//------------------------------------------------------------------
TMXIsoZorderNew::TMXIsoZorderNew()
{
    auto map = cocos2d::experimental::TMXTiledMap::create("TileMaps/iso-test-zorder.tmx");
    addChild(map, 0, kTagTileMap);

    auto s = map->getContentSize();
    CCLOG("ContentSize: %f, %f", s.width,s.height);
    map->setPosition(Vec2(-s.width/2,0));
    
    _tamara = Sprite::create(s_pathSister1);
    map->addChild(_tamara, (int)map->getChildren().size() );
    _tamara->retain();
    int mapWidth = map->getMapSize().width * map->getTileSize().width;
    _tamara->setPosition(CC_POINT_PIXELS_TO_POINTS(Vec2( mapWidth/2,0)));
    _tamara->setAnchorPoint(Vec2(0.5f,0));

    
    auto move = MoveBy::create(10, Vec2(300,250));
    auto back = move->reverse();
    auto seq = Sequence::create(move, back,nullptr);
    _tamara->runAction( RepeatForever::create(seq) );
    
    schedule( CC_SCHEDULE_SELECTOR(TMXIsoZorderNew::repositionSprite) );
}
示例#5
0
void EditorWeapon::startWeaponLoop() {
//    this->scheduleUpdate();
    if(!this->isChild) {
        this->schedule(CC_SCHEDULE_SELECTOR(EditorWeapon::mainLoop));
    }
}
示例#6
0
void SchedulerUpdateFromCustom::stopUpdate(float dt)
{
    unscheduleUpdate();
    unschedule(CC_SCHEDULE_SELECTOR(SchedulerUpdateFromCustom::stopUpdate));
}
示例#7
0
void PropSpeedupView::refreshView(CCObject* ccObj){
    if(m_clickIndex > -1 && m_clickIndex<m_Tools.size()){
        
        m_isSendingCMD=false;
        m_sprSelect->removeFromParent();
        m_sprSelect=NULL;
        CCPoint offset = m_scrollView->getContentOffset();
        CCSize nodeSize = m_nodeProp1->getContentSize();
        CCScrollView *scroll = CCScrollView::create(nodeSize);
        scroll->setDirection(kCCScrollViewDirectionHorizontal);
        scroll->setTouchEnabled(false);
        m_nodeProp1->addChild(scroll);
        std::vector<int>::iterator iter = m_Tools.begin();
        int index =0;
        while (iter!=m_Tools.end()) {
            auto &info = ToolController::getInstance()->getToolInfoById((*iter));
            if(info.getCNT()>0){
                PropSpeedupCell* cell = PropSpeedupCell::create(info.itemId);
                scroll->addChild(cell);
                cell->setPosition(ccp(PROP_SPEEDUP_CELL_W * (index + .5), PROP_SPEEDUP_CELL_W * 1.1));
                ++index;
                ++iter;
            }else{
                m_Tools.erase(iter);
            }
        }
        if(m_clickIndex >= m_Tools.size()){
            m_clickIndex = m_Tools.size() - 1;
        }
        scroll->setContentOffset(offset);
        m_scrollView->removeFromParent();
        m_scrollView = scroll;
        m_sprSelect=CCLoadSprite::createScale9Sprite("sel_general.png");
        m_sprSelect->setInsetBottom(10);
        m_sprSelect->setInsetTop(10);
        m_sprSelect->setInsetLeft(10);
        m_sprSelect->setInsetRight(10);
        m_sprSelect->setPreferredSize(CCSize(PROP_SPEEDUP_CELL_W, PROP_SPEEDUP_CELL_W));
        m_partileNode = Node::create();
        m_sprSelect->addChild(m_partileNode);
        auto particle = ParticleController::createParticle("Speedupicon_1");
        particle->setPosition(m_sprSelect->getContentSize() / 2);
        m_partileNode->addChild(particle);
        m_scrollView->addChild(m_sprSelect);
        m_sprSelect->setZOrder(-1);
        setSelectSpritePosition();
        autoBoundsScroll();
        refreshEditBox();
        {
            this->unschedule(schedule_selector(PropSpeedupView::updateProgressBar));
            auto& qInfo = GlobalData::shared()->allQueuesInfo[m_qID];
            float sumTime = qInfo.totalTime;
            float curTime = qInfo.finishTime - GlobalData::shared()->getWorldTime();
            float scaleXDst = 1 - curTime * 1.0 / sumTime;
//            float scaleYNow = m_progressTime->getScaleX();
            float scaleY = m_progressTime->getScaleY();
            m_progressTime->stopAllActions();
            this->unschedule(CC_SCHEDULE_SELECTOR(PropSpeedupView::showProTxt));
            this->schedule(CC_SCHEDULE_SELECTOR(PropSpeedupView::showProTxt));
            ScaleTo* sc = ScaleTo::create(1.0, scaleXDst, scaleY);
            auto fun1 = [=](){
                this->unschedule(CC_SCHEDULE_SELECTOR(PropSpeedupView::showProTxt));
                this->unschedule(schedule_selector(PropSpeedupView::updateProgressBar));
                this->updateProgressBar(0);
                this->schedule(schedule_selector(PropSpeedupView::updateProgressBar), 1);
            };
            CallFunc* cfun1 = CallFunc::create(fun1);
            m_progressTime->runAction(Sequence::create(sc, cfun1, nullptr));
        }
    }
    
    if(m_Tools.size()==0){
        closeDialog();
    }else{
//        m_clickIndex = -1;
        m_isSendingCMD=false;
        if(m_waitInterface){
            m_waitInterface->removeFromParent();
            m_waitInterface=NULL;
        }
        CCSafeNotificationCenter::sharedNotificationCenter()->removeObserver(this,  MSG_QUEUE_TIME_UPDATE);
    }
}
示例#8
0
void GameLayer::RockerStopMoveHero()
{
	unschedule(CC_SCHEDULE_SELECTOR(GameLayer::HeroMove));
}
示例#9
0
// on "init" you need to initialize your instance
bool Scene102::init()
{
	//////////////////////////////
	// 1. super init first
	if (!Layer::init())
	{
		return false;
	}

	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();
	Size size;

	SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Scene101/scene101.plist");
	SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Scene101/scene101bg.plist");

	//以 Sprite 作為背景
	Sprite *bkimage = Sprite::createWithSpriteFrameName("s101bgimg.png");  // 使用 create 函式,給予檔名即可
	bkimage->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y)); // 位置通常放置在螢幕正中間
	this->addChild(bkimage, 0);

	// 自行增加 sprite 將 bean01.png 到螢幕正中間


	// create and initialize a label, add a label shows "Scene 101"
	auto label = Label::createWithTTF("Scene 101", "fonts/Marker Felt.ttf", 32);
	label->setAlignment(cocos2d::TextHAlignment::CENTER); // 預設靠左對齊
	label->setWidth(100);	// 設定每行文字的顯示寬度
	size = label->getContentSize();
	label->setPosition(Vec2(origin.x + visibleSize.width - size.width / 2 - 10, origin.y + visibleSize.height - size.height / 2 - 10));
	this->addChild(label, 1);

	this->_sceneno = 102;
	strcpy(this->_cSceneNo, "Scene 102");

	//一般(非中文字)文字的顯示方式
	_label1 = Label::createWithBMFont("fonts/couriernew32.fnt", "Scene 101");
	size = _label1->getContentSize();
	_label1->setColor(Color3B::WHITE);
	_label1->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height - size.height));
	this->addChild(_label1, 1);

	// 中文字的顯示方式
	auto strings = FileUtils::getInstance()->getValueMapFromFile("scene101/strings.xml");
	std::string str1 = strings["chinese1"].asString();
	std::string str2 = strings["chinese2"].asString();
	auto label2 = Label::createWithBMFont("fonts/hansans48.fnt", str1);
	auto label3 = Label::createWithBMFont("fonts/hansans48.fnt", str2);
	size = label2->getContentSize();
	label2->setColor(Color3B(255, 238, 217));
	label2->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height - 80 - size.height));
	this->addChild(label2, 1);

	label3->setColor(Color3B(250, 251, 170));
	size = label3->getContentSize();
	label3->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height - 140 - size.height));
	this->addChild(label3, 1);

	// add Return Button
	this->returnbtn = Sprite::createWithSpriteFrameName("returnbtn.png");
	size = returnbtn->getContentSize();
	this->returnbtn->setPosition(Vec2(origin.x + size.width / 2 + 5, origin.y + visibleSize.height - size.height / 2 - 5));
	Point pos = returnbtn->getPosition();
	this->rectReturn = Rect(pos.x - size.width / 2, pos.y - size.height / 2, size.width, size.height);
	this->addChild(returnbtn, 1);

	// add Replay Button
	this->replaybtn = Sprite::createWithSpriteFrameName("replaybtn.png");
	size = replaybtn->getContentSize();
	this->replaybtn->setPosition(Vec2(origin.x + size.width / 2 + 90, origin.y + visibleSize.height - size.height / 2 - 5));
	pos = replaybtn->getPosition();
	this->rectReplay = Rect(pos.x - size.width / 2, pos.y - size.height / 2, size.width, size.height);
	this->addChild(replaybtn, 1);

	// add Cuber Button
	this->cuberbtn = Sprite::createWithSpriteFrameName("cuberbtn1.png");
	size = cuberbtn->getContentSize();
	this->cuberbtn->setPosition(Vec2(origin.x + visibleSize.width - size.width / 2, origin.y + visibleSize.height - size.height / 2 - 60));
	pos = cuberbtn->getPosition();
	this->rectCuber = Rect(pos.x - size.width / 2, pos.y - size.height / 2, size.width, size.height);
	this->addChild(cuberbtn, 1);

	_listener1 = EventListenerTouchOneByOne::create();	//創建一個一對一的事件聆聽器
	_listener1->onTouchBegan = CC_CALLBACK_2(Scene102::onTouchBegan, this);		//加入觸碰開始事件
	_listener1->onTouchMoved = CC_CALLBACK_2(Scene102::onTouchMoved, this);		//加入觸碰移動事件
	_listener1->onTouchEnded = CC_CALLBACK_2(Scene102::onTouchEnded, this);		//加入觸碰離開事件

	this->_eventDispatcher->addEventListenerWithSceneGraphPriority(_listener1, this);	//加入剛創建的事件聆聽器
	this->schedule(CC_SCHEDULE_SELECTOR(Scene102::doStep));

	return true;
}
示例#10
0
bool GameScene::init(bool _clickRed) {
	if (!Layer::init()){
		return false;
	}
	this->aiPlayer = new AIPlayer(this);

	clickRed = _clickRed;
	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();
	auto closeItem = MenuItemImage::create(
		"CloseNormal.png",
		"CloseSelected.png",
		CC_CALLBACK_1(GameScene::menuCloseCallback, this));
	closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width / 2,
		origin.y + closeItem->getContentSize().height / 2));

	MenuItemImage* backMenu = MenuItemImage::create("res/regret.png", "res/regret_selected.png", CC_CALLBACK_1(GameScene::backQIMenuCallback, this));
	backMenu->setPosition(Vec2(visibleSize.width - 200, visibleSize.height / 2 - 100));

	MenuItemImage* newGameMenu = MenuItemImage::create("res/new.png", "res/new_selected.png", CC_CALLBACK_1(GameScene::newGameMenuCallback, this));
	newGameMenu->setPosition(Vec2(visibleSize.width - 200, visibleSize.height / 2));

	auto menu = Menu::create(closeItem, backMenu, newGameMenu, NULL);
	menu->setPosition(Vec2::ZERO);
	this->addChild(menu, 1);
	/*
	auto label = Label::createWithTTF(getStringByKey("GuideStart"), "fonts/fangzheng.ttf", 24);
	label->setPosition(Vec2(origin.x + visibleSize.width/2,
	origin.y + visibleSize.height - label->getContentSize().height));
	this->addChild(label, 1);
	*/

	Vec2 offset = Vec2(20.0, 10.0);
	auto floor = Sprite::create("res/floor.png");
	floor->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));
	floor->setScaleX(visibleSize.width / floor->getContentSize().width);
	floor->setScaleY(visibleSize.height / floor->getContentSize().height);
	this->addChild(floor);

	Sprite* qipan = Sprite::create("res/background.png");
	qipan->setAnchorPoint(Vec2::ZERO);
	qipan->setPosition(offset);
	qipan->setScale((visibleSize.height - offset.y * 2) / qipan->getContentSize().height);
	this->addChild(qipan);
	// 给棋盘添加touch监听
	EventListenerTouchOneByOne *touchListener = EventListenerTouchOneByOne::create();
	touchListener->onTouchBegan = CC_CALLBACK_2(GameScene::onTouchesBegan, this);
	touchListener->onTouchCancelled = CC_CALLBACK_2(GameScene::onTouchCancelled, this);
	touchListener->onTouchEnded = CC_CALLBACK_2(GameScene::onTouchEnded, this);
	touchListener->onTouchMoved = CC_CALLBACK_2(GameScene::onTouchMoved, this);
	EventDispatcher* eventDispatcher = Director::getInstance()->getEventDispatcher();
	eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener->clone(), qipan);

	for (int i = 0; i < 32; i++){
		sts[i] = Stone::create(i, clickRed);
		sts[i]->setPosition(Vec2(rand_0_1()*visibleSize.width, rand_0_1()*visibleSize.height));
		MoveTo* moveTo = MoveTo::create(0.6f, Vec2(sts[i]->getRealX(), sts[i]->getRealY()));
		//MoveTo* moveTo = MoveTo::create(0.6f, Vec2(stone_x + sts[i]->getX()*def, stone_y + sts[i]->getY()*def));
		//sts[i]->setPosition(Vec2(stone_x + sts[i]->getX()*def, stone_y + sts[i]->getY()*def));
		sts[i]->runAction(moveTo);
		this->addChild(sts[i]);
	}

	spriteSelected = Sprite::create("res/selected.png");
	spriteSelected->setVisible(false);
	addChild(spriteSelected, 10);
	select_id = -1;
	//level = 1;
	isRedTurn = true;
	steps = Array::create();
	steps->retain();

	scheduleOnce(CC_SCHEDULE_SELECTOR(GameScene::updateAutoGo), 1.0f);
	return true;
}
示例#11
0
// 键盘触摸回调事件
void GameLayer::onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event)
{
	if (keyCode == EventKeyboard::KeyCode::KEY_LEFT_ARROW
		|| keyCode == EventKeyboard::KeyCode::KEY_UP_ARROW
		|| keyCode == EventKeyboard::KeyCode::KEY_RIGHT_ARROW
		|| keyCode == EventKeyboard::KeyCode::KEY_DOWN_ARROW
		|| keyCode == EventKeyboard::KeyCode::KEY_CAPITAL_A
		|| keyCode == EventKeyboard::KeyCode::KEY_CAPITAL_W
		|| keyCode == EventKeyboard::KeyCode::KEY_CAPITAL_D
		|| keyCode == EventKeyboard::KeyCode::KEY_CAPITAL_S
		|| keyCode == EventKeyboard::KeyCode::KEY_A
		|| keyCode == EventKeyboard::KeyCode::KEY_W
		|| keyCode == EventKeyboard::KeyCode::KEY_D
		|| keyCode == EventKeyboard::KeyCode::KEY_S)
	{
		m_bIsPressed = true;
		switch (keyCode)
		{
		case cocos2d::EventKeyboard::KeyCode::KEY_RIGHT_ARROW:
		{
																 m_pHero->SetSpeed(Point(300, 0));
		}
			break;
		case cocos2d::EventKeyboard::KeyCode::KEY_UP_ARROW:
		{
															  m_pHero->SetSpeed(Point(0, 300));
		}
			break;
		case cocos2d::EventKeyboard::KeyCode::KEY_DOWN_ARROW:
		{
																m_pHero->SetSpeed(Point(0, -300));
		}
			break;
		case cocos2d::EventKeyboard::KeyCode::KEY_LEFT_ARROW:
		{
																m_pHero->SetSpeed(Point(-300, 0));
		}
			break;
		case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_A:
		{
															   m_pHero->SetSpeed(Point(-300, 0));
		}
			break;

		case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_D:
		{
															   m_pHero->SetSpeed(Point(300, 0));
		}
			break;

		case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_S:
		{
															   m_pHero->SetSpeed(Point(0, -300));
		}
			break;

		case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_W:
		{
															   m_pHero->SetSpeed(Point(0, 300));
		}
															   break;

		case cocos2d::EventKeyboard::KeyCode::KEY_A:
		{
													   m_pHero->SetSpeed(Point(-300, 0));
		}
			break;

		case cocos2d::EventKeyboard::KeyCode::KEY_D:
		{
													   m_pHero->SetSpeed(Point(300, 0));
		}
			break;

		case cocos2d::EventKeyboard::KeyCode::KEY_S:
		{
													   m_pHero->SetSpeed(Point(0, -300));
		}
			break;

		case cocos2d::EventKeyboard::KeyCode::KEY_W:
		{
													   m_pHero->SetSpeed(Point(0, 300));

		}
			break;
		default:
			return;
		}
			m_nKeyPressed++;
			m_bIsPressed = true;
			schedule(CC_SCHEDULE_SELECTOR(GameLayer::HeroMove));
		}
}
示例#12
0
void GameScene::updateAutoGo(float delay){
	unschedule(CC_SCHEDULE_SELECTOR(GameScene::updateAutoGo));
	if (!clickRed && isRedTurn){
		aiGostep();
	}
}
示例#13
0
void GameScene::reStartGame(){
	Director::getInstance()->replaceScene(GameScene::createScene(clickRed));
	scheduleOnce(CC_SCHEDULE_SELECTOR(GameScene::updateAutoGo), 1.0f);
}
示例#14
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    ///////////////////////////////////////////////////////////////
    //                 Get Default Color
    // sqlite setting
    sqlite3 *pdb = OpenDatabase();
    int result;
    std::string dbPath;
    
    // create table
    result = sqlite3_exec(pdb, "create table if not exists colorsetting(idx integer primary key autoincrement, default_color int)", nullptr, nullptr, nullptr);
    if(result != SQLITE_OK){
        log("craete table failed");
    }
    
    // get default color
    char *errMsg;
    std::string select_query = "select default_color from colorsetting limit 1";
    sqlite3_stmt* statement;
    if (sqlite3_prepare(pdb, select_query.c_str(), -1, &statement, nullptr) == SQLITE_OK) {
        if (sqlite3_step(statement) == SQLITE_ROW) {
            g_defaultcolor = sqlite3_column_int(statement, 0);
        }else{
            // if no row
            // set default color
            std::string insert_query = "insert into colorsetting (default_color) values (1)";
            sqlite3_exec(pdb, insert_query.c_str(), nullptr, nullptr, &errMsg);
        }
    }else{
        // if select failed
        // set default color
        std::string insert_query = "insert into colorsetting (default_color) values (1)";
        sqlite3_exec(pdb, insert_query.c_str(), nullptr, nullptr, &errMsg);
    }
    sqlite3_finalize(statement);
    sqlite3_close(pdb);
    
    auto initColor3b = colorTable[g_defaultcolor].color;
    auto initColor4b = Color4B(initColor3b);
    //              End get Default Color
    //////////////////////////////
    
    
    
    
    
    
    //////////////////////////////
    // 1. super init first
//    if ( !LayerColor::initWithColor(Color4B(106,208,17,255)))
    if ( !LayerColor::initWithColor(initColor4b))
    {
        return false;
    }
 
    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
//    auto closeItem = MenuItemImage::create(
//                                           "CloseNormal.png",
//                                           "CloseSelected.png",
//                                           CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
//    
//	closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
//                                origin.y + closeItem->getContentSize().height/2));

//    auto nextscene = MenuItemFont::create("NEXT", CC_CALLBACK_1(HelloWorld::goFrameSelect,this));
//    nextscene->setPosition(Vec2(100,100));
    
    // create menu, it's an autorelease object
//    auto menu = Menu::create(nextscene, NULL);
//    menu->setPosition(Vec2::ZERO);
//    this->addChild(menu, 1);
    
    /////////////////////////////
    // 3. add your codes below...

    // add a label shows "Hello World"
    // create and initialize a label
    
//    auto label = Label::createWithTTF("FLIPICKER", "fonts/GROTESKIA OBLIQUE.otf", 24);
//    
//    // position the label on the center of the screen
//    label->setPosition(Vec2(origin.x + visibleSize.width/2,
//                            origin.y + visibleSize.height - label->getContentSize().height));
//    
//    // add the label as a child to this layer
//    this->addChild(label, 1);
    
    // size factor
    visibleSize = Director::getInstance()->getVisibleSize();
    origin = Director::getInstance()->getVisibleOrigin();
    r = float(visibleSize.height / 640 > visibleSize.width / 1136 ? visibleSize.width / 1136 : visibleSize.height / 640);
    if(menuscale * r >= 2.0f){
        path = "res/retina/";
        menuscale = menuscale / 2;
    }

    // add "HelloWorld" splash screen"
    auto sprite = Sprite::create(path+"00splash_logo.png");
    
    auto baseScale = 1.5;
    sprite->setScale(r * baseScale, r * baseScale);

    // position the sprite on the center of the screen
    sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height*55/100 + origin.y));

    // add the sprite as a child to this layer
    this->addChild(sprite, 0);
    
    auto job = CC_SCHEDULE_SELECTOR(HelloWorld::goFrameSelect);
    this->scheduleOnce(job, 1.0f);
    
    return true;
}
示例#15
0
void Stratosphere::startGameReady()
{
	this->startScrolling();
	this->schedule(CC_SCHEDULE_SELECTOR(Stratosphere::createPuff), 0.2f);
	this->getPlaneSprite()->runByState(PLANE_STATE::STATE_READY);
}
示例#16
0
void ZwoptexGenericTest::startIn05Secs(float dt)
{
    unschedule(CC_SCHEDULE_SELECTOR(ZwoptexGenericTest::startIn05Secs));
    schedule(CC_SCHEDULE_SELECTOR(ZwoptexGenericTest::flipSprites), 0.5f);
}
void ScenarioTest::beginStat(float dt)
{
    unschedule(CC_SCHEDULE_SELECTOR(ScenarioTest::beginStat));
    isStating = true;
}
void ControlStepper::startAutorepeat()
{
    _autorepeatCount    = -1;

    this->schedule(CC_SCHEDULE_SELECTOR(ControlStepper::update), kAutorepeatDeltaTime, CC_REPEAT_FOREVER, kAutorepeatDeltaTime * 3);
}
void SpriteMainScene::beginStat(float dt)
{
    unschedule(CC_SCHEDULE_SELECTOR(SpriteMainScene::beginStat));
    isStating = true;
}
/** Stop the autorepeat. */
void ControlStepper::stopAutorepeat()
{
    this->unschedule(CC_SCHEDULE_SELECTOR(ControlStepper::update));
}
示例#21
0
void TMXIsoZorderNew::onExit()
{
    unschedule(CC_SCHEDULE_SELECTOR(TMXIsoZorderNew::repositionSprite));
    TileDemoNew::onExit();
}
void ParticleMainScene::beginStat(float dt)
{
    unschedule(CC_SCHEDULE_SELECTOR(ParticleMainScene::beginStat));
    isStating = true;
}
示例#23
0
//------------------------------------------------------------------
//
// SchedulerUpdateFromCustom
//
//------------------------------------------------------------------
void SchedulerUpdateFromCustom::onEnter()
{
    SchedulerTestLayer::onEnter();

    schedule(CC_SCHEDULE_SELECTOR(SchedulerUpdateFromCustom::schedUpdate), 2.0f);
}
void ParticleMainScene::initWithSubTest(int asubtest, int particles)
{
    //srandom(0);

    isStating = false;
    subtestNumber = asubtest;
    auto s = Director::getInstance()->getWinSize();

    lastRenderedCount = 0;
    quantityParticles = particles;

    MenuItemFont::setFontSize(65);
    auto decrease = MenuItemFont::create(" - ", [&](Ref *sender) {
		quantityParticles -= kNodesIncrease;
		if( quantityParticles < 0 )
			quantityParticles = 0;

		updateQuantityLabel();
		createParticleSystem();
	});
    decrease->setColor(Color3B(0,200,20));
    auto increase = MenuItemFont::create(" + ", [&](Ref *sender) {
		quantityParticles += kNodesIncrease;
		if( quantityParticles > kMaxParticles )
			quantityParticles = kMaxParticles;

		updateQuantityLabel();
		createParticleSystem();
	});
    increase->setColor(Color3B(0,200,20));

    auto menu = Menu::create(decrease, increase, nullptr);
    menu->alignItemsHorizontally();
    menu->setPosition(Vec2(s.width/2, s.height/2+15));
    addChild(menu, 1);

    auto infoLabel = Label::createWithTTF("0 nodes", "fonts/Marker Felt.ttf", 30);
    infoLabel->setColor(Color3B(0,200,20));
    infoLabel->setPosition(Vec2(s.width/2, s.height - 90));
    addChild(infoLabel, 1, kTagInfoLayer);

    // particles on stage
    auto labelAtlas = LabelAtlas::create("0000", "fps_images.png", 12, 32, '.');
    addChild(labelAtlas, 0, kTagLabelAtlas);
    labelAtlas->setPosition(Vec2(s.width-66,50));

    // Sub Tests
    MenuItemFont::setFontSize(40);
    auto pSubMenu = Menu::create();
    for (int i = 1; i <= MAX_SUB_TEST_NUM; ++i)
    {
        char str[10] = {0};
        sprintf(str, "%d ", i);
        auto itemFont = MenuItemFont::create(str, CC_CALLBACK_1(ParticleMainScene::testNCallback, this));
        itemFont->setTag(i);
        pSubMenu->addChild(itemFont, 10);

        if (i <= 3)
        {
            itemFont->setColor(Color3B(200,20,20));
        }
        else
        {
            itemFont->setColor(Color3B(0,200,20));
        }
    }
    pSubMenu->alignItemsHorizontally();
    pSubMenu->setPosition(Vec2(s.width/2, 80));
    addChild(pSubMenu, 2);

    auto label = Label::createWithTTF(title().c_str(), "fonts/arial.ttf", 32);
    addChild(label, 1, kTagTitle);
    label->setPosition(Vec2(s.width/2, s.height-50));

    updateQuantityLabel();
    createParticleSystem();

    schedule(CC_SCHEDULE_SELECTOR(ParticleMainScene::step));
}
示例#25
0
void SchedulerDelayAndRepeat::onEnter()
{
    SchedulerTestLayer::onEnter();
    schedule(CC_SCHEDULE_SELECTOR(SchedulerDelayAndRepeat::update), 0, 4 , 3.f);
    CCLOG("update is scheduled should begin after 3 seconds");
}
示例#26
0
void ShowStar::gotoHomeScheduce(float delay)
{
	this->scheduleOnce(CC_SCHEDULE_SELECTOR(ShowStar::gotoHomePage), delay);
}
////////////////////////////////////////////////////////
//
// PerformanceEventDispatcherScene
//
////////////////////////////////////////////////////////
void PerformanceEventDispatcherScene::initWithQuantityOfNodes(unsigned int nNodes)
{
    _type = 0;
    srand((unsigned)time(nullptr));
    auto s = Director::getInstance()->getWinSize();
    
    // Title
    auto label = Label::createWithTTF(title().c_str(), "fonts/arial.ttf", 32);
    addChild(label, 1, TAG_TITLE);
    label->setPosition(Vec2(s.width/2, s.height-50));
    
    // Subtitle
    std::string strSubTitle = subtitle();
    if(strSubTitle.length())
    {
        auto l = Label::createWithTTF(strSubTitle.c_str(), "fonts/Thonburi.ttf", 16);
        addChild(l, 1, TAG_SUBTITLE);
        l->setPosition(Vec2(s.width/2, s.height-80));
    }
    
    _lastRenderedCount = 0;
    _currentQuantityOfNodes = 0;
    _quantityOfNodes = nNodes;
    
    MenuItemFont::setFontSize(65);
    auto decrease = MenuItemFont::create(" - ", [&](Ref *sender) {
		_quantityOfNodes -= kNodesIncrease;
		if( _quantityOfNodes < 0 )
			_quantityOfNodes = 0;
        
		updateQuantityLabel();
		updateQuantityOfNodes();
        updateProfilerName();
        CC_PROFILER_PURGE_ALL();
        srand(0);
	});
    decrease->setColor(Color3B(0,200,20));
    _decrease = decrease;
    
    auto increase = MenuItemFont::create(" + ", [&](Ref *sender) {
		_quantityOfNodes += kNodesIncrease;
		if( _quantityOfNodes > kMaxNodes )
			_quantityOfNodes = kMaxNodes;
        
		updateQuantityLabel();
		updateQuantityOfNodes();
        updateProfilerName();
        CC_PROFILER_PURGE_ALL();
        srand(0);
	});
    increase->setColor(Color3B(0,200,20));
    _increase = increase;
    
    auto menu = Menu::create(decrease, increase, nullptr);
    menu->alignItemsHorizontally();
    menu->setPosition(Vec2(s.width/2, s.height/2+15));
    addChild(menu, 1);
    
    auto infoLabel = Label::createWithTTF("0 listeners", "fonts/Marker Felt.ttf", 30);
    infoLabel->setColor(Color3B(0,200,20));
    infoLabel->setPosition(Vec2(s.width/2, s.height/2-15));
    addChild(infoLabel, 1, kTagInfoLayer);
    
    auto menuLayer = new (std::nothrow) EventDispatcherBasicLayer(true, MAX_LAYER, g_curCase);
    addChild(menuLayer);
    menuLayer->release();
    
    int oldFontSize = MenuItemFont::getFontSize();
    MenuItemFont::setFontSize(24);
    
    Vector<cocos2d::MenuItem *> toggleItems;
    
    generateTestFunctions();
    
    CCASSERT(!_testFunctions.empty(), "Should not be empty after generate test functions");
    
    
    for (const auto& f : _testFunctions)
    {
        toggleItems.pushBack(MenuItemFont::create(f.name));
    }
    
    auto reset = [this](){
        // Removes all nodes
        for (auto& node : _nodes)
        {
            node->removeFromParent();
        }
        
        _nodes.clear();
        
        // Removes all fixed listeners
        for (auto& listener : _fixedPriorityListeners)
        {
            Director::getInstance()->getEventDispatcher()->removeEventListener(listener);
        }
        
        this->_lastRenderedCount = 0;
    };
    
    auto toggle = MenuItemToggle::createWithCallback([=](Ref* sender){
        auto toggle = static_cast<MenuItemToggle*>(sender);
        this->_type = toggle->getSelectedIndex();
        auto label = static_cast<Label*>(this->getChildByTag(TAG_SUBTITLE));
        label->setString(StringUtils::format("Test '%s', See console", this->_testFunctions[this->_type].name));
        this->updateProfilerName();
        reset();
    }, toggleItems);
    
    toggle->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT);
    toggle->setPosition(VisibleRect::left());
    _toggle = toggle;
    
    auto start = MenuItemFont::create("start", [this](Ref* sender){
        auto director = Director::getInstance();
        auto sched = director->getScheduler();
        
        CC_PROFILER_PURGE_ALL();
        sched->schedule(CC_SCHEDULE_SELECTOR(PerformanceEventDispatcherScene::dumpProfilerInfo), this, 2, false);
        
        this->unscheduleUpdate();
        this->scheduleUpdate();
        this->_startItem->setEnabled(false);
        this->_stopItem->setEnabled(true);
        this->_toggle->setEnabled(false);
        this->_increase->setEnabled(false);
        this->_decrease->setEnabled(false);
    });
    start->setAnchorPoint(Vec2::ANCHOR_MIDDLE_RIGHT);
    start->setPosition(VisibleRect::right() + Vec2(0, 40));
    _startItem = start;
    
    auto stop = MenuItemFont::create("stop", [=](Ref* sender){
        auto director = Director::getInstance();
        auto sched = director->getScheduler();
        
        sched->unschedule(CC_SCHEDULE_SELECTOR(PerformanceEventDispatcherScene::dumpProfilerInfo), this);
        
        this->unscheduleUpdate();
        this->_startItem->setEnabled(true);
        this->_stopItem->setEnabled(false);
        this->_toggle->setEnabled(true);
        this->_increase->setEnabled(true);
        this->_decrease->setEnabled(true);
        
        reset();
    });
    
    stop->setEnabled(false);
    stop->setAnchorPoint(Vec2::ANCHOR_MIDDLE_RIGHT);
    stop->setPosition(VisibleRect::right() + Vec2(0, -40));
    _stopItem = stop;
    
    auto menu2 = Menu::create(toggle, start, stop, nullptr);
    menu2->setPosition(Vec2::ZERO);
    addChild(menu2);
    
    MenuItemFont::setFontSize(oldFontSize);
    
    updateQuantityLabel();
    updateQuantityOfNodes();
    updateProfilerName();
}
示例#28
0
void Stratosphere::stopScrolling()
{
	this->unschedule(CC_SCHEDULE_SELECTOR(Stratosphere::createPuff));
	this->unscheduleUpdate();
}
示例#29
0
EditorWeapon::~EditorWeapon() {
//    this->releaseSelf();
    this->unschedule(CC_SCHEDULE_SELECTOR(EditorWeapon::mainLoop));
    this->info = nullptr;
}
示例#30
0
void ScoreScene::showScore() {
    switch (count) {
    case 0:
    {
        enemyAHits->setVisible(true);
        enemyAScore->setVisible(true);
        updateTimes = GameManager::getInstance()->getEnemyAKilled();
        totalKill += updateTimes;
        this->schedule(CC_SCHEDULE_SELECTOR(ScoreScene::updateLabel), 0.2f);
        break;
    }
    case 1:
    {
        enemyBHits->setVisible(true);
        enemyBScore->setVisible(true);
        updateTimes = GameManager::getInstance()->getEnemyBKilled();
        totalKill += updateTimes;
        this->schedule(CC_SCHEDULE_SELECTOR(ScoreScene::updateLabel), 0.2f);
        break;
    }
    case 2:
    {
        enemyCHits->setVisible(true);
        enemyCScore->setVisible(true);
        updateTimes = GameManager::getInstance()->getEnemyCKilled();
        totalKill += updateTimes;
        this->schedule(CC_SCHEDULE_SELECTOR(ScoreScene::updateLabel), 0.2f);
        break;
    }
    case 3:
    {
        enemyDHits->setVisible(true);
        enemyDScore->setVisible(true);
        updateTimes = GameManager::getInstance()->getEnemyDKilled();
        totalKill += updateTimes;
        this->schedule(CC_SCHEDULE_SELECTOR(ScoreScene::updateLabel), 0.2f);
        break;
    }
    case 4:
    {
        total->setVisible(true);
        auto totalStr = StringUtils::format("%d", totalKill);
        total->setString(totalStr);
        if (GameManager::getInstance()->getOver()) {
            DelayTime *delayAction = DelayTime::create(3.0f);
            auto call = CallFuncN::create(CC_CALLBACK_0(ScoreScene::showGameOver, this));
            auto seq = Sequence::create(delayAction, call, NULL);
            this->runAction(seq);
        }
        else {
            DelayTime *delayAction = DelayTime::create(3.0f);
            auto call = CallFuncN::create(CC_CALLBACK_0(ScoreScene::gotoNextLevel, this));
            auto seq = Sequence::create(delayAction, call, NULL);
            this->runAction(seq);
        }
        break;
    }
    default:
        break;
    }
}