bool GeneralDialogTest::init()
{
    if (CCLayer::init())
    {
        //正常状态按钮
        CCScale9Sprite *backgroundButton = CCScale9Sprite::create("button.png");
        //按下效果
        CCScale9Sprite *backgroundHighlightedButton = CCScale9Sprite::create("buttonHighlighted.png");
        //按钮的大小根据标题变化
        CCLabelTTF *titleButton = CCLabelTTF::create("Touch Me!", "Marker Felt", 30);
        //按钮颜色
        titleButton->setColor(ccc3(159, 168, 176));
        
        CCControlButton* controlButton = CCControlButton::create(titleButton, backgroundButton);
        controlButton->setBackgroundSpriteForState(backgroundHighlightedButton, CCControlStateHighlighted);
        controlButton->setTitleColorForState(ccWHITE, CCControlStateHighlighted);
        
//        controlButton->setAnchorPoint(ccp(0.5f, 1));
        controlButton->setPosition(ccp(640/2, 960/5));
        addChild(controlButton);
        /* 当鼠标处于按下并曾经点中按钮的状态下,鼠标松开且在按钮范围内,则触发一次 */
        controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(GeneralDialogTest::touchUpInside), CCControlEventTouchUpInside);
        return true;
    }
    return false;
}
Example #2
0
CCControlButton* ButtonUtils::createButton(const char *normalFrame, const char *highLightFrame, const char *disableFrame, cocos2d::CCSize size, const char *label,float labelSize ,ccColor3B labelColor)
{
    CCScale9Sprite *normal = CCScale9Sprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(normalFrame));
    CCScale9Sprite *highLight = CCScale9Sprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(highLightFrame));
    CCScale9Sprite *disable = CCScale9Sprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(disableFrame));
    CCControlButton *btn = CCControlButton::create(label, "Arial", labelSize);
    btn->setPreferredSize(size);
    btn->setBackgroundSpriteForState(normal, CCControlStateNormal);
    btn->setBackgroundSpriteForState(highLight, CCControlStateHighlighted);
    btn->setBackgroundSpriteForState(disable, CCControlStateDisabled);
    btn->setTitleColorForState(labelColor, CCControlStateNormal);
    btn->setTitleColorForState(labelColor, CCControlStateHighlighted);
    btn->setTitleColorForState(labelColor, CCControlStateDisabled);
    btn->setTouchPriority(0);
    
    return btn;
}
Example #3
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

    /////////////////////////////
    // 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
    CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
                                        "CloseNormal.png",
                                        "CloseSelected.png",
                                        this,
                                        menu_selector(HelloWorld::menuCloseCallback));
    
	pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
                                origin.y + pCloseItem->getContentSize().height/2));

    // create menu, it's an autorelease object
    CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
    pMenu->setPosition(CCPointZero);
    this->addChild(pMenu, 1);

    /////////////////////////////
    // 3. add your codes below...

    // add a label shows "Hello World"
    // create and initialize a label
    
    CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24);
    
    // position the label on the center of the screen
    pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - pLabel->getContentSize().height));

    // add the label as a child to this layer
    this->addChild(pLabel, 1);

	CCRect rect1(133, 333, 42, 46);
	CCScale9Sprite* btnNormal = CCScale9Sprite::create("char_bluelight.png",rect1);  
	CCScale9Sprite* btnDown = CCScale9Sprite::create("char_bluelight.png",rect1);  
	CCControlButton* controlBtn = CCControlButton::create(btnNormal);  
	controlBtn->setBackgroundSpriteForState(btnDown, CCControlStateSelected);  
	controlBtn->setPosition(ccp(visibleSize.width/2, visibleSize.height/2));  
	controlBtn->setPreferredSize(CCSize(60, 50));  
	controlBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchDownAction), CCControlEventTouchDown);
	this->addChild(controlBtn);  
    
    return true;
}
bool HelloWorld::init()
{
    if ( !CCLayer::init() )
    {
        return false;
    }

//获取可视区域尺寸大小
	CCSize mysize = CCDirector::sharedDirector()->getVisibleSize();
//获取可视区域的原点位置
	CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
//屏幕正中心位置
	CCPoint midPos = ccp(mysize.width/2, mysize.height/2);


//显示按钮状态的标签displayLabel
	displayLabel = CCLabelTTF::create("No Event", "Marker Felt", 32);
	displayLabel->setPosition( midPos + ccp(0, 100) );
	this->addChild(displayLabel);


//按钮中的背景精灵CCScale9Sprite
	CCScale9Sprite* bgNormal = CCScale9Sprite::create("btnNormal.png"); //正常背景
	CCScale9Sprite* bgHighlighted = CCScale9Sprite::create("btnHighlighted.png"); //高亮背景

//按钮中的标签CCLabelTTF
	CCLabelTTF* titleNormal = CCLabelTTF::create("Button is Normal !", "Marker Felt", 30);
	CCLabelTTF* titleHighlighted = CCLabelTTF::create("Button is Highlighted !", "Marker Felt", 30);


//创建按钮CCControlButton
	CCControlButton* btn = CCControlButton::create(titleNormal, bgNormal);
	btn->setPosition( midPos );
	this->addChild(btn);

//设置按钮高亮时的状态
	btn->setTitleLabelForState(titleHighlighted, CCControlStateHighlighted); //高亮标签
	btn->setTitleColorForState(ccRED, CCControlStateHighlighted); //红色
	btn->setBackgroundSpriteForState(bgHighlighted, CCControlStateHighlighted); //高亮背景

	//写了这句话,反而大小被固定了。没有按照label的大小进行自动伸展了
	//btn->setPreferredSize( CCSizeMake(120,40) );

//绑定事件,用于显示按钮状态
	btn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchDownAction), CCControlEventTouchDown); //刚刚开始触摸按钮时
	btn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchDragInsideAction), CCControlEventTouchDragInside);  //在内部拖动时(保持触摸状态下)
	btn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchDragOutsideAction), CCControlEventTouchDragOutside); //在外部拖动时(保持触摸状态下)
	btn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchDragEnterAction), CCControlEventTouchDragEnter);  //拖动刚进入内部时(保持触摸状态下)
	btn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchDragExitAction), CCControlEventTouchDragExit); //拖动刚离开内部时(保持触摸状态下)
	btn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchUpInsideAction), CCControlEventTouchUpInside); //在内部抬起手指(保持触摸状态下)
	btn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchUpOutsideAction), CCControlEventTouchUpOutside); //在外部抬起手指(保持触摸状态下)
	btn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchCancelAction), CCControlEventTouchCancel); //取消触点

	return true;
}
Example #5
0
bool HelloScene::init()
{
    if (!CCLayer::init())
    {
        return false;
    }

    CCSprite *bg = CCSprite::create("background.png");
    bg->setPosition(VisibleRect::center());
    //CCSize &winSize = CCDirector::sharedDirector()->getWinSize();
    //float scalex = winSize.width / 480;
    //float scaley = winSize.height / 800;
    //bg->setScaleX(scalex);
    //bg->setScaleY(scaley);
    addChild(bg);

    const CCPoint &center = VisibleRect::center();

    CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
        "CloseNormal.png",
        "CloseSelected.png",
        this,
        menu_selector(HelloScene::menuCloseCallback));
    pCloseItem->setPosition(ccp(VisibleRect::rightBottom().x - pCloseItem->getContentSize().width/2 ,
        pCloseItem->getContentSize().height/2));
    CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
    pMenu->setPosition(CCPointZero);
    this->addChild(pMenu, 1);

    CCLabelTTF *title = CCLabelTTF::create("Lovexin Plane Chess", "Arial", 40);
    title->setPosition(ccp(center.x, center.y + 250));
    CCLabelTTF *author = CCLabelTTF::create("made by Waltz Duyf", "Arial", 20);
    author->setPosition(ccp(center.x + 100, center.y + 200));
    addChild(title);
    addChild(author);

    addSetupSwitch(ccp(center.x - 120, center.y + 50 ), "RED", ccc3(255, 0, 0), FORCE_COLOR_RED);//, cccontrol_selector(HelloScene::valueChangedJoinInR), cccontrol_selector(HelloScene::valueChangedAIR));
    addSetupSwitch(ccp(center.x - 120, center.y - 10 ), "YEL", ccc3(234, 165, 0), FORCE_COLOR_YELLOW);//, cccontrol_selector(HelloScene::valueChangedJoinInY), cccontrol_selector(HelloScene::valueChangedAIY));
    addSetupSwitch(ccp(center.x - 120, center.y - 70 ), "GRE", ccc3(0, 255, 0), FORCE_COLOR_GREEN);//, cccontrol_selector(HelloScene::valueChangedJoinInG), cccontrol_selector(HelloScene::valueChangedAIG));
    addSetupSwitch(ccp(center.x - 120, center.y - 130), "BLU", ccc3(0, 144, 255), FORCE_COLOR_BLUE);//, cccontrol_selector(HelloScene::valueChangedJoinInB), cccontrol_selector(HelloScene::valueChangedAIB));

    CCScale9Sprite *backgroundButton = CCScale9Sprite::create("button.png");
    CCScale9Sprite *backgroundHighlightedButton = CCScale9Sprite::create("buttonHighlighted.png");
    CCLabelTTF *titleButton = CCLabelTTF::create("Play Now", "Arial", 30);
    titleButton->setColor(ccc3(159, 168, 176));
    CCControlButton *button = CCControlButton::create(titleButton, backgroundButton);
    button->setBackgroundSpriteForState(backgroundHighlightedButton, CCControlStateHighlighted);
    button->setTitleColorForState(ccWHITE, CCControlStateHighlighted);
    button->setMargins(70, 20);
    button->setPosition(ccp(center.x, center.y - 250));
    addChild(button);
    button->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloScene::playBtnCallback), CCControlEventTouchUpInside);

    return true;
}
Example #6
0
void guankaScene::jumpBtn() {
    CCSize screenSize = CCDirector::sharedDirector()->getVisibleSize();
    
    CCLabelTTF* jumptext = CCLabelTTF::create("Jump!!", "Arial", 40);
    CCScale9Sprite* noDownbtn = CCScale9Sprite::create("button.png");
    CCScale9Sprite* downbtn = CCScale9Sprite::create("buttonDown.png");
    CCControlButton* Btnjump = CCControlButton::create(jumptext, noDownbtn);
    Btnjump->setPosition(ccp(screenSize.width-80, 50));
    Btnjump->setBackgroundSpriteForState(downbtn, extension::CCControlStateHighlighted);
    Btnjump->addTargetWithActionForControlEvents(this, cccontrol_selector(guankaScene::jumpEvent),CCControlEventTouchDown);
    this->addChild(Btnjump,1);
}
Example #7
0
CTableSprite CStar97Game::CreateTableSprite()
{
	CTableSprite tableSprite;
	CCSize szBKSize;

	if (m_pResManager->GenerateNodeByCfgID(eSpriteType_Cfg, Star97_Room_Table, tableSprite.m_pTableBK))
	{
		szBKSize = tableSprite.m_pTableBK->getContentSize();
		tableSprite.m_pTableBK->setAnchorPoint(ccp(0.5f, 0.5f));
		tableSprite.m_pTableBK->setScale(1.4f);
	}
	if (m_pResManager->GenerateNodeByCfgID(eSpriteType_Cfg, Star97_Room_Table_P, tableSprite.m_pTableP))
	{
		szBKSize = tableSprite.m_pTableP->getContentSize();
		tableSprite.m_pTableP->setAnchorPoint(ccp(0.0f, 0.0f));
		tableSprite.m_pTableP->setPosition(CCPoint(0,0));
		tableSprite.m_pTableP->setZOrder(tableSprite.m_pTableBK->getZOrder()+1);
		tableSprite.m_pTableBK->addChild(tableSprite.m_pTableP);
	}
	//桌子编号
	if (m_pResManager->GenerateNodeByCfgID(eSpriteType_Base, Star97_Room_Table_Num_Font, tableSprite.m_pTableNum))
	{
		szBKSize = tableSprite.m_pTableBK->getContentSize();
		tableSprite.m_pTableNum->setAnchorPoint(ccp(0.5, 0.5));
		tableSprite.m_pTableNum->setPosition(ccp(120.f,240.f));
		//tableSprite.m_pTableNum->setScale(0.3f);
		if (NULL != tableSprite.m_pTableBK)
		{
			tableSprite.m_pTableBK->addChild(tableSprite.m_pTableNum);
		}
	}

	//游戏桌子编号
	if (m_pResManager->GenerateNodeByCfgID(eSpriteType_Base, Star97_Room_Table_Num_Font, tableSprite.m_pTableNumP))
	{
		tableSprite.m_pTableNumP->setAnchorPoint(ccp(0.5, 0.5));
		tableSprite.m_pTableNumP->setPosition(ccp(120.f,240.f));
		//tableSprite.m_pTableNumP->setScale(0.3f);
		if (NULL != tableSprite.m_pTableP)
		{
			tableSprite.m_pTableP->addChild(tableSprite.m_pTableNumP);
		}
	}

	//座位
	for (int n = 0; n < 1; n++)
	{
		CSeatSprite seat;

		CCLabelTTF *titleButton = CCLabelTTF::create("", "Arial", 30);
		if (NULL == titleButton)
		{
			ERROR_CHECK;
			break;
		}
		titleButton->setColor(ccc3(159, 168, 176));

		CCScale9Sprite *backgroundButton = NULL;
		if (!m_pResManager->GenerateNodeByCfgID(eSpriteType_Cfg, Star97_Room_Sit, backgroundButton))
		{
			ERROR_CHECK;
			break;
		}

		CCControlButton* pButton = CMoveableButton::create(titleButton, backgroundButton);
		if (NULL == pButton)
		{
			ERROR_CHECK;
			break;
		}

		CCScale9Sprite *backgroundHighlightedButton = NULL;
		if (m_pResManager->GenerateNodeByCfgID(eSpriteType_Cfg, Star97_Room_Sit, backgroundHighlightedButton))
		{
			pButton->setBackgroundSpriteForState(backgroundHighlightedButton, CCControlStateHighlighted);
		}

		CCScale9Sprite *backgroundDisibleButton = NULL;
		if (m_pResManager->GenerateNodeByCfgID(eSpriteType_Cfg, Star97_Room_Sit_D, backgroundDisibleButton))
		{
			pButton->setBackgroundSpriteForState(backgroundDisibleButton, CCControlStateDisabled);
		}

		pButton->setPosition(CCPoint(134.0f,105.0f));
		pButton->setAdjustBackgroundImage(false);
		//pButton->setZoomOnTouchDown(false);
		pButton->setTag(n);
		if (tableSprite.m_pTableP)
		{
			pButton->setZOrder(tableSprite.m_pTableP->getZOrder()+4);
		}

		tableSprite.m_pTableBK->addChild(pButton);
		seat.m_pSeat = pButton;

		//更新名称
		CCLabelTTF* pUserName = NULL; 

		if (m_pResManager->GenerateNodeByCfgID(eSpriteType_Cfg, Star97_Font_Room_Sit_Name, pUserName))
		{

		}

		if (pUserName && tableSprite.m_pTableBK)
		{
			szBKSize = tableSprite.m_pTableBK->getContentSize();
			pUserName->setString("");
			pUserName->setPosition(ccp(szBKSize.width*0.5,0));
			pUserName->setHorizontalAlignment(kCCTextAlignmentCenter);
			pUserName->setVerticalAlignment(kCCVerticalTextAlignmentCenter);
			tableSprite.m_pTableBK->addChild(pUserName);
			seat.m_pNameLabel = pUserName;
		}

		tableSprite.m_vSeatSprites.push_back(seat);
	}

	return tableSprite;
}