예제 #1
0
bool ChooseLevelLayer::init()
{
	//调用父类的初始化
	if (!Layer::init())
	{
		return false;
	}
	//标题精灵
	Sprite* ttSprite = Sprite::create("mainpic/title.png");
	ttSprite->setPosition(Point(270,780));
	this->addChild(ttSprite,1);

	bgSpriteO = Sprite::create("scene/scene1.jpg");
	bgSpriteO->setPosition(270,480);
	this->addChild(bgSpriteO,BGZORDER-1);

	bgSpriteT = Sprite::create("scene/scene1.jpg");
	bgSpriteT->setPosition(270,-480);
	this->addChild(bgSpriteT,BGZORDER);

	for(int i=0;i<3;i++)
	{
		gate0Sprite[i] = Sprite::create(StringUtils::format("choose/gate%d.png",i));
		gate0Sprite[i]->setPosition(Point(110+i*160,550));
		this->addChild(gate0Sprite[i],BGZORDER+1);

		int lock = UserDefault::getInstance()->getIntegerForKey(
				Constant::uesrGKLock[i].c_str());
		if(lock == 0)
		{
			Sprite* lockSp = Sprite::create("choose/lock.png");
			lockSp->setPosition(Point(110+i*160,550));
			this->addChild(lockSp,BGZORDER+2);
		}
	}
	Sprite* txtund = Sprite::create("choose/txtund.png");
	txtund->setPosition(Point(270,300));
	this->addChild(txtund,BGZORDER+1);

	taskLabel = Label::createWithTTF("\u70b9\u51fb\u5173\u5361\u67e5\u770b\u4efb\u52a1","fonts/FZKATJW.ttf",48);
	taskLabel->setPosition(Point(250,67));
	txtund->addChild(taskLabel,1);

	//创建下一个菜单项
	MenuItemImage* backMenu = MenuItemImage::create(
			   "mainpic/goback.png",	//平时的图片
			   "mainpic/gobackp.png",	//选中时的图片
			   CC_CALLBACK_0(ChooseLevelLayer::backMenuCallback, this) //点击时执行的回调方法
		);
	//设置下一个菜单项的位置
	backMenu->setPosition(Point(40,920));
	//创建菜单对象
	auto menu = Menu::create(backMenu,NULL);
	//设置菜单位置
	menu->setPosition(Point::ZERO);
	//将菜单添加到布景中
	this->addChild(menu, 1);

	//设置定时回调指定方法干活
	auto director = Director::getInstance();
	auto sched = director->getScheduler();
	//背景滚屏定时回调
	sched->scheduleSelector(SEL_SCHEDULE(&ChooseLevelLayer::bgUpdate),this,0.005,false);

	EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
	listener->setSwallowTouches(true);
	listener->onTouchBegan = CC_CALLBACK_2(ChooseLevelLayer::onTouchBegan, this);
	listener->onTouchEnded = CC_CALLBACK_2(ChooseLevelLayer::onTouchEnded, this);
	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener,gate0Sprite[0]);
	for(int i=1;i<3;i++)
	{
		_eventDispatcher->addEventListenerWithSceneGraphPriority(listener->clone(),gate0Sprite[i]);
	}
	return true;
}
예제 #2
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;
}