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

前端之家收集整理的这篇文章主要介绍了quick-cocos2d-x3.2 scheduler使用注意事项前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

调用

  1. local scheduler = require(cc.PACKAGE_NAME .. ".scheduler")
  2.  
  3.  
  4. function MainScene:ctor()
  5. self.player_:pos(self.player_:getContentSize().width / 2,display.height / 2)
  6. scheduler.scheduleGlobal(self.addMonster,1)
  7. end
  8.  
  9. function MainScene:addMonster()
  10.  
  11. local monster = display.newSprite("monster.png"):addTo(self)
  12. end

报错:

  1. stack traceback:
  2. [string "framework/shortcodes.lua"]:62: in function 'addTo'
  3. [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>
  4. cocos2d: ----------------------------------------

解决方法


  1. local scheduler = require(cc.PACKAGE_NAME .. ".scheduler")
  2.  
  3.  
  4. function MainScene:ctor()
  5. self.player_:pos(self.player_:getContentSize().width / 2,display.height / 2)
  6. scheduler.scheduleGlobal(function()
  7. self:addMonster()
  8. end,1)
  9. end
  10.  
  11. function MainScene:addMonster()
  12.  
  13. local monster = display.newSprite("monster.png"):addTo(self)
  14. end

猜你在找的Cocos2d-x相关文章