Skip to content

Instantly share code, notes, and snippets.

@yihuang
Created October 17, 2012 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yihuang/3904880 to your computer and use it in GitHub Desktop.
Save yihuang/3904880 to your computer and use it in GitHub Desktop.
cocos2d-x-bug.lua
function some_expensive_function()
local tbl = {}
for i=1,100 do
table.insert(tbl, i)
end
local a = {}
for i=1,100 do
for idx,f in ipairs(tbl) do
a[i] = idx / (1/24)
end
end
return a
end
function create_node()
local n = CCSprite:create('assets/somesprite.png')
local n1 = CCNode:create()
local n2 = CCNode:create()
local n3 = CCNode:create()
n1:addChild(n)
n2:addChild(n1)
n3:addChild(n2)
return n3
end
function dumpNode(n, label, indent)
indent = indent or ''
print(string.format('%s%s', indent, tostring(n)))
local c = n:getChildren()
if c and c:count()>0 then
for i=0,c:count()-1 do
dumpNode(c:objectAtIndex(i), label, indent..' ')
end
end
end
local director = CCDirector:sharedDirector()
local scene = CCScene:create()
local size = director:getWinSize()
local layer = CCLayer:create()
local sharedScheduler = director:getScheduler()
function simple_mc(layer)
local node = create_node()
node:setPosition(size.width/2, size.height/2)
local elapsed = 0
function tick(time)
dumpNode(node)
some_expensive_function()
elapsed = elapsed + time
local layerNode = node:getChildren():objectAtIndex(0)
local elem = layerNode:getChildren():objectAtIndex(0)
elem:setRotation(elapsed*100)
end
sharedScheduler:scheduleScriptFunc(tick, 0, false)
layer:addChild(node)
end
simple_mc(layer)
scene:addChild(layer)
CCDirector:sharedDirector():runWithScene(scene)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment