为什么在帧率低的情况下,帧事件会提早回调的?

都导成csb了,和flash应该没多大关系吧。

http://www.cocoachina.com/bbs/read.php?tid-280861.html 是不是因为这个

那个bug是cocos2d-x3.4beta0才有的吧,我用的是cocos2dx-3.3final的。

不是的,3.3也有,反正我3.3的时候也有

但是60帧下是没有问题,这个bug只是低帧率下。

跳帧了,时间是一致的就没问题;帧率60时的22帧和帧率20时的10帧(应该是7-9帧左右)的时间是一致的

cocos理论上不是不需要处理跳帧的这个问题的吗?为什么studio的动画要搞跳帧?

理论上?怎么说?

cocos引擎中,director的runloop,当前帧率超过你预设的就sleep一阵子,而帧率不足就只是一直run而已,逻辑还是会走完了,不需要处理掉帧的情况。
而在flash中,掉帧是要处理掉帧过程的逻辑的。

尝试用3.4beta0测试没出问题吗?

刚尝试用3.4beta0,然后也修复了你的那个cctimeline的bug,还是不行。我也用2.1的cocostudio重新导出过资源,那个问题还是存在。
end的帧事件回调的时候,我把frame的frameIndex输出来,确实是114,但是跟cocos引擎跑过的帧数对不上。
还是那个老问题,帧数低的时候,明明那个动画是22帧的,但只跑了10帧不到。
然后我看ccactiontime的源码,发现时间间隔是写死了1/60?

但我上次用3.3final的时候,在debug模式下,掉帧环境也出现了这个问题了。应该和我主动把帧率设成20帧没关系吧?

这个能解决吗?我怕以后掉帧的时候会出现问题.

可否提供你的代码我瞧瞧。
我有空的时候会测试下。

因为是公司内部代码,不能发出来,我写了一个demo让你测试下,好吗?
资源还是那只鲨鱼,flash转cocos的那个例子的。

帧事件:
我在鲨鱼的generalshark_left_foot部件(第一个)的68帧添加了一个start事件,151帧添加了一个end事件。

环境:
Cocos2dx-3.3final,CocoStudio2.05,CocosCodeIDE1.10

代码如下:

cc.FileUtils:getInstance():addSearchPath(“src”)
cc.FileUtils:getInstance():addSearchPath(“res”)

– CC_USE_DEPRECATED_API = true
require “cocos.init”

– cclog
local cclog = function(…)
print(string.format(…))
end

– for CCLuaEngine traceback
function G__TRACKBACK(msg)
cclog("----------------------------------------")
cclog(“LUA ERROR: " … tostring(msg) … “\n”)
cclog(debug.traceback())
cclog(”----------------------------------------")
return msg
end

local function main()
collectgarbage(“collect”)
– avoid memory leak
collectgarbage(“setpause”, 100)
collectgarbage(“setstepmul”, 5000)

-- initialize director
local director = cc.Director:getInstance()

--turn on display FPS
director:setDisplayStats(true)

--set FPS. the default value is 1.0/60 if you don't call this
director:setAnimationInterval(1.0 / 60)

cc.Director:getInstance():getOpenGLView():setDesignResolutionSize(1280, 720, 1)

--create scene
local gameScene = cc.Scene:create();

if cc.Director:getInstance():getRunningScene() then
    cc.Director:getInstance():replaceScene(gameScene)
else
    cc.Director:getInstance():runWithScene(gameScene)
end

local i = 1;
cc.Director:getInstance():getScheduler():scheduleScriptFunc(function(dt)
    i = i + 1;
end,0,false);

local node = cc.CSLoader:createNode("generalshark.csb");
local action = cc.CSLoader:createTimeline("generalshark.csb");
node:runAction(action);
gameScene:addChild(node);
node:setPosition(150,100);
action:setFrameEventCallFunc(function(frame)
    local index = frame:getFrameIndex();
    local event = frame:getEvent();
    print(string.format("frames:%i index:%i event:%s",i,index,event));
end);
action:gotoFrameAndPlay(68,151,false);

end

local status, msg = xpcall(main, G__TRACKBACK)
if not status then
error(msg)
end

输出:
frames:1 index:68 event:start
frames:208 index:151 event:end
因为这个资源是24fps的,所以它把83帧的动画拉到207帧,这是没问题的。
因为只有一只怪,在debug模式下也不能模拟掉帧的情况,所以我把帧率调成20帧。
director:setAnimationInterval(1.0 / 20)
输出:
frames:1 index:68 event:start
frames:69 index:151 event:end
问题就来了,cocos引擎只跑了68帧,end事件就回调出来了。

方便把那个鲨鱼的资源上传上来么?
我这儿没有flash没法转。

flash是这个:
http://www.cocoachina.com/bbs/read.php?tid-236927-keyword-flash.html
如果要csd的话,我今晚回家再上传吧。

嗯,好的!

昨天回去竟然忘了这件事了。

你所谓的跑了10帧就回调帧事件是什么意思?
是在引擎中mainLoop跑了10次还是动画走了10帧?

那个动画正常情况下,start与end事件回调间隔,引擎中mainLoop应该要跑207帧才对。
而在掉帧到20fps的时候,start与end事件回调间隔,引擎中mainLoop跑了才68帧。
在cocos中,cocostudio的动画不是按照引擎的mainLoop来跑的吗?