setContentSize在cocos2dx3.0中不起作用
setContentSize is not working in cocos2dx3.0
setContentSize不工作
我是cocos2dx的新手,我想把另一个类的层添加到我的主Splashscreen类中,但setContentSize使用设备宽度和高度。
我想设置图层大小和我的精灵大小。
查看我的代码
小工具.cpp
#include "Gadget.h"
#include "math.h"
int nCount = 100;
static CCPoint Circle [100]; // vertex array
Gadget* Gadget::create(int type)
{
Gadget *pRet = new Gadget();
if (pRet && pRet->init(type))
{
pRet->autorelease();
return pRet;
}
else
{
delete pRet;
pRet = NULL;
return NULL;
}
}
bool Gadget::init(int type)
{
if(!LayerColor::init())
{
return false;
}
this->setContentSize(CCSize::ZERO);
this->initWithColor(Color4B(255,255,255,255));
CCLog("Before Calling");
addGadget(type);
return true;
}
Gadget::Gadget() {
// TODO Auto-generated constructor stub
}
Gadget::~Gadget() {
// TODO Auto-generated destructor stub
}
void Gadget::addGadget(int type)
{
const char* image = "gadget_2.png";
if(type==2)
{
image = "gadget_1.png";
}
//this->initWithFile(image);
CCLog("After Calling");
CCSprite *spr = CCSprite::create(image);
setGadgetPos(this->getContentSize().width/2,0.0);
this->drawCircle(100,100,100);
}
void Gadget::setGadgetPos(float x, float y)
{
// this->ignoreAnchorPointForPosition(true);
this->setPosition(x,y);
}
void Gadget::gadgetAnimStart(int type)
{
if(type==1)
{
this->setAnchorPoint(ccp(0,3));
auto rotate = RotateBy::create(3,360);
this->runAction(CCRepeatForever::create(rotate));
}
}
void Gadget::gadgetAnimStop()
{
this->stopAllActions();
}
void Gadget::drawCircle(float X, float Y,float rad)
{
DrawNode *drawnode = DrawNode::create();
for ( int i = 0 ; i <100; i ++)
{
float rads = i * M_1_PI; // radians
Circle [i] .x = rad * cosf (rads); //vertex x
Circle [i] .y = rad * sinf (rads); //vertex y
}
drawnode->setPosition(Director::sharedDirector()->getVisibleSize().width/2,Director::sharedDirector()->getVisibleSize().height/2);
drawnode->drawPolygon(Circle,100,Color4F(0,0,0,0),1,Color4F(1,122,153,1));
this->addChild(drawnode);
}
我必须在Splashscreen.cpp 上使用Gadget.co类
#include "Splashscreen.h"
#include "HelloWorldScene.h"
#include "CCHelper.h"
#include "Gadget.h"
#include "UserDefaultStorage.h"
#include "VisibleRect.h"
#include "math.h"
#include "Sound.h"
#include "Text_En.h"
USING_NS_CC;
Scene* Splashscreen::createScene()
{
Scene *s = Scene::create();
LayerColor *lc = Splashscreen::create();
s->addChild(lc);
return s;
}
Splashscreen::Splashscreen() {
// TODO Auto-generated constructor stub
}
Splashscreen::~Splashscreen() {
// TODO Auto-generated destructor stub
}
bool Splashscreen::init()
{
if(!LayerColor::create())
{
return false;
}
this->initWithColor(ccc4(0,0,0,255));
this->setContentSize(CCSizeZero);
Gadget *g = Gadget::create(GREEN_GADGET);
g->setPosition(ccp(-100,-100));
this->addChild(g);
return true;
}
当我使用"this->setContentSize(CCSizeZero);"代码但视图中没有更改时。它从位置-100,-100 生成全屏层
请给我一些解决方案,为什么setContentSize不起作用。
提前感谢Rishabh Shah
初始化后,setContentSize
将设置大小,但不会进行任何可见的更改,在初始化时提供宽度和高度会更好。
类似:
this->initWithColor(ccc4(0,0,0,255), width, height);
if(!LayerColor::create())
{
return false;
}
应该是
if(!LayerColor::init())
{
return false;
}
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 为什么二进制搜索在我的测试中不起作用
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 带有指定长度字符* 参数的 std::regex_search 在 VS2017 中不起作用?
- Bjarne Stroustrup Book - std_lib_facilities.h - 不起作用(未知类型名称)
- 为什么简单的算术减法在"if"条件下不起作用?
- 为什么Stroustup书中的has_f不起作用
- 你能检查一下为什么在这个代码中从链接列表中删除项目不起作用吗
- 嵌套While循环不起作用(C++问题)
- C++Matching Brackets 2解决方案不起作用
- 为什么这段代码不起作用,我该如何解决?
- setContentSize在cocos2dx3.0中不起作用