标签:
bool HelloWorld::init()
{
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
_direction.set(random(-1.0f,1.0f),random(-1.0f,1.0f));
_direction.normalize();
auto dot=DrawNode::create();
dot->drawDot(Vec2(0,0),10,Color4F(1.0,1.0,1.0,1.0));
addChild(dot);
dot->setPosition(visibleSize/2);
schedule([dot,this,visibleSize](float f){
auto p=dot->getPosition();
if (p.x<0||p.x>visibleSize.width) {
_direction.x*=-1;
}else if (p.y<0||p.y>visibleSize.height){
_direction.y*=-1;
}
dot->setPosition(p+_direction*10);
},"Test");
return true;
}
标签:
原文地址:http://www.cnblogs.com/daochong/p/5225990.html