cocos2dx是怎么了

最近用cocos2dx 3.5仿着开发一款类似竖屏小游戏,发现如果一个精灵(图片大小42*125px)从上往下 匀速下降(测试时每次下降5px左右)的时候,竟然会有顿的感觉,不管是安卓手机或PC上都会,帧率在57-60之间波动,苹果手机上会好很多,本来以为我代码逻辑有问题,后来尝试只是加载一张图片而已,精灵下降时也会有卡顿的感觉,然后就这么个简单的处理都有问题吗?那如何开发精灵会快速跑动的游戏呢? 后面尝试cocos2dx 2.2.6版的, 在安卓手机上也是会卡顿测试手机有 魅族MX3 三星I9268 联想A808T ,但是PC上基本是不卡顿。
下面贴出主要代码,基本只是简单改下hellocpp 而已。

#include “HelloWorldScene.h”
#include “AppMacros.h”
USING_NS_CC;

CCScene* HelloWorld::scene()
{
// ‘scene’ is an autorelease object
CCScene *scene = CCScene::create();

// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create();


// add layer as a child to scene
scene->addChild(layer);


// return the scene
return scene;

}

// on “init” you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}

CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

wall = CCSprite::create(“btn-about-normal-vertical.png”);
wall->setAnchorPoint(ccp(0.0, 0.0));

wall->setPositionX(visibleSize.width / 2 - wall->getContentSize().width / 2);
wall->setPositionY(0);

this->addChild(wall);
this->scheduleUpdate();

return true;

}

void HelloWorld::update(float delta)
{
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
wall->setPositionY(wall->getPositionY() - 5);
if (wall->getPositionY() < -visibleSize.height)
{
wall->setPositionY(visibleSize.height);
}
}
void HelloWorld::menuCloseCallback(CCObject* pSender)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
CCMessageBox(“You pressed the close button. Windows Store Apps do not implement a close button.”,“Alert”);
#else
CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
#endif
}

1.换moveto试试
2.修改每帧移动的像素距离大小试试

有试过了, moveto moveby ,还有新增定时器的方式,结果都是一样

你试试测试例看看,我测试例没看出什么问题。

没问题。你的机子是不是配置比较低?

还是时器的方式吧,值设置大点!

cocos2dx中,无论是定时器schedule还是moveBy等都是帧回调,都会受帧率的影响有卡顿现象

如果在安卓手机上运行可以用闹钟机制来做这个定时回调,会平稳很多;还有就是cocos中另起一线程,但好像cocos是线程不安全的,我没试过

请不要无视update中那个dt参数,你现在的情况是每一帧都移动相同的距离,这样帧率只要稍微变动就会有卡顿

那有什么方法可以解决这个问题吗?

timer间隔改成0.02这种看看会不会好点