您好,我正在开发一款游戏,其中对象必须在屏幕上随机移动。我正在使用 cocos2dx 框架。我的代码是
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
int minY = HelloWorld::bird->getContentSize().height/2;
int maxY = winSize.height - HelloWorld::bird->getContentSize().height/2;
int minX = HelloWorld::bird->getContentSize().width/2;
int maxX = winSize.width - HelloWorld::bird->getContentSize().width/2;
int range = maxX - minX;
int actualY = (rand() % range) + minY;
int actualX = (rand() % range) + minX;
//HelloWorld::bird->setPosition(ccp(actualX, actualY));
CCActionInterval* actionTo = CCMoveTo::actionWithDuration(3, ccp(actualX,actualY));
HelloWorld::runAction(actionTo);
它正在工作但只产生正数。所以精灵要离开屏幕了。我搜索了教程,但没有得到。