@H_404_1@最近在使用scheduler时发现如下问题
@H_404_1@
local scheduler = require(cc.PACKAGE_NAME .. ".scheduler") function MainScene:ctor() self.player_:pos(self.player_:getContentSize().width / 2,display.height / 2) scheduler.scheduleGlobal(self.addMonster,1) end function MainScene:addMonster() local monster = display.newSprite("monster.png"):addTo(self) end
报错:
@H_404_1@
stack traceback: [string "framework/shortcodes.lua"]:62: in function 'addTo' [string "/Users/tokou/Documents/work_cocos/firstapp/src/app/scenes/MainScene.lua"]:30: in function <[string "/Users/tokou/Documents/work_cocos/firstapp/src/app/scenes/MainScene.lua"]:28> cocos2d: ----------------------------------------
解决方法
@H_404_1@
@H_404_1@
local scheduler = require(cc.PACKAGE_NAME .. ".scheduler") function MainScene:ctor() self.player_:pos(self.player_:getContentSize().width / 2,display.height / 2) scheduler.scheduleGlobal(function() self:addMonster() end,1) end function MainScene:addMonster() local monster = display.newSprite("monster.png"):addTo(self) end原文链接:https://www.f2er.com/cocos2dx/346657.html