axmol/samples/Cpp/TestCpp/Classes/BugsTest/Bug-458/QuestionContainerSprite.cpp

87 lines
3.1 KiB
C++
Raw Normal View History

2011-07-08 11:22:35 +08:00
#include "QuestionContainerSprite.h"
#define kLabelTag
USING_NS_CC;
2011-07-08 11:22:35 +08:00
bool QuestionContainerSprite::init()
{
if (Sprite::init())
2011-07-08 11:22:35 +08:00
{
//Add label
auto label = LabelTTF::create("Answer 1", "Arial", 12);
2011-07-08 11:22:35 +08:00
label->setTag(100);
//Add the background
auto size = Director::getInstance()->getWinSize();
auto corner = Sprite::create("Images/bugs/corner.png");
2011-07-08 11:22:35 +08:00
int width = size.width * 0.9f - (corner->getContentSize().width * 2);
int height = size.height * 0.15f - (corner->getContentSize().height * 2);
auto layer = LayerColor::create(Color4B(255, 255, 255, 255 * .75), width, height);
2013-07-12 14:11:55 +08:00
layer->setPosition(Point(-width / 2, -height / 2));
2011-07-08 11:22:35 +08:00
//First button is blue,
//Second is red
//Used for testing - change later
static int a = 0;
if (a == 0)
label->setColor(Color3B::BLUE);
2011-07-08 11:22:35 +08:00
else
{
log("Color changed");
label->setColor(Color3B::RED);
2011-07-08 11:22:35 +08:00
}
a++;
addChild(layer);
2013-07-12 14:11:55 +08:00
corner->setPosition(Point(-(width / 2 + corner->getContentSize().width / 2), -(height / 2 + corner->getContentSize().height / 2)));
2011-07-08 11:22:35 +08:00
addChild(corner);
auto corner2 = Sprite::create("Images/bugs/corner.png");
2013-07-12 14:11:55 +08:00
corner2->setPosition(Point(-corner->getPosition().x, corner->getPosition().y));
corner2->setFlippedX(true);
2011-07-08 11:22:35 +08:00
addChild(corner2);
auto corner3 = Sprite::create("Images/bugs/corner.png");
2013-07-12 14:11:55 +08:00
corner3->setPosition(Point(corner->getPosition().x, -corner->getPosition().y));
corner3->setFlippedY(true);
2011-07-08 11:22:35 +08:00
addChild(corner3);
auto corner4 = Sprite::create("Images/bugs/corner.png");
2013-07-12 14:11:55 +08:00
corner4->setPosition(Point(corner2->getPosition().x, -corner2->getPosition().y));
corner4->setFlippedX(true);
corner4->setFlippedY(true);
2011-07-08 11:22:35 +08:00
addChild(corner4);
auto edge = Sprite::create("Images/bugs/edge.png");
2011-07-08 11:22:35 +08:00
edge->setScaleX(width);
2013-07-12 14:11:55 +08:00
edge->setPosition(Point(corner->getPosition().x + (corner->getContentSize().width / 2) + (width / 2), corner->getPosition().y));
2011-07-08 11:22:35 +08:00
addChild(edge);
auto edge2 = Sprite::create("Images/bugs/edge.png");
2011-07-08 11:22:35 +08:00
edge2->setScaleX(width);
2013-07-12 14:11:55 +08:00
edge2->setPosition(Point(corner->getPosition().x + (corner->getContentSize().width / 2) + (width / 2), -corner->getPosition().y));
edge2->setFlippedY(true);
2011-07-08 11:22:35 +08:00
addChild(edge2);
auto edge3 = Sprite::create("Images/bugs/edge.png");
2011-07-08 11:22:35 +08:00
edge3->setRotation(90);
edge3->setScaleX(height);
2013-07-12 14:11:55 +08:00
edge3->setPosition(Point(corner->getPosition().x, corner->getPosition().y + (corner->getContentSize().height / 2) + (height / 2)));
2011-07-08 11:22:35 +08:00
addChild(edge3);
auto edge4 = Sprite::create("Images/bugs/edge.png");
2011-07-08 11:22:35 +08:00
edge4->setRotation(270);
edge4->setScaleX(height);
2013-07-12 14:11:55 +08:00
edge4->setPosition(Point(-corner->getPosition().x, corner->getPosition().y + (corner->getContentSize().height / 2) + (height / 2)));
2011-07-08 11:22:35 +08:00
addChild(edge4);
addChild(label);
return true;
}
return false;
}