Android : this->getContentSize().width give me zero response but layer is equal to device width and height

on Tuesday, September 30, 2014


one more problem facing that getContentSize() return zero width and height.


i have created circle using Drawnode and than get its content size but return zero.


My working code is


where rad=100;



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));

CCSprite *spr = CCSprite::create(image);
spr->setPosition(ccp(drawnode->getContentSize().width/2,0));
drawnode->addChild(spr);
CCLog("Draw node width : %f",this->getContentSize().width);
float p = (100/spr->getContentSize().width)+0.5;
spr->setAnchorPoint(ccp(0,p));
auto rotate = RotateBy::create(3,360);
spr->runAction(CCRepeatForever::create(rotate));

this->addChild(drawnode);


please give me solution for better work.


Thanks in advance Rishabh Shah


0 comments:

Post a Comment