背景和头像缺失
This commit is contained in:
48
cocos2d/tests/cpp-tests/Classes/BugsTest/Bug-458/Bug-458.cpp
Normal file
48
cocos2d/tests/cpp-tests/Classes/BugsTest/Bug-458/Bug-458.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// Bug-458 test case by nedrafehi
|
||||
// http://code.google.com/p/cocos2d-iphone/issues/detail?id=458
|
||||
//
|
||||
|
||||
#include "Bug-458.h"
|
||||
#include "QuestionContainerSprite.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
bool Bug458Layer::init()
|
||||
{
|
||||
if(BugsTestBase::init())
|
||||
{
|
||||
// ask director the the window size
|
||||
auto size = Director::getInstance()->getWinSize();
|
||||
|
||||
auto question = new (std::nothrow) QuestionContainerSprite();
|
||||
auto question2 = new (std::nothrow) QuestionContainerSprite();
|
||||
question->init();
|
||||
question2->init();
|
||||
|
||||
// [question setContentSize:CGSizeMake(50,50)];
|
||||
// [question2 setContentSize:CGSizeMake(50,50)];
|
||||
|
||||
auto sprite = MenuItemSprite::create(question2, question, CC_CALLBACK_1(Bug458Layer::selectAnswer, this) );
|
||||
auto layer = LayerColor::create(Color4B(0,0,255,255), 100, 100);
|
||||
question->release();
|
||||
question2->release();
|
||||
|
||||
auto layer2 = LayerColor::create(Color4B(255,0,0,255), 100, 100);
|
||||
auto sprite2 = MenuItemSprite::create(layer, layer2, CC_CALLBACK_1(Bug458Layer::selectAnswer, this) );
|
||||
auto menu = Menu::create(sprite, sprite2, nullptr);
|
||||
menu->alignItemsVerticallyWithPadding(100);
|
||||
menu->setPosition(size.width / 2, size.height / 2);
|
||||
|
||||
// add the label as a child to this Layer
|
||||
addChild(menu);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Bug458Layer::selectAnswer(Ref* sender)
|
||||
{
|
||||
log("Selected");
|
||||
}
|
||||
15
cocos2d/tests/cpp-tests/Classes/BugsTest/Bug-458/Bug-458.h
Normal file
15
cocos2d/tests/cpp-tests/Classes/BugsTest/Bug-458/Bug-458.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef __BUG_458_H__
|
||||
#define __BUG_458_H__
|
||||
|
||||
#include "../BugsTest.h"
|
||||
|
||||
class Bug458Layer : public BugsTestBase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Bug458Layer);
|
||||
|
||||
virtual bool init() override;
|
||||
void selectAnswer(cocos2d::Ref* sender);
|
||||
};
|
||||
|
||||
#endif // __BUG_458_H__
|
||||
@@ -0,0 +1,86 @@
|
||||
#include "QuestionContainerSprite.h"
|
||||
|
||||
#define kLabelTag
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
bool QuestionContainerSprite::init()
|
||||
{
|
||||
if (Sprite::init())
|
||||
{
|
||||
//Add label
|
||||
auto label = Label::createWithTTF("Answer 1", "fonts/arial.ttf", 12);
|
||||
label->setTag(100);
|
||||
|
||||
//Add the background
|
||||
auto size = Director::getInstance()->getWinSize();
|
||||
auto corner = Sprite::create("Images/bugs/corner.png");
|
||||
|
||||
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);
|
||||
layer->setPosition(Vec2(-width / 2, -height / 2));
|
||||
|
||||
//First button is blue,
|
||||
//Second is red
|
||||
//Used for testing - change later
|
||||
static int a = 0;
|
||||
|
||||
if (a == 0)
|
||||
label->setColor(Color3B::BLUE);
|
||||
else
|
||||
{
|
||||
log("Color changed");
|
||||
label->setColor(Color3B::RED);
|
||||
}
|
||||
a++;
|
||||
addChild(layer);
|
||||
|
||||
corner->setPosition(Vec2(-(width / 2 + corner->getContentSize().width / 2), -(height / 2 + corner->getContentSize().height / 2)));
|
||||
addChild(corner);
|
||||
|
||||
auto corner2 = Sprite::create("Images/bugs/corner.png");
|
||||
corner2->setPosition(Vec2(-corner->getPosition().x, corner->getPosition().y));
|
||||
corner2->setFlippedX(true);
|
||||
addChild(corner2);
|
||||
|
||||
auto corner3 = Sprite::create("Images/bugs/corner.png");
|
||||
corner3->setPosition(Vec2(corner->getPosition().x, -corner->getPosition().y));
|
||||
corner3->setFlippedY(true);
|
||||
addChild(corner3);
|
||||
|
||||
auto corner4 = Sprite::create("Images/bugs/corner.png");
|
||||
corner4->setPosition(Vec2(corner2->getPosition().x, -corner2->getPosition().y));
|
||||
corner4->setFlippedX(true);
|
||||
corner4->setFlippedY(true);
|
||||
addChild(corner4);
|
||||
|
||||
auto edge = Sprite::create("Images/bugs/edge.png");
|
||||
edge->setScaleX(width);
|
||||
edge->setPosition(Vec2(corner->getPosition().x + (corner->getContentSize().width / 2) + (width / 2), corner->getPosition().y));
|
||||
addChild(edge);
|
||||
|
||||
auto edge2 = Sprite::create("Images/bugs/edge.png");
|
||||
edge2->setScaleX(width);
|
||||
edge2->setPosition(Vec2(corner->getPosition().x + (corner->getContentSize().width / 2) + (width / 2), -corner->getPosition().y));
|
||||
edge2->setFlippedY(true);
|
||||
addChild(edge2);
|
||||
|
||||
auto edge3 = Sprite::create("Images/bugs/edge.png");
|
||||
edge3->setRotation(90);
|
||||
edge3->setScaleX(height);
|
||||
edge3->setPosition(Vec2(corner->getPosition().x, corner->getPosition().y + (corner->getContentSize().height / 2) + (height / 2)));
|
||||
addChild(edge3);
|
||||
|
||||
auto edge4 = Sprite::create("Images/bugs/edge.png");
|
||||
edge4->setRotation(270);
|
||||
edge4->setScaleX(height);
|
||||
edge4->setPosition(Vec2(-corner->getPosition().x, corner->getPosition().y + (corner->getContentSize().height / 2) + (height / 2)));
|
||||
addChild(edge4);
|
||||
|
||||
addChild(label);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef __QUESTION_CONTAINER_SPRITE_H__
|
||||
#define __QUESTION_CONTAINER_SPRITE_H__
|
||||
|
||||
#include "cocos2d.h"
|
||||
|
||||
class QuestionContainerSprite : public cocos2d::Sprite
|
||||
{
|
||||
public:
|
||||
virtual bool init() override;
|
||||
};
|
||||
|
||||
#endif // __QUESTION_CONTAINER_SPRITE_H__
|
||||
Reference in New Issue
Block a user