码迷,mamicode.com
首页 > 其他好文 > 详细

quick-cocos2d-x3.2 scheduler使用注意事项

时间:2014-10-26 18:26:54      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:quick-cocos2d-x3.2   scheduler   self   scheduleglobal   每秒调用   

最近在使用scheduler时发现如下问题

调用:

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

报错:

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: ----------------------------------------

解决方法


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


quick-cocos2d-x3.2 scheduler使用注意事项

标签:quick-cocos2d-x3.2   scheduler   self   scheduleglobal   每秒调用   

原文地址:http://blog.csdn.net/qqmcy/article/details/40478451

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!