setContentSize不工作setContentSize不cocos2dx3.0工作
我在cocos2dx新的,我想從另一個類添加圖層到我的主SplashScreen類,但setContentSize使用設備的寬度和高度。
我想設置圖層大小以及我的精靈大小。
看到我的代碼
Gadget.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);
}
我必須使用Gadget.coo類在Splashscreen.cpp
#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;
}
當我使用「這 - > setContentSize(CCSizeZero );」代碼但沒有改變視圖。 它從位置-100生成全屏圖層,-100
請給我一些解決方案,爲什麼setContentSize不起作用。
在先進的感謝 RISHABH沙阿
請給我解決,爲什麼setContentSize沒有設置層的寬度和高度。 – 2014-09-30 09:52:46