zoukankan      html  css  js  c++  java
  • quick-cocos2d-x3.2 scheduler使用注意事项

    近期在使用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


  • 相关阅读:
    Qt 配置fakevim
    CentOS安装Ruby组件
    Linux shell 操作 postgresql,并设置crontab任务
    修改win7锁定界面背景
    Ubuntu安装Redis
    Java 向SQL Server插入文件数据
    用VMware vSphere Client客户端登陆vsphere5提示错误
    DD应用实例
    shell初学
    deepin2014.1快捷键
  • 原文地址:https://www.cnblogs.com/yutingliuyl/p/6767311.html
Copyright © 2011-2022 走看看