Skip to content

Instantly share code, notes, and snippets.

@syuhari
Created April 20, 2013 08:17
Show Gist options
  • Save syuhari/5425221 to your computer and use it in GitHub Desktop.
Save syuhari/5425221 to your computer and use it in GitHub Desktop.
CCScale9Sprite sample
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCRect spriteRect = CCRectMake(0, 0, 70, 70);
CCRect capInsents = CCRectMake(6, 6, 58, 58);
CCScale9Sprite* backgroundSprite = CCScale9Sprite::create("9x9.png", spriteRect, capInsents);
CCLabelTTF* label = CCLabelTTF::create("ボタン1", "Arial", 30);
CCControlButton* button = CCControlButton::create(label, backgroundSprite);
button->setPreferredSize(CCSizeMake(200, 60));
button->setPosition(ccp(50+button->getContentSize().width/2, size.height/2+button->getContentSize().height));
this->addChild(button);
button->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::menuCloseCallback), CCControlEventTouchUpInside);
CCScale9Sprite* backgroundSprite2 = CCScale9Sprite::create("9x9.png", spriteRect, capInsents);
CCLabelTTF* label2 = CCLabelTTF::create("ボタン2", "Arial", 30);
CCControlButton* button2 = CCControlButton::create(label2, backgroundSprite2);
button2->setPreferredSize(CCSizeMake(150, 100));
button2->setPosition(ccp(50+button2->getContentSize().width/2, size.height/2-button2->getContentSize().height/2));
this->addChild(button2);
CCScale9Sprite* backgroundSprite3 = CCScale9Sprite::create("9x9.png", spriteRect, capInsents);
CCLabelTTF* label3 = CCLabelTTF::create("ボタン3", "Arial", 30);
CCControlButton* button3 = CCControlButton::create(label3, backgroundSprite3);
button3->setPreferredSize(CCSizeMake(150, 150));
button3->setPosition(ccp(size.width/2+button3->getContentSize().width, button->getPositionY()-button2->getContentSize().height/2));
this->addChild(button3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment