示例#1
0
Label::Label(FontAtlas *atlas /* = nullptr */, TextHAlignment hAlignment /* = TextHAlignment::LEFT */, 
             TextVAlignment vAlignment /* = TextVAlignment::TOP */,bool useDistanceField /* = false */,bool useA8Shader /* = false */)
: _isOpacityModifyRGB(false)
, _contentDirty(false)
, _fontAtlas(atlas)
, _textSprite(nullptr)
, _compatibleMode(false)
, _reusedLetter(nullptr)
, _additionalKerning(0.0f)
, _commonLineHeight(0.0f)
, _lineBreakWithoutSpaces(false)
, _horizontalKernings(nullptr)
, _maxLineWidth(0.0f)
, _labelDimensions(Size::ZERO)
, _labelWidth(0.0f)
, _labelHeight(0.0f)
, _hAlignment(hAlignment)
, _vAlignment(vAlignment)
, _currNumLines(-1)
, _fontScale(1.0f)
, _useDistanceField(useDistanceField)
, _useA8Shader(useA8Shader)
, _effectColorF(Color4F::BLACK)
, _uniformEffectColor(0)
, _shadowDirty(false)
, _blendFunc(BlendFunc::ALPHA_PREMULTIPLIED)
, _insideBounds(true)
{
    setAnchorPoint(Vec2::ANCHOR_MIDDLE);
    reset();

    _purgeTextureListener = EventListenerCustom::create(FontAtlas::CMD_PURGE_FONTATLAS, [this](EventCustom* event){
        if (_fontAtlas && _currentLabelType == LabelType::TTF && event->getUserData() == _fontAtlas)
        {
            for (auto it : _letters)
            {
                it.second->setTexture(nullptr);
            }
            _batchNodes.clear();

            if (_fontAtlas)
            {
                FontAtlasCache::releaseFontAtlas(_fontAtlas);
            }
        }
    });
    _eventDispatcher->addEventListenerWithFixedPriority(_purgeTextureListener, 1);
    
    _resetTextureListener = EventListenerCustom::create(FontAtlas::CMD_RESET_FONTATLAS, [this](EventCustom* event){
        if (_fontAtlas && _currentLabelType == LabelType::TTF && event->getUserData() == _fontAtlas)
        {
            _fontAtlas = nullptr;
            this->setTTFConfig(_fontConfig);
            for (auto it : _letters)
            {
                getLetter(it.first);
            }
        }
    });
    _eventDispatcher->addEventListenerWithFixedPriority(_resetTextureListener, 2);
}
示例#2
0
bool LevelSeven::init()
{
	if (!Layer::init())
	{
		return false;
	}

	// 用于解决刚体穿透问题
	this->scheduleUpdate();
	// 计时器
	this->schedule(schedule_selector(LevelSeven::timeCounter), 1.0f);

	auto visibleSize = Director::getInstance()->getVisibleSize();
	auto origin = Director::getInstance()->getVisibleOrigin();

	// 加载背景贴图
	auto spriteBg = Sprite::create("background.png");
	spriteBg->setAnchorPoint(Vec2::ZERO);
	spriteBg->setPosition(Vec2::ZERO);
	addChild(spriteBg);

	// 将资源加载到精灵帧缓存
	SpriteFrameCache::getInstance()->addSpriteFramesWithFile("threeColor.plist");

	ballOne = Sprite::createWithSpriteFrameName("hero.png");
	ballOne->setPosition(visibleSize.width / 2.0f, visibleSize.height / 2.0f);
	auto ballBodyOne = PhysicsBody::createCircle(ballOne->getContentSize().width / 2, PHYSICSBODY_MATERIAL_DEFAULT);
	//是否设置物理为静态
	//ballBodyOne->setDynamic(false);
	//设置物理的恢复力
	ballBodyOne->getShape(0)->setRestitution(0.5f);
	//设置物体的摩擦力
	ballBodyOne->getShape(0)->setFriction(0.0f);
	ballBodyOne->getShape(0)->setDensity(0.3f);
	// 设置质量 质量等于密度乘以面积
	//ballBodyOne->getShape(0)->setMass(5000);
	// 设置物体是否受重力系数影响
	ballBodyOne->setGravityEnable(true);

	ballBodyOne->setCategoryBitmask(1);// 分类掩码
	ballBodyOne->setCollisionBitmask(1 | 2 | 4);// 碰撞掩码
	ballBodyOne->setContactTestBitmask(2);// 接触测试掩码

	// 把物体添加到精灵
	ballOne->setPhysicsBody(ballBodyOne);
	this->addChild(ballOne);

	//创建一个盒子,用来碰撞
	auto edgeSpace = Sprite::create();
	auto boundBody = PhysicsBody::createEdgeBox(visibleSize, PHYSICSBODY_MATERIAL_DEFAULT, 3);
	boundBody->getShape(0)->setFriction(0.0f);
	boundBody->getShape(0)->setRestitution(1.0f);

	edgeSpace->setPhysicsBody(boundBody);
	edgeSpace->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2));
	this->addChild(edgeSpace);
	edgeSpace->setTag(0);

	boundBody->setCategoryBitmask(4);
	boundBody->setCollisionBitmask(1 | 2 | 4);
	boundBody->setContactTestBitmask(0);

	// 创建yuan
	auto white1 = Sprite::createWithSpriteFrameName("white2.png");
	auto whiteBody1 = PhysicsBody::createCircle(white1->getContentSize().width / 2.0f, PHYSICSBODY_MATERIAL_DEFAULT);
	whiteBody1->setDynamic(false);
	whiteBody1->setCategoryBitmask(4);
	whiteBody1->setCollisionBitmask(1 | 2 | 4);
	whiteBody1->setContactTestBitmask(0);
	white1->setPhysicsBody(whiteBody1);
	this->addChild(white1);

	// 正方形
	auto white1_2 = Sprite::createWithSpriteFrameName("white1.png");
	auto whiteBody1_2 = PhysicsBody::createBox(white1_2->getContentSize(), PHYSICSBODY_MATERIAL_DEFAULT);
	whiteBody1_2->setDynamic(false);
	whiteBody1_2->setCategoryBitmask(4);
	whiteBody1_2->setCollisionBitmask(1 | 2 | 4);
	whiteBody1_2->setContactTestBitmask(0);
	white1_2->setPhysicsBody(whiteBody1_2);
	this->addChild(white1_2);

	// 创建三角形
	Vec2 arr[] =
	{
		Vec2(-16.50000, 36.00000),
		Vec2(35.50000, -15.00000),
		Vec2(-34.00000, -32.50000)
	};
	auto white3 = Sprite::createWithSpriteFrameName("white3.png");
	auto whiteBody3 = PhysicsBody::createPolygon(arr, 3, PHYSICSBODY_MATERIAL_DEFAULT);
	whiteBody3->setDynamic(false);
	whiteBody3->setCategoryBitmask(4);
	whiteBody3->setCollisionBitmask(1 | 2 | 4);
	whiteBody3->setContactTestBitmask(0);
	white3->setPhysicsBody(whiteBody3);
	this->addChild(white3);

	// 随机位置
	int index = CCRANDOM_0_1() * 3;
	switch (index)
	{
	case 0:
	{
			  white1->setPosition(visibleSize.width / 2.0f, visibleSize.height / 2.0f + 200.0f);
			  whiteBody1->setDynamic(true);
			  whiteBody1->setGravityEnable(false);
			  white1_2->setPosition(visibleSize.width / 2.0f + 100.0f, visibleSize.height / 2.0f);
			  white3->setPosition(visibleSize.width / 2.0f - 100.0f, visibleSize.height / 2.0f);
	}
		break;
	case 1:
	{
			  white1_2->setPosition(visibleSize.width / 2.0f, visibleSize.height / 2.0f + 200.0f);
			  whiteBody1_2->setDynamic(true);
			  whiteBody1_2->setGravityEnable(false);
			  white1->setPosition(visibleSize.width / 2.0f + 100.0f, visibleSize.height / 2.0f);
			  white3->setPosition(visibleSize.width / 2.0f - 100.0f, visibleSize.height / 2.0f);
	}
		break;
	case 2:
	{
			  white3->setPosition(visibleSize.width / 2.0f, visibleSize.height / 2.0f + 200.0f);
			  whiteBody3->setDynamic(true);
			  whiteBody3->setGravityEnable(false);
			  white1->setPosition(visibleSize.width / 2.0f + 100.0f, visibleSize.height / 2.0f);
			  white1_2->setPosition(visibleSize.width / 2.0f - 100.0f, visibleSize.height / 2.0f);
	}
		break;
	default:
		break;
	}

	// 正方形旋转
	auto rotation = RotateBy::create(1, 360);
	auto rotationback = rotation->reverse();
	auto seq = Sequence::create(rotation, rotationback, nullptr);
	auto repeat = RepeatForever::create(seq);
	white1->runAction(repeat);
	// 
	// 第二个正方形旋转
	auto rotation_1 = RotateBy::create(2, 360);
	auto rotationback_1 = rotation_1->reverse();
	auto seq1 = Sequence::create(rotation_1, rotationback_1, nullptr);
	auto repeat1 = RepeatForever::create(seq1);
	white1_2->runAction(repeat1);

	// 三角形旋转
	auto rotation_2 = RotateBy::create(2, 360);
	auto rotationback_2 = rotation_2->reverse();
	auto seq2 = Sequence::create(rotation_2, rotationback_2, nullptr);
	auto repeat2 = RepeatForever::create(seq2);
	white3->runAction(repeat2);

	auto yuantong0 = Sprite::createWithSpriteFrameName("yuantong.png");
	yuantong0->setPosition(Vec2(visibleSize.width / 2.0f, visibleSize.height + yuantong0->getContentSize().height / 2.0f));

	auto yuantongBody = PhysicsBody::createBox(yuantong0->getContentSize(), PHYSICSBODY_MATERIAL_DEFAULT);
	yuantongBody->setDynamic(false);
	yuantongBody->setCategoryBitmask(4);
	yuantongBody->setCollisionBitmask(1 | 2 | 4);
	yuantongBody->setContactTestBitmask(0);
	yuantong0->setPhysicsBody(yuantongBody);

	this->addChild(yuantong0);

	auto moveby0 = MoveBy::create(1.0f, Vec2(0, -90));
	auto moveby0back = moveby0->reverse();
	auto easein = EaseBackIn::create(moveby0);
	auto seq0 = Sequence::create(easein, CallFuncN::create(CC_CALLBACK_1(LevelSeven::callbackC, this)), moveby0back, nullptr);
	auto repeat0 = RepeatForever::create(seq0);
	yuantong0->runAction(repeat0);

	listener = EventListenerTouchOneByOne::create();
	listener->onTouchBegan = [=](Touch* touch, Event* event){
		auto touchPosition = touch->getLocation();

		Vec2 force = Vec2::ZERO;
		if (touchPosition.x > visibleSize.width / 2.0f)
		{
			force = Vec2(50000.0f, 0.0f);
		}
		else
		{
			force = Vec2(-50000.0f, 0.0f);
		}

		ballOne->getPhysicsBody()->applyImpulse(force);

		return true;
	};
	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

	// 时间显示文本
	test = LabelAtlas::create(StringUtils::toString(LEVELSEVEN), "1.png", 14, 21, '0');
	test->setScale(2.0f);
	test->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
	test->setPosition(Vec2(test->getContentSize().width*2, visibleSize.height - test->getContentSize().height));
	this->addChild(test);

	test2 = LabelAtlas::create("0", "1.png", 14, 21, '0');
	test2->setScale(2.0f);
	test2->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
	test2->setPosition(Vec2(visibleSize.width - test2->getContentSize().width*2, visibleSize.height - test2->getContentSize().height));
	this->addChild(test2);

	return true;
}
bool MainScene::init(){
    if(!Scene::init()){
        return false;
    }
    Size visibleSize = Director::getInstance()->getVisibleSize();

    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("newAlwaysShow.plist");
    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("UI/res_fx/normal_bullet.plist");
    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("newCommon.plist");
    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("newBattle.plist");
    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("nopack/qiancengta.plist");//出新英雄的背景
    
    auto btnFrame_normal = Sprite::createWithSpriteFrameName("btn_dibuzhukong_normal.png");
    auto btnFrame_clicked = Sprite::createWithSpriteFrameName("btn_dibuzhukong_highlight.png");
    auto btnFrame_normal2 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_normal.png");
    auto btnFrame_clicked2 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_highlight.png");
    auto btnFrame_normal3 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_normal.png");
    auto btnFrame_clicked3 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_highlight.png");
    auto btnFrame_normal4 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_normal.png");
    auto btnFrame_clicked4 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_highlight.png");
    auto btnFrame_normal5 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_normal.png");
    auto btnFrame_clicked5 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_highlight.png");

    auto liangshan = Sprite::createWithSpriteFrameName("btn_liangshan.png");
    auto zhenrong = Sprite::createWithSpriteFrameName("icon_zhenrong.png");
    auto zhengzhan = Sprite::createWithSpriteFrameName("icon_zhengzhan.png");
    auto xingxia = Sprite::createWithSpriteFrameName("icon_xingxia.png");
    auto shop = Sprite::createWithSpriteFrameName("icon_shangdian.png");
    //加上下边框
    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("gameFrame.plist");
    auto upFrame = Sprite::createWithSpriteFrameName("icon_shanghuabian.png");
    auto downFrame = Sprite::createWithSpriteFrameName("icon_xiahuabian.png");
    downFrame->setPosition(visibleSize.width/2,downFrame->getContentSize().height/2);
    upFrame->setPosition(visibleSize.width/2,visibleSize.height-upFrame->getContentSize().height/2);
    this->addChild(downFrame,2);
    this->addChild(upFrame,2);
    //加入所有底层功能
    auto liangshan2 = Sprite::createWithSpriteFrameName("btn_liangshan.png");
    liangshan2->setScale(0.8f);
    btnFrame_normal->addChild(liangshan);
    btnFrame_clicked->addChild(liangshan2);
    auto btn1 = MenuItemSprite::create(btnFrame_normal,btnFrame_clicked,CC_CALLBACK_1(MainScene::bottomFunction,this));
    
    liangshan->setPosition(btn1->getContentSize().width/2,btn1->getContentSize().height/2);
    liangshan2->setPosition(btn1->getContentSize().width/2,btn1->getContentSize().height/2);
    
    auto zhenrong2 = Sprite::createWithSpriteFrameName("icon_zhenrong.png");
    zhenrong2->setScale(0.8f);
    btnFrame_normal2->addChild(zhenrong);
    btnFrame_clicked2->addChild(zhenrong2);
    auto btn2 = MenuItemSprite::create(btnFrame_normal2,btnFrame_clicked2,CC_CALLBACK_1(MainScene::bottomFunction,this));
    zhenrong->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2);
    zhenrong2->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2);

    auto zhengzhan2 = Sprite::createWithSpriteFrameName("icon_zhengzhan.png");
    zhengzhan2->setScale(0.8f);
    btnFrame_normal3->addChild(zhengzhan);
    btnFrame_clicked3->addChild(zhengzhan2);
    auto btn3 = MenuItemSprite::create(btnFrame_normal3,btnFrame_clicked3,CC_CALLBACK_1(MainScene::bottomFunction,this));
    zhengzhan->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2);
    zhengzhan2->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2);
    
    auto xingxia2 = Sprite::createWithSpriteFrameName("icon_xingxia.png");
    xingxia2->setScale(0.8f);
    btnFrame_normal4->addChild(xingxia);
    btnFrame_clicked4->addChild(xingxia2);
    auto btn4 = MenuItemSprite::create(btnFrame_normal4,btnFrame_clicked4,CC_CALLBACK_1(MainScene::bottomFunction,this));
    xingxia->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2);
    xingxia2->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2);
    
    auto shop2 = Sprite::createWithSpriteFrameName("icon_shangdian.png");
    shop2->setScale(0.8f);
    btnFrame_normal5->addChild(shop);
    btnFrame_clicked5->addChild(shop2);
    auto btn5 = MenuItemSprite::create(btnFrame_normal5,btnFrame_clicked5,CC_CALLBACK_1(MainScene::bottomFunction,this));
    shop->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2);
    shop2->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2);
    
    //liangshan1->setTag(11);
    /*auto menu2 = Menu::create(liangshan1,zhenrong1,zhengzhan1,xingxia1,shop1,NULL);
    menu2->alignItemsHorizontallyWithPadding(0.0f);
    menu2->setPosition(visibleSize.width/2,btn1->getContentSize().height/2+downFrame->getContentSize().height-2);
    this->addChild(menu2);
    */
    menu1 = Menu::create(btn1,btn2,btn3,btn4,btn5,NULL);
    menu1->alignItemsHorizontally();
    menu1->alignItemsHorizontallyWithPadding(0.0f);
    menu1->setPosition(visibleSize.width/2,btn1->getContentSize().height/2+downFrame->getContentSize().height-2);
    this->addChild(menu1,2,MAIN_MENU_TAG);
//底层功能TAG
    btn1->setTag(11);
    btn2->setTag(12);
    btn3->setTag(13);
    btn4->setTag(14);
    btn5->setTag(15);
    
//TO DO....阵型   &   武将列表
    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("more.plist");
    auto zhenxing = Sprite::createWithSpriteFrameName("icon_zhanghaoshezhi.png");
    auto zhenxingitem = MenuItemSprite::create(zhenxing, zhenxing, CC_CALLBACK_1(MainScene::showZhenXing,this));
    auto wujiang = Sprite::createWithSpriteFrameName("icon_tujian.png");
    auto wujiangitem = MenuItemSprite::create(wujiang, wujiang, CC_CALLBACK_1(MainScene::showTeamList,this));
    auto menu4 = Menu::create(zhenxingitem,wujiangitem,NULL);
    menu4->alignItemsHorizontally();
    menu4->setPosition(visibleSize.width/4,194+zhenxing->getContentSize().height);
    this->addChild(menu4,2);
    
//攻城列队
    auto gongcheng = Sprite::createWithSpriteFrameName("icon_bangzhu.png");
    auto gongchengitem = MenuItemSprite::create(gongcheng, gongcheng, CC_CALLBACK_1(MainScene::showGongchengTeam,this));
    auto menu5 = Menu::create(gongchengitem,NULL);
    menu5->setPosition(Vec2::ZERO);
    gongchengitem->setPosition(visibleSize.width/2,194+zhenxing->getContentSize().height);
    this->addChild(menu5,2);

//背景
    auto bg = Sprite::create("building.jpeg");
	bg->setPosition(visibleSize.width/2, visibleSize.height/2);
    this->addChild(bg,1);
    auto topleft = Sprite::createWithSpriteFrameName("bg-banner_top_left.png");
    auto topright = Sprite::createWithSpriteFrameName("bg-banner_top_right.png");
    topleft->setAnchorPoint(Vec2(0,1));
    topright->setAnchorPoint(Vec2(1,1));
    topleft->setPosition(0,visibleSize.height-upFrame->getContentSize().height+2);
    topright->setPosition(visibleSize.width,visibleSize.height-upFrame->getContentSize().height+2);
    this->addChild(topleft,2);
    this->addChild(topright,2);
    
//用户等级,名字,银两,声望------------
    char wenzi[32];
    sprintf(wenzi,"%d",99);
    auto level = Label::createWithTTF(wenzi, "字体/华文新魏.TTF", 24);
    auto name = Label::createWithTTF("十八罗汉", "字体/华文新魏.TTF", 24);
    level->setPosition(40,visibleSize.height-upFrame->getContentSize().height-topleft->getContentSize().height/4);
    name->setPosition(50+name->getContentSize().width/2+30,visibleSize.height-upFrame->getContentSize().height-topleft->getContentSize().height/4);
    this->addChild(level,3,USERLEVEL_TAG);
    this->addChild(name,3,USERNAME_TAG);
    
    sprintf(wenzi,"%d",99999);
    auto money = Label::createWithTTF(wenzi, "字体/华文新魏.TTF", 24);
    money->setPosition(visibleSize.width/2+50+money->getContentSize().width/2,visibleSize.height-upFrame->getContentSize().height-topright->getContentSize().height*3/4);
    this->addChild(money,3,USERMONEY_TAG);
    
    sprintf(wenzi,"%d",99999);
    auto reputation = Label::createWithTTF(wenzi, "字体/华文新魏.TTF", 24);
    reputation->setPosition(visibleSize.width*3/4+50+reputation->getContentSize().width/2,visibleSize.height-upFrame->getContentSize().height-topright->getContentSize().height*3/4);
    this->addChild(reputation,3,USERREPUTATION_TAG);

//抽将功能页面HelloWorldLayer加载,MainLayer没用可以删掉
    //TO DO...抽装备选项
    auto _HelloWorldLayer = HelloWorldLayer::create();
    auto _MainLayer = MainLayer::create();
    if(_HelloWorldLayer){
        _HelloWorldLayer->setDelegator(_MainLayer);
        this->addChild(_HelloWorldLayer,1,HELLOWORLD_LAYER_TAG);
    }
    if(_MainLayer)
        this->addChild(_MainLayer,1);
    
//载入数据-----------------------
    //string dou = FileUtils::getInstance()->fullPathForFilename("wholeheros.db");
    //log("存放路径为%s",dou.c_str());
    //string documentpath1 = FileUtils::getInstance()->fullPathForFilename("UserInfo.db");
    
    log("存放路径为%s",documentpath1.c_str());
    GameStat::getInstance()->readFromUserInfo("Users_Info", documentpath1.c_str());
    GameStat::getInstance()->readFromUserHeros("User_hero", documentpath1.c_str(), 0);

    char sql[1024];
    sprintf(sql, "select * from User_equip where username = \"%s\"", user_name.c_str());//根据用户名读取英雄
    GameStat::getInstance()->readfromEquipInfo("User_equip", documentpath1.c_str(),sql);
    
    //将玩家信息:等级、名字、银两、声望、元宝等从服务器加载
    MainScene::resetUserInfo();
    
//-------------------------------

//载入攻城车
    GongChengType gongcheng1;
    gongcheng1.engname = "gongchengche";
    gongcheng1.type = 1;
    gongcheng1.attack = 210;
    gongcheng1.durable = 4;
    gongcheng1.attack_type = 1;
    gongcheng1.bullet_type = 1;
    GongChengType gongcheng2;
    gongcheng2.engname = "toushiche";
    gongcheng2.type = 1;
    gongcheng2.attack = 240;
    gongcheng2.durable = 3;
    gongcheng2.attack_type = 1;
    gongcheng2.bullet_type = 1;
    
    GongChengType gongcheng3;
    gongcheng3.engname = "paoshiche";
    gongcheng3.type = 1;
    gongcheng3.attack = 260;
    gongcheng3.durable = 3;
    gongcheng3.attack_type = 1;
    gongcheng3.bullet_type = 1;
    GongChengType gongcheng4;
    gongcheng4.engname = "nuche";
    gongcheng4.type = 2;
    
    gongcheng4.attack = 210;
    gongcheng4.durable = 5;
    gongcheng4.attack_type = 1;
    gongcheng4.bullet_type = 2;
    
    GongChengType gongcheng5;
    gongcheng5.engname = "junuche";
    gongcheng5.type = 2;
    gongcheng5.attack = 350;
    gongcheng5.durable = 3;
    gongcheng5.attack_type = 1;
    gongcheng5.bullet_type = 2;
    
    GongChengType gongcheng6;
    gongcheng6.engname = "liannu";
    gongcheng6.type = 2;
    gongcheng6.attack = 200;
    gongcheng6.durable = 5;
    gongcheng6.attack_type = 3;
    gongcheng6.bullet_type = 2;
    GameStat::getInstance()->userqixie.push_back(gongcheng1);
    GameStat::getInstance()->userqixie.push_back(gongcheng2);
    GameStat::getInstance()->userqixie.push_back(gongcheng3);
    GameStat::getInstance()->userqixie.push_back(gongcheng4);
    GameStat::getInstance()->userqixie.push_back(gongcheng5);
    GameStat::getInstance()->userqixie.push_back(gongcheng6);
    
    //敌军守城器械赋值
    GameStat::getInstance()->enemyCompeteQixie[0] = gongcheng6;
    GameStat::getInstance()->enemyCompeteQixie[0].position = 0;
    
    GameStat::getInstance()->enemyCompeteQixie[1] = gongcheng5;
    GameStat::getInstance()->enemyCompeteQixie[1].position = 1;
    
    GameStat::getInstance()->enemyCompeteQixie[2] = gongcheng4;
    GameStat::getInstance()->enemyCompeteQixie[2].position = 2;
    

//进入新手指导
    __NotificationCenter::getInstance()->addObserver(this, callfuncO_selector(MainScene::receive_notice_from_battle), "newPlayer", NULL);//一般是从战斗场景跳回调用
    if(in_newplayer_mode)
        MainScene::newPlayerStart(new_stage);

    return true;
}
示例#4
0
bool MailWritePopUpView::initWithGift(int giftID,int propID) {
    if(!PopupBaseView::init()) {
        return false;
    }
    setIsHDPanel(true);
    mPropID = propID;
    mType = 1;
//    auto cf = CCLoadSprite::getSF("Mail_diban.png");
    auto cf = CCLoadSprite::getSF("Mail_BG1.png");
    if (cf==NULL) {
        CCLoadSprite::doResourceByCommonIndex(11, true);
        CCLoadSprite::doResourceByCommonIndex(6, true);
        setCleanFunction([]() {
            CCLoadSprite::doResourceByCommonIndex(11, false);
            CCLoadSprite::doResourceByCommonIndex(6, false);
        });
    }
    else {
        CCLoadSprite::doResourceByCommonIndex(11, true);
        setCleanFunction([]() {
            CCLoadSprite::doResourceByCommonIndex(11, false);
        });
    }

    auto bg = CCBLoadFile("NEWMailWriteView", this, this);
    if (CCCommonUtils::isIosAndroidPad()) {
        this->setContentSize(CCDirector::sharedDirector()->getWinSize());
    }
    else
        this->setContentSize(bg->getContentSize());
//    setTitleName(_lang("105513"));
    m_titleText->setString(_lang("105513"));
    if (CCCommonUtils::isIosAndroidPad()) {
        int extH = getExtendHeight();
        this->m_listNode->setContentSize(CCSize(m_listNode->getContentSize().width, m_listNode->getContentSize().height + extH));
        m_downNode->setPositionY(m_downNode->getPositionY() - extH);
        m_bgNode->setPositionY(m_bgNode->getPositionY() - extH);
//        m_nodeContent->setPositionY(m_nodeContent->getPositionY() - extH);
        auto tbg = CCLoadSprite::loadResource("Mail_diban.png");
        auto tBatchNode = CCSpriteBatchNode::createWithTexture(tbg->getTexture());
        auto picBg1 = CCLoadSprite::createSprite("Mail_diban.png");
        picBg1->setAnchorPoint(ccp(0, 0));
        picBg1->setPosition(ccp(0, 0));
        picBg1->setScaleX(2.4);
        tBatchNode->addChild(picBg1);
        int maxHeight = CCDirector::sharedDirector()->getWinSize().height;
        int curHeight = picBg1->getContentSize().height;
        while(curHeight < maxHeight)
        {
            auto picBg2 = CCLoadSprite::createSprite("Mail_diban.png");
            picBg2->setAnchorPoint(ccp(0, 0));
            picBg2->setPosition(ccp(0, curHeight));
            picBg2->setScaleX(2.4);
            tBatchNode->addChild(picBg2);
            curHeight += picBg2->getContentSize().height;
        }
        m_bgNode->addChild(tBatchNode);
    }
    else {
        int extH = getExtendHeight();
        this->m_listNode->setContentSize(CCSize(m_listNode->getContentSize().width, m_listNode->getContentSize().height + extH));
        m_downNode->setPositionY(m_downNode->getPositionY() - extH);
        m_bgNode->setPositionY(m_bgNode->getPositionY() - extH);
//        m_nodeContent->setPositionY(m_nodeContent->getPositionY() - extH);
        auto tbg = CCLoadSprite::loadResource("Mail_diban.png");
        auto tBatchNode = CCSpriteBatchNode::createWithTexture(tbg->getTexture());
        auto picBg1 = CCLoadSprite::createSprite("Mail_diban.png");
        picBg1->setAnchorPoint(ccp(0, 0));
        picBg1->setPosition(ccp(0, 0));
        tBatchNode->addChild(picBg1);
        int maxHeight = CCDirector::sharedDirector()->getWinSize().height;
        int curHeight = picBg1->getContentSize().height;
        while(curHeight < maxHeight)
        {
            auto picBg2 = CCLoadSprite::createSprite("Mail_diban.png");
            picBg2->setAnchorPoint(ccp(0, 0));
            picBg2->setPosition(ccp(0, curHeight));
            tBatchNode->addChild(picBg2);
            curHeight += picBg2->getContentSize().height;
        }
        m_bgNode->addChild(tBatchNode);
    }
//    CCSize wNodeSize = this->m_waitingNode->getContentSize();
//    m_waitingNode->setContentSize(CCSize(wNodeSize.width,wNodeSize.height + dh));
//    m_waitingNode->setPositionY(m_waitingNode->getPositionY() - dh*0.5);

//    this->m_nameText->setString(_lang("105505").c_str());
    //    this->m_titleText->setString(_lang("105503").c_str());
//    this->m_contentText->setString(_lang("105504").c_str());

    CCNode *searchnode = CCNode::create();
    auto spr1 = CCLoadSprite::createScale9Sprite("button_dark.png");
    CCControlButton *shareBtn = CCControlButton::create(spr1);
    searchnode->addChild(shareBtn);
    shareBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(MailWritePopUpView::onChooseName), CCControlEventTouchUpInside);
    CCSprite* sprIcon = CCLoadSprite::createSprite("search_icon.png");
    CCSize sprSize = sprIcon->getContentSize();
    searchnode->addChild(sprIcon);
    CCCommonUtils::setSpriteMaxSize(sprIcon, 40);
    shareBtn->setPreferredSize(CCSize(60, 60));
    this->m_nameContainer->addChild(searchnode);
    searchnode->setPosition(440, 0);

    CCScrollView *scrollView = CCScrollView::create(m_listNode->getContentSize());
    scrollView->setTouchPriority(Touch_Popup_Item);
    scrollView->setDirection(kCCScrollViewDirectionVertical);
    m_nodeContent->removeFromParentAndCleanup(false);
    scrollView->addChild(m_nodeContent);
    scrollView->setTag(10000);
    m_nameEditBox = InputFieldMultiLine::create(CCSizeMake(380,40),"Mail_write.png",24);
//    m_nameEditBox->setTouchPriority(Touch_Default);
    m_nameEditBox->setMaxChars(30);
    m_nameEditBox->setPosition(ccp(0, -20));
    m_nameEditBox->setLineNumber(1);
    m_nameEditBox->setFontColor({63,44,27});

    this->m_nameContainer->addChild(m_nameEditBox);
    m_nameEditBox->m_enabled = (mPropID == ITEM_SEND_GIFTALLIANCE || mPropID == ITEM_SEND_GIFT || mPropID == ITEM_SEND_GIFTMORE)?false:true;

    m_contentEditBox = InputFieldMultiLine::create(m_contentContainer->getContentSize(),"Mail_write.png",24);
    m_contentEditBox->setTouchPriority(Touch_Default);
    m_contentEditBox->setMaxChars(300);
    m_contentEditBox->setLineNumber(5);
    m_contentEditBox->setPosition(ccp(0, 0));
    m_contentEditBox->setFontColor({63,44,27});
    this->m_contentContainer->addChild(m_contentEditBox);
    m_contentEditBox->setText(_lang("101383"));
    CCSize liseNodeSize = this->m_listNode->getContentSize() * m_listNode->getScale();
    MailGiftCell *mailGiftCell = MailGiftCell::create(CCSize(liseNodeSize.width, liseNodeSize.height - 110),mPropID,giftID);
    scrollView->addChild(mailGiftCell);
    mailGiftCell->setTag(10000);
    CCSize cellSize = mailGiftCell->getContentSize();
    int needH = ceil(cellSize.height + 400);
    int nowH = m_listNode->getContentSize().height;
    m_nodeContent->setPosition(ccp(300,cellSize.height + 100));
    mailGiftCell->setPosition(ccp(0,0));
    m_listNode->addChild(scrollView);
    scrollView->setContentSize(CCSize(600,400 + cellSize.height));
    scrollView->setContentOffset(ccp(0, nowH - needH));

    if(needH>nowH) {
        scrollView->setTouchEnabled(true);
    } else {
        scrollView->setTouchEnabled(false);
    }

    if(!m_toName.empty()) {
        m_nameEditBox->setText(m_toName.c_str());
        m_nameEditBox->setEnabled(false);
    }
    updateBtnStatus();

    return true;
}
示例#5
0
void GameUILayer::onTexturesLoaded()
{
    m_pLeft->setAnchorPoint(Point(0.0f,1.0f));
    m_pLeft->setPosition(VisibleRect::leftTop());
    
    //玩家控制的角色的头像
    auto playerIcon = SPRITE(GameConfig::getInstance()->getSelectRoleName()+"_icon_big.png");
    m_pLeft->addChild(playerIcon);
    playerIcon->setAnchorPoint(Point(0.0f,1.0f));
    playerIcon->setPosition(10, DESIGN_HEIGHT-10);
    //玩家的HP条
    auto hpBg = SPRITE("hp_value_bg.png");
    auto hp = SPRITE("hp_value.png");
    hpBg->setAnchorPoint(Point(0.0f,1.0f));
    hpBg->setPosition(10,DESIGN_HEIGHT - playerIcon->getContentSize().height - 20);
    
    hpBar = ProgressTimer::create(hp);
    hpBar->setAnchorPoint(Point(0.0f,1.0f));
    hpBar->setType(ProgressTimer::Type::BAR);
    hpBar->setMidpoint(Point::ZERO);
    hpBar->setBarChangeRate(Point(0,1));
    hpBar->setPercentage(100);
    hpBar->setPosition(hpBg->getPosition());
    m_pLeft->addChild(hpBg);
    m_pLeft->addChild(hpBar);
    
    
    //定时器 血瓶 设置
    auto hpMenuItem = MenuItemSprite::create(SPRITE("hp_icon_normal.png"), SPRITE("hp_icon_press.png"),SPRITE("hp_icon_disable.png"));
    auto timerBombItem = MenuItemSprite::create(SPRITE("timer_bomb_normal.png"), SPRITE("timer_bomb_press.png"),SPRITE("timer_bomb_disable.png"));
    auto settingItem = MenuItemSprite::create(SPRITE("setting_normal.png"), SPRITE("setting_press.png"));
    settingItem->setAnchorPoint(Point(1.0f,1.0f));
    settingItem->setPosition(VisibleRect::rightTop()-Point(20,20));
    settingItem->setCallback([](Ref *pSender)->void{
        NotificationCenter::getInstance()->postNotification(SHOW_PAUSE);
    });
    
    hpMenuItem->setAnchorPoint(Point(1.0f,1.0f));
    hpMenuItem->setPosition(VisibleRect::right()+Point(-20,100));
    timerBombItem->setAnchorPoint(hpMenuItem->getAnchorPoint());
    timerBombItem->setPosition(hpMenuItem->getPosition()-Point(0,80*GameManager::getInstance()->getScaleFactor()));
    
    timerBombItem->setScale(m_fScaleFactor);
    hpMenuItem->setScale(m_fScaleFactor);
    settingItem->setScale(m_fScaleFactor);
    
    auto menu = Menu::create(settingItem,hpMenuItem,timerBombItem,nullptr);
    addChild(menu);
    menu->ignoreAnchorPointForPosition(false);
    menu->setAnchorPoint(Point::ZERO);
    menu->setPosition(Point::ZERO);
    
    
    //玩家的装备信息
    auto infoNode = Node::create();
    infoNode->setScale(m_fScaleFactor*1.2);
    auto playerInfo = SPRITE("role_info_bg.png");
    playerInfo->setAnchorPoint(Point(0.5f,1.0f));
    infoNode->addChild(playerInfo);

    auto shoe = Label::createWithBMFont("font/font_02.fnt", "0");
    auto bomb = Label::createWithBMFont("font/font_02.fnt", Util::itoa(GameManager::getInstance()->getBombNum()));
    auto power = Label::createWithBMFont("font/font_02.fnt", "1");
    auto coin = Label::createWithBMFont("font/font_02.fnt", __String::createWithFormat("%06d",__userDefault->getIntegerForKey(KEY_COIN_NUM))->getCString());
    shoe->setPosition(playerInfo->getContentSize().width/2*-1+40,-20);
    auto pad = 70;
    power->setPosition(shoe->getPosition().x+pad,shoe->getPosition().y);
    bomb->setPosition(power->getPosition().x+pad+10,shoe->getPosition().y);
    coin->setPosition(bomb->getPosition().x+pad+10,shoe->getPosition().y);
    coin->setAnchorPoint(Point(0,0.5));
    infoNode->addChild(shoe);
    infoNode->addChild(bomb);
    infoNode->addChild(power);
    infoNode->addChild(coin);
    addChild(infoNode);
    //选择的模式以及关卡
    auto mode = SPRITE(GameConfig::getInstance()->getSelectSceneName()+"_main_sign.png");
    auto levelLabel = Label::createWithBMFont("font/font_01.fnt", __String::createWithFormat("%d",GameConfig::getInstance()->getSelectLevel())->getCString());
    auto monstersLabel = Label::createWithBMFont("font/font_01.fnt", __String::createWithFormat("%d/%d",0,GameManager::getInstance()->getMonsterCount())->getCString());
    mode->setPosition(coin->getPosition().x+coin->getContentSize().width+pad,shoe->getPosition().y);
    levelLabel->setPosition(mode->getPosition().x+mode->getContentSize().width+5,mode->getPosition().y);
    auto padding = 50;
    monstersLabel->setPosition(levelLabel->getPosition().x+levelLabel->getContentSize().width+padding,mode->getPosition().y);
    monstersLabel->setTag(kTagMonsterCountLabel);
    levelLabel->setTag(kTagLevelLabel);
    infoNode->setTag(kTagWraper);
    infoNode->addChild(mode);
    infoNode->addChild(levelLabel);
    infoNode->addChild(monstersLabel);
    infoNode->setContentSize(Size(monstersLabel->getContentSize().width+monstersLabel->getPosition().x,1));
    infoNode->setAnchorPoint(Point(0.5,1));
    infoNode->setPosition(VisibleRect::top()+Point(100,0));
    
    shoe->setTag(PlayerInfoParam::kTypeShoe);
    bomb->setTag(PlayerInfoParam::kTypeBomb);
    power->setTag(PlayerInfoParam::kTypePower);
    coin->setTag(PlayerInfoParam::kTypeCoin);
}
示例#6
0
void SpritePolygonTestDemo::initDefaultSprite(const std::string &filename, cocos2d::experimental::SpritePolygon * inst)
{
    Director::getInstance()->setClearColor(Color4F(102.f/255, 184.f/255, 204.f/255, 255.f));
    
    spp = inst;
    addChild(spp);
    auto s = Director::getInstance()->getWinSize();
    auto offset = Vec2(0.15*s.width,0);
    spp->setPosition(Vec2(s)/2 + offset);

    
    sp = Sprite::create(filename);
    addChild(sp);
    sp->setPosition(Vec2(s)/2 - offset);
    
    auto touchListener = EventListenerTouchOneByOne::create();
    touchListener->onTouchBegan = [&](Touch* touch, Event* event){
        spp->showDebug(true);
        debugForNormalSprite->setVisible(true);
        return true;
    };
    touchListener->onTouchMoved = [&](Touch* touch, Event* event){
            auto pos = touch->getDelta();
            float newScale = clampf(spp->getScale() + pos.x * 0.01f, 0.1f, 2.f);
            spp->setScale(newScale);
            sp->setScale(newScale);
    };
    touchListener->onTouchEnded = [&](Touch* touch, Event* event){
        spp->showDebug(false);
        debugForNormalSprite->setVisible(false);
    };
    _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
    
    debugForNormalSprite = DrawNode::create();
    sp->addChild(debugForNormalSprite);
    
    auto positions = new Vec2[4];
    auto spSize = sp->getContentSize();
    positions[0] = Vec2(0, spSize.height);
    positions[1] = Vec2(spSize);
    positions[2] = Vec2(spSize.width, 0);
    positions[3] = Vec2(0,0);
    debugForNormalSprite->drawPoints(positions, 4, 8, Color4F{0.0,1.0,1.0,1.0});
    debugForNormalSprite->drawLine(positions[0], positions[1], Color4F::GREEN);
    debugForNormalSprite->drawLine(positions[1], positions[2], Color4F::GREEN);
    debugForNormalSprite->drawLine(positions[2], positions[3], Color4F::GREEN);
    debugForNormalSprite->drawLine(positions[3], positions[0], Color4F::GREEN);
    debugForNormalSprite->drawLine(positions[0], positions[2], Color4F::GREEN);
    debugForNormalSprite->setVisible(false);
    
    TTFConfig ttfConfig("fonts/arial.ttf", 8);
    std::string temp = "Sprite:\nPixels drawn: ";
    auto spArea = Label::createWithTTF(ttfConfig, temp+Value((int)spSize.width*(int)spSize.height).asString());
    sp->addChild(spArea);
    spArea->setAnchorPoint(Vec2(0,1));
    
    temp = "SpritePolygon:\nPixels drawn: ";
    auto vertCount = "\nverts:"+Value((int)spp->getVertCount()).asString();
    auto sppArea = Label::createWithTTF(ttfConfig, temp+Value((int)spp->getArea()).asString()+vertCount);
    spp->addChild(sppArea);
    sppArea->setAnchorPoint(Vec2(0,1));
}
示例#7
0
bool MailWritePopUpView::init() {
    if(!PopupBaseView::init()) {
        return false;
    }
    setIsHDPanel(true);
    mType = 0;
//    auto cf = CCLoadSprite::getSF("Mail_diban.png");
    auto cf = CCLoadSprite::getSF("Mail_BG1.png");
    if (cf==NULL) {
        CCLoadSprite::doResourceByCommonIndex(6, true);
        setCleanFunction([]() {
            CCLoadSprite::doResourceByCommonIndex(6, false);
        });
    }

    auto bg = CCBLoadFile("NEWMailWriteView", this, this);
    if (CCCommonUtils::isIosAndroidPad()) {
        this->setContentSize(CCDirector::sharedDirector()->getWinSize());
    }
    else
        this->setContentSize(bg->getContentSize());
//    setTitleName(_lang("105513"));
    m_titleText->setString(_lang("105513"));
    if (CCCommonUtils::isIosAndroidPad()) {
        int extH = getExtendHeight();
        this->m_listNode->setContentSize(CCSize(m_listNode->getContentSize().width, m_listNode->getContentSize().height + extH));
        m_downNode->setPositionY(m_downNode->getPositionY() - extH);
        m_bgNode->setPositionY(m_bgNode->getPositionY() - extH);
        auto tbg = CCLoadSprite::loadResource("Mail_diban.png");
        auto tBatchNode = CCSpriteBatchNode::createWithTexture(tbg->getTexture());
        auto picBg1 = CCLoadSprite::createSprite("Mail_diban.png");
        picBg1->setAnchorPoint(ccp(0, 0));
        picBg1->setPosition(ccp(0, 0));
        picBg1->setScaleX(2.4);
        tBatchNode->addChild(picBg1);
        int maxHeight = CCDirector::sharedDirector()->getWinSize().height;
        int curHeight = picBg1->getContentSize().height;
        while(curHeight < maxHeight)
        {
            auto picBg2 = CCLoadSprite::createSprite("Mail_diban.png");
            picBg2->setAnchorPoint(ccp(0, 0));
            picBg2->setPosition(ccp(0, curHeight));
            picBg2->setScaleX(2.4);
            tBatchNode->addChild(picBg2);
            curHeight += picBg2->getContentSize().height;
        }
        m_bgNode->addChild(tBatchNode);
    }
    else {
        int extH = getExtendHeight();
        this->m_listNode->setContentSize(CCSize(m_listNode->getContentSize().width, m_listNode->getContentSize().height + extH));
        m_downNode->setPositionY(m_downNode->getPositionY() - extH);
        m_bgNode->setPositionY(m_bgNode->getPositionY() - extH);
        auto tbg = CCLoadSprite::loadResource("Mail_diban.png");
        auto tBatchNode = CCSpriteBatchNode::createWithTexture(tbg->getTexture());
        auto picBg1 = CCLoadSprite::createSprite("Mail_diban.png");
        picBg1->setAnchorPoint(ccp(0, 0));
        picBg1->setPosition(ccp(0, 0));
        tBatchNode->addChild(picBg1);
        int maxHeight = CCDirector::sharedDirector()->getWinSize().height;
        int curHeight = picBg1->getContentSize().height;
        while(curHeight < maxHeight)
        {
            auto picBg2 = CCLoadSprite::createSprite("Mail_diban.png");
            picBg2->setAnchorPoint(ccp(0, 0));
            picBg2->setPosition(ccp(0, curHeight));
            tBatchNode->addChild(picBg2);
            curHeight += picBg2->getContentSize().height;
        }
        m_bgNode->addChild(tBatchNode);
    }
//    this->m_bg->setContentSize(CCSize(m_bg->getContentSize().width, m_bg->getContentSize().height + dh));

//    this->m_nameText->setString(_lang("105505").c_str());
//    this->m_titleText->setString(_lang("105503").c_str());
//    this->m_contentText->setString(_lang("105504").c_str());

//    m_nameEditBox->setReturnType(kKeyboardReturnTypeDone);
//    m_nameEditBox->setInputFlag(kEditBoxInputFlagInitialCapsSentence);
#if (CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID)
    if(MailController::getInstance()->getChatRoomEnable() && GlobalData::shared()->playerInfo.isInAlliance())
    {
        m_nameEditBox = InputFieldMultiLine::create(CCSizeMake(410,40),"Mail_write.png",24);
        m_nameEditBox->setMaxChars(300);
        m_nameEditBox->setPosition(ccp(0, -20));
        m_nameEditBox->setLineNumber(1);
        m_nameEditBox->setFontColor({63,44,27});

        auto inviteImg = CCLoadSprite::createScale9Sprite("icon_add_mumber.png");
        m_inviteBtn = CCControlButton::create(inviteImg);
        m_inviteBtn->setPreferredSize(CCSize(40, 40));
        m_inviteBtn->setPosition(ccp(430,0));
        m_inviteBtn->setAnchorPoint(ccp(0,0.5));
        m_inviteBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(MailWritePopUpView::onInvitePlayer), CCControlEventTouchUpInside);
        this->m_nameContainer->addChild(m_inviteBtn);
    }
    else
    {
        m_nameEditBox = InputFieldMultiLine::create(CCSizeMake(475,40),"Mail_write.png",24);
        m_nameEditBox->setMaxChars(30);
        m_nameEditBox->setPosition(ccp(0, -20));
        m_nameEditBox->setLineNumber(1);
        m_nameEditBox->setFontColor({63,44,27});
    }
#elif (CC_TARGET_PLATFORM==CC_PLATFORM_IOS)
    if (!ChatServiceCocos2dx::enableChatRoom) {
        m_nameEditBox = InputFieldMultiLine::create(CCSizeMake(475,40),"Mail_write.png",24);
        m_nameEditBox->setMaxChars(30);
        m_nameEditBox->setPosition(ccp(0, -20));
        m_nameEditBox->setLineNumber(1);
        m_nameEditBox->setFontColor({63,44,27});
    } else {
        if(GlobalData::shared()->playerInfo.isInAlliance())
        {
            m_nameEditBox = InputFieldMultiLine::create(CCSizeMake(410,40),"Mail_write.png",24);
            m_nameEditBox->setMaxChars(300);
            m_nameEditBox->setPosition(ccp(0, -20));
            m_nameEditBox->setLineNumber(1);
            m_nameEditBox->setFontColor({63,44,27});
            //显示加号按钮
            auto inviteImg = CCLoadSprite::createScale9Sprite("icon_add_mumber.png");
            m_inviteBtn = CCControlButton::create(inviteImg);
            m_inviteBtn->setPreferredSize(CCSize(40, 40));
            m_inviteBtn->setPosition(ccp(430,0));
            m_inviteBtn->setAnchorPoint(ccp(0,0.5));
            m_inviteBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(MailWritePopUpView::onInvitePlayer), CCControlEventTouchUpInside);
            this->m_nameContainer->addChild(m_inviteBtn);
        }
        else
        {
            m_nameEditBox = InputFieldMultiLine::create(CCSizeMake(475,40),"Mail_write.png",24);
            m_nameEditBox->setMaxChars(30);
            m_nameEditBox->setPosition(ccp(0, -20));
            m_nameEditBox->setLineNumber(1);
            m_nameEditBox->setFontColor({63,44,27});
        }

    }

#endif

    this->m_nameContainer->addChild(m_nameEditBox);

//    m_titleEditBox = InputFieldMultiLine::create(CCSizeMake(475,40),"UI_Alliance_TextBox.png",24);
//    m_titleEditBox->setMaxChars(30);
//    m_titleEditBox->setLineNumber(1);
//    m_titleEditBox->setPosition(ccp(0, -20));
//    m_titleEditBox->setFontColor({63,44,27});
////    m_titleEditBox->setReturnType(kKeyboardReturnTypeDone);
////    m_titleEditBox->setInputFlag(kEditBoxInputFlagInitialCapsSentence);
//    this->m_titleContainer->addChild(m_titleEditBox);

    m_contentEditBox = InputFieldMultiLine::create(m_contentContainer->getContentSize(),"Mail_write.png",24);
    m_contentEditBox->setMaxChars(300);
    m_contentEditBox->setLineNumber(5);
    m_contentEditBox->setPosition(ccp(0, 0));
//    m_contentEditBox->setFontSize(24);
//    m_contentEditBox->setMaxLength(300);
    m_contentEditBox->setFontColor({63,44,27});
//    m_contentEditBox->setReturnType(kKeyboardReturnTypeDone);
//    m_contentEditBox->setInputFlag(kEditBoxInputFlagInitialCapsSentence);
    this->m_contentContainer->addChild(m_contentEditBox);

    if(!m_toName.empty()) {
        m_nameEditBox->setText(m_toName.c_str());
        if(!m_allianceId.empty() || !m_thanksMail.empty()) {
            m_nameEditBox->setEnabled(false);
        }
    }
    if(!m_thanksMail.empty()) {
        m_contentEditBox->setText(_lang("101387"));
    }
    if(m_title != "") {
//        m_titleEditBox->setText(LocalController::shared()->TextINIManager()->getObjectByKey("105511", "1", m_title.c_str()).c_str());
    }
    updateBtnStatus();
//    m_waitInterface = NULL;
    return true;
}
CCScene::CCScene()
{
	m_bIsRelativeAnchorPoint = false;
	setAnchorPoint(ccp(0.5f, 0.5f));
}
bool HomeSceneLayer::init(){
    
    if (!Layer::init()) {
        
        return false;
    }
    //对手机返回键的监听
    auto listener = EventListenerKeyboard::create();
    //和回调函数绑定
    listener->onKeyReleased = CC_CALLBACK_2(HomeSceneLayer::onKeyReleased,this);
    //添加到事件分发器中
    Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener,this);
    
    
    //SpriteFrameCache::getInstance()->addSpriteFramesWithFile("UIResource_ch.plist");
    
    auto sky=Sprite::createWithSpriteFrameName("sky.png");
    
    sky->setAnchorPoint(Vec2(1.0,1.0));
    
    sky->setPosition(Vec2(WINSIZE_WIDTH,WINSIZE_HEIGHT));
    
    this->addChild(sky);
    
    auto cloud_01=Sprite::createWithSpriteFrameName("cloud_01.png");
    cloud_01->setPosition(CLOUD_01_VEC2);
    this->addChild(cloud_01);
    
    auto moveBy_01=MoveBy::create(15,Vec2(WINSIZE_WIDTH-250,0));
    auto rev_01=moveBy_01->reverse();
    auto seq_01=Sequence::create(moveBy_01,rev_01, NULL);
    cloud_01->runAction(RepeatForever::create(seq_01));
    
    auto cloud_02=Sprite::createWithSpriteFrameName("cloud_02.png");
    cloud_02->setPosition(CLOUD_02_VEC2);
    this->addChild(cloud_02);
    
    auto moveBy_02=MoveBy::create(13,Vec2(-WINSIZE_WIDTH+250,0));
    auto rev_02=moveBy_02->reverse();
    auto seq_02=Sequence::create(moveBy_02,rev_02, NULL);
    cloud_02->runAction(RepeatForever::create(seq_02));
    
    auto cloud_03=Sprite::createWithSpriteFrameName("cloud_03.png");
    cloud_03->setPosition(Vec2(cloud_03->getContentSize().width/2,400));
    this->addChild(cloud_03);
    
    auto cloud_04=Sprite::createWithSpriteFrameName("cloud_04.png");
    cloud_04->setPosition(Vec2(WINSIZE_WIDTH-50,380));
    this->addChild(cloud_04);
    
    auto wall=Sprite::createWithSpriteFrameName("wall.png");
    
    wall->setAnchorPoint(Vec2(0.5,0));
    
    wall->setPosition(Vec2(WINSIZE_WIDTH/2,0));
    
    this->addChild(wall);
    
    auto Defend_monk=Sprite::createWithSpriteFrameName("Defend_monk.png");
    
    Defend_monk->setPosition(Vec2(320,670));
    
    this->addChild(Defend_monk);
    
    auto best_score=Sprite::createWithSpriteFrameName("best_score.png");
    
    best_score->setPosition(Vec2(320,520));
    
    this->addChild(best_score);
    
    auto labFont=Label::createWithBMFont("fonts.fnt","0");
    
    if (Value(UserDefault::getInstance()->getStringForKey("string").c_str()).asInt()!=0) {
        
        labFont->setString(UserDefault::getInstance()->getStringForKey("string").c_str());
        
    }
    
    labFont->setAnchorPoint(Vec2(0,0));//左对齐
    
    labFont->setPosition(Vec2(304,502));
    
    
    this->addChild(labFont);
    
    float baseX=106;  //设定初始值,即第一个和尚的X,Y轴坐标。
    float baseY=235;
    for (int i=0;i<5;i++)
    {                                                 //循环5次,创建五个精灵对象
        
        __String  *fileName=__String::createWithFormat("monk_0%d.png",i+1); //fileName存储变换的路径字符串
        
        auto monkSpr=Sprite::createWithSpriteFrameName(fileName->getCString()); //获得fileName对象存储的路径
        
        monkSpr->setPosition(Vec2(baseX,baseY));
        
        this->addChild(monkSpr);
        
        baseX+=107; //从第二个和尚开始加X坐标值加120
        
    }
    
    auto StartItem = MenuItemSprite::create(
                                           Sprite::createWithSpriteFrameName("start_01.png"),
                                           Sprite::createWithSpriteFrameName("start_02.png"),
                                           CC_CALLBACK_1(HomeSceneLayer::menuStartCallback, this));
    
    StartItem->setPosition(Vec2(320,410));
    
    
    auto CommentItem = MenuItemSprite::create(
                                             Sprite::createWithSpriteFrameName("comment_01.png"),
                                             Sprite::createWithSpriteFrameName("comment_02.png"),
                                           CC_CALLBACK_1(HomeSceneLayer::menucommentCallback, this));
    
    CommentItem->setPosition(Vec2(132,110));
    
    auto FeedbackItem = MenuItemSprite::create(
                                            Sprite::createWithSpriteFrameName("feedback_01.png"),
                                            Sprite::createWithSpriteFrameName("feedback_02.png"),
                                           CC_CALLBACK_1(HomeSceneLayer::menuFeedbackCallback, this));
    
    FeedbackItem->setPosition(Vec2(320,110));
    
    auto ShareItem = MenuItemSprite::create(
                                           Sprite::createWithSpriteFrameName("share_01.png"),
                                           Sprite::createWithSpriteFrameName("share_02.png"),
                                           CC_CALLBACK_1(HomeSceneLayer::menuShareCallback, this));
    
    ShareItem->setPosition(Vec2(508,110));
    
    
    
    
    auto menu = Menu::create(StartItem,CommentItem,FeedbackItem,ShareItem,NULL);
    menu->setPosition(Vec2::ZERO);
    this->addChild(menu);
    


    return true;
}
示例#10
0
bool GameScene::init()
{
    if (!Layer::init()) {
        return false;
    }
    
    CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("whack.caf");
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    
    auto bg = Sprite::createWithSpriteFrameName("bg_dirt.png");
    bg->setScale(2);
    bg->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2));
    this->addChild(bg, -2);
    
    auto upperGrass = Sprite::createWithSpriteFrameName("grass_upper.png");
    upperGrass->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM);
    upperGrass->setPosition(visibleSize.width/2, visibleSize.height/2);
    this->addChild(upperGrass, -1);
    
    auto lowerGrass = Sprite::createWithSpriteFrameName("grass_lower.png");
    lowerGrass->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT);
    lowerGrass->setPosition(Vec2(0, visibleSize.height/2));
    this->addChild(lowerGrass, 2);
    
    auto mole1 = Sprite::createWithSpriteFrameName("mole_1.png");
    mole1->setPosition(Vec2(visibleSize.width/2-144, visibleSize.height/2-65));
    this->addChild(mole1, 1);
    _molesVector.pushBack(mole1);
    
    auto mole2 = Sprite::createWithSpriteFrameName("mole_1.png");
    mole2->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2-65));
    this->addChild(mole2, 1);
    _molesVector.pushBack(mole2);
    
    auto mole3 = Sprite::createWithSpriteFrameName("mole_1.png");
    mole3->setPosition(Vec2(visibleSize.width/2+144, visibleSize.height/2-65));
    this->addChild(mole3, 1);
    _molesVector.pushBack(mole3);
    
    _successScore = 15 + (_level*5 - 5);
    _totalMoles = 20 + (_level*5 - 5);
    _popDelay = 0.5 - (_level*0.05 - 0.05);
    
    std::string levelStr = StringUtils::format("关卡:%d", _level);
    _levelLabel = Label::createWithSystemFont(levelStr, "fonts/Marker Felt.ttf", 16);
    _levelLabel->setPosition(visibleSize.width*0.1, visibleSize.height-20);
    this->addChild(_levelLabel,10);
    
    std::string scoreStr = StringUtils::format("本关得分:%d", _score);
    _scoreLab = Label::createWithSystemFont(scoreStr, "fonts/Marker Felt.ttf", 16);
    _scoreLab->setPosition(visibleSize.width*0.3, visibleSize.height-20);
    this->addChild(_scoreLab,10);
    
    std::string moleStr = StringUtils::format("本关地鼠:%d", _totalMoles);
    _moleLabel = Label::createWithSystemFont(moleStr, "fonts/Marker Felt.ttf", 16);
    _moleLabel->setPosition(visibleSize.width*0.55, visibleSize.height-20);
    this->addChild(_moleLabel,10);
    
    std::string successStr = StringUtils::format("过关目标分:%d", _successScore);
    _passLabel = Label::createWithSystemFont(successStr, "fonts/Marker Felt.ttf", 16);
    _passLabel->setPosition(visibleSize.width*0.85, visibleSize.height-20);
    this->addChild(_passLabel,10);
    
    
    this->schedule(schedule_selector(GameScene::andomPopMoles), _popDelay);
    this->schedule(schedule_selector(GameScene::gameOver), _popDelay);
    
    auto listener = EventListenerTouchOneByOne::create();
    listener->onTouchBegan = [=](Touch* touch, Event* event){
        Point p = this->convertTouchToNodeSpace(touch);
        for (auto mole : _molesVector) {
            if (mole->getTag() == 0) continue;
            
            if (mole->getBoundingBox().containsPoint(p))
            {
                _score += 1;
                
                auto mallter = Sprite::createWithSpriteFrameName("mallet1.png");
                mallter->setScale(0.8);
                mallter->setPosition(mole->getPosition().x+mole->getContentSize().width/2-10, mole->getPosition().y+80);
                this->addChild(mallter,3);
                
                auto animate = Animate::create(AnimationCache::getInstance()->getAnimation("mallet"));
                mallter->runAction(Sequence::create(animate, CallFunc::create([=]{
                    CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("ow.caf");
                    //播放粒子效果
                    auto aswoon = ParticleSystemQuad::create("aswoon.plist");
                    aswoon->setPosition(mole->getPosition());
                    this->addChild(aswoon);
                    //移除木槌
                    this->removeChild(mallter);
                    
                }), NULL));
                
                 _scoreLab->setString(StringUtils::format("本关得分:%d", _score));
                //地鼠打中后修改tag为0
                mole->setTag(0);
                mole->stopAllActions();
                
                //播放地鼠被打中动画
                auto hitAnimate = Animate::create(AnimationCache::getInstance()->getAnimation("thump"));
                auto moveDown = MoveBy::create(0.2f, Point(0, -mole->getContentSize().height));
                auto easeMoveDown = EaseInOut::create(moveDown, 3.0f);
                mole->runAction(Sequence::create(hitAnimate, easeMoveDown, NULL));
                
            }
            
        }
        
        return true;
    };
    
    //活动监听器
    Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);
    
    return true;
}
示例#11
0
void TaskDialog::initPanel()
{
	WINSIZE;
	int w = 600;
	int h = 350;

	float border=20.0f;//间隙
	float liaotianExtern=30.0f;//聊天框的格外宽度(那个角)
	nameHeight=30.0f;//名称高度
	setAnchorPoint(ccp(0.5f,0.5f));
	setContentSize(CCSizeMake(w,h));
	setPosition(ccp(winSize.width/2,winSize.height/2));

	//背景
	Scale9Sprite *bg=Scale9Sprite::createWithSpriteFrameName(DIALOG_BG,DIALOG_BG_CCRect);
	bg->setContentSize(getContentSize());
	bg->setAnchorPoint(Point::ZERO);
	bg->setTag(TASKDIALOG_BG_TAG);
	addChild(bg);

	//聊天框
	Scale9Sprite *liaotian=Scale9Sprite::createWithSpriteFrameName(DIALOG_LIAOTIAN,DIALOG_LIAOTIAN_CCRect);
	liaotian->setContentSize(CCSizeMake(w/4*3,h-border*2));
	liaotian->setAnchorPoint(Point::ZERO);
	liaotian->setPosition(getContentSize().width-border-liaotian->getContentSize().width,border);
	addChild(liaotian);

	//头像
	char str[50];
	if (currentTaskInfo->status==QUEST_STATUS_COMPLETE)
	{
		std::sprintf(str,"%d.png",currentTaskInfo->m_taskDetail.m_completeNPC);
	}
	else
	{
        std::sprintf(str,"%d.png",currentTaskInfo->m_taskDetail.m_anwserNPC);
	}

	touxiang=CCSprite::createWithSpriteFrameName(str);
	touxiang->setAnchorPoint(Point::ZERO);
	touxiang->setPosition(ccp(25,200));
	addChild(touxiang);

	taskDetailStr = InternationManager::getInstance().getCharacterText("task_label_0070");
	taskAwardStr = InternationManager::getInstance().getCharacterText("task_label_0100");//任务奖励
	maohaoStr = InternationManager::getInstance().getCharacterText("maohao");
	expStr = InternationManager::getInstance().getCharacterText("general_label_0038");//经验
	finishStr = InternationManager::getInstance().getCharacterText("dialog_text_0030");
	leaveStr = InternationManager::getInstance().getCharacterText("dialog_text_0020");
	acceptStr = InternationManager::getInstance().getCharacterText("dialog_text_0440");

	//显示元素
	tableViewCellNode = Node::create();
	tableViewCellNode->autorelease();
	CC_SAFE_RETAIN(tableViewCellNode);

	//分割线
	fengexian=CCSprite::createWithSpriteFrameName("dialog_fengexian.png");
	tableViewCellNode->addChild(fengexian,FENGEXIAN_ZORDER);

	//任务标题
	cocos2d::CCLabelTTF* taskTitle = cocos2d::CCLabelTTF::create("leenini", FONT_NAME_DEFAULT, 26, Size::ZERO, kCCTextAlignmentLeft);
	taskTitle->setAnchorPoint(ccp(0.5f,0));
	taskTitle->setPosition(ccp(w/2, h-50));
	taskTitle->setTag(10);
	taskTitle->setColor(CH_GREEN);

	Scale9Sprite* s9sNormal;
	Scale9Sprite* s9sSelected;
	CCSize btnSize = CCSize(100, 45);
	CCRect btnRect = Rect(30,8,30,9);
	const char* normalStr = "button.png";
	const char* selectedStr = "button.png";

	//接收任务按钮
	s9sNormal = Scale9Sprite::createWithSpriteFrameName(normalStr, btnRect);
	s9sNormal->setContentSize(btnSize);
	s9sSelected = Scale9Sprite::createWithSpriteFrameName(selectedStr, btnRect);
	s9sSelected->setContentSize(btnSize);
	WXSimpleButton* rightBtn = WXSimpleButton::createWithNode(s9sNormal, s9sSelected, NULL, "RIGHT");
	rightBtn->setTarget(this, menu_selector(TaskDialog::btnCallback));
	rightBtn->setPosition(ccp(getContentSize().width-border*3/2-rightBtn->getContentSize().width/2,rightBtn->getContentSize().height/2+border*3/2));
	rightBtn->setTag(2);

	//关闭按钮
	WXSimpleButton* close_button = WXSimpleButton::createWithSpriteFrameName(CLOSE_BTN_45_45_NORMAL,CLOSE_BTN_45_45_SELECTED,this,menu_selector(TaskDialog::btnCallback));
	close_button->setPosition(w-GAP*2,h-GAP*2);
	close_button->setTag(1);

	WXMenu* menu = WXMenu::create(rightBtn,close_button, NULL);
	menu->setAnchorPoint(Point::ZERO);
	menu->setPosition(Point::ZERO);
	menu->setTag(1000);
	//menu->alignItemsHorizontallyWithPadding(150);
	addChild(menu,MENU_ZORDER);

	tableViewSize = CCSizeMake(liaotian->getContentSize().width-liaotianExtern-border*2, liaotian->getContentSize().height
		-border*2);

	//awardLabel=WXRichLabelEx::create();
	//awardLabel->Initialize(FONT_ALIAS_DEFAULT_20, tableViewSize);
	//awardLabel->setVisible(false);
	//awardLabel->setPosition(liaotian->getPositionX()+liaotianExtern+border,liaotian->getContentSize().height/2+border/2);
	//this->addChild(awardLabel);

	//任务奖励
	bounsGridPanel = WXGridPanel::create();
	std::vector<CCPoint> tplist;
	tplist.push_back(ccp(100, 0));
	tplist.push_back(ccp(200, 0));
	tplist.push_back(ccp(300, 0));
	tplist.push_back(ccp(400, 0));
	bounsGridPanel->createGrids(tplist, GRID_BG, NULL, NULL);
	tableViewCellNode->addChild(bounsGridPanel);

	tableView = WXTableView::create(this, tableViewSize);
	tableView->setDirection(ScrollView::Direction::VERTICAL);
	tableView->setVerticalFillOrder(TableView::VerticalFillOrder::TOP_DOWN);
	tableView->setDelegate(this);
	tableView->setPosition(ccp(liaotian->getPositionX()+liaotianExtern+border,liaotian->getPositionY()+border));
	addChild(tableView);
}
示例#12
0
void Label::alignText()
{
    if (_reusedLetter == nullptr)
    {
        return;
    }

    for (const auto& batchNode:_batchNodes)
    {
        batchNode->getTextureAtlas()->removeAllQuads();
    }
    _fontAtlas->prepareLetterDefinitions(_currentUTF16String);
    auto textures = _fontAtlas->getTextures();
    if (textures.size() > _batchNodes.size())
    {
        for (auto index = _batchNodes.size(); index < textures.size(); ++index)
        {
            auto batchNode = SpriteBatchNode::createWithTexture(textures[index]);
            batchNode->setAnchorPoint(Point::ANCHOR_TOP_LEFT);
            batchNode->setPosition(Point::ZERO);
            Node::addChild(batchNode,0,Node::INVALID_TAG);
            _batchNodes.push_back(batchNode);
        }
    }
    LabelTextFormatter::createStringSprites(this);    
    if(_maxLineWidth > 0 && _contentSize.width > _maxLineWidth && LabelTextFormatter::multilineText(this) )      
        LabelTextFormatter::createStringSprites(this);
    
    if(_currNumLines > 1 && _alignment != TextHAlignment::LEFT)
        LabelTextFormatter::alignText(this);
  
    int strLen = cc_wcslen(_currentUTF16String);
    Rect uvRect;
    Sprite* letterSprite;
    for(const auto &child : _children) {
        int tag = child->getTag();
        if(tag >= strLen)
        {
            SpriteBatchNode::removeChild(child, true);
        }
        else if(tag >= 0)
        {
            letterSprite = dynamic_cast<Sprite*>(child);
            if (letterSprite)
            {
                uvRect.size.height = _lettersInfo[tag].def.height;
                uvRect.size.width  = _lettersInfo[tag].def.width;
                uvRect.origin.x    = _lettersInfo[tag].def.U;
                uvRect.origin.y    = _lettersInfo[tag].def.V;

                letterSprite->setTexture(textures[_lettersInfo[tag].def.textureID]);
                letterSprite->setTextureRect(uvRect);
            }          
        }
    }
    
    int index;
    for (int ctr = 0; ctr < strLen; ++ctr)
    {        
        if (_lettersInfo[ctr].def.validDefinition)
        {
            updateSpriteWithLetterDefinition(_lettersInfo[ctr].def,textures[_lettersInfo[ctr].def.textureID]);
            _reusedLetter->setPosition(_lettersInfo[ctr].position);
            index = _batchNodes[_lettersInfo[ctr].def.textureID]->getTextureAtlas()->getTotalQuads();
            _batchNodes[_lettersInfo[ctr].def.textureID]->insertQuadFromSprite(_reusedLetter,index);
        }     
    }

    updateColor();
}