为什么说我的addEventWithSceneGraphPriority是空值

来源:4-5 蛇骑士!控制蛇身二

慕丝8128172

2016-05-13 20:09

MainScene.lua

local Snake = require"app.Snake"



local MainScene = class("MainScene", function()

return display.newScene("MainScene")

end)


local cMovespeed = 0.3



function MainScene:onEnter()

self.snake = Snake.new(self)

self:processInput()

local tick = function()

self.snake:Update()

end

cc.Director:getInstance():getScheduler():scheduleScriptFunc(tick,cMovespeed,false)


end


local function vector2Dir(x,y)


if math.abs(x) > math.abs(y) then

if x<0 then

return "left"

else

return "right"

end

else

if Y < 0 then

return "up"

else

return "down"

end

end

end

function MainScene:processInput()

local function onTouchBegan(touch, event)

local location = touch:getLocation()

local visibleSize = cc.Director:getInstance():getVisibleSize()

local origin = cc.Director:getInstance():getVisibleOrigin()

local finaX = location.x - (origin.x + visibleSize.width/2)

local finaY = location.y - (origin.y + visibleSize.height/2)

local dir = vector2Dir(finaX,finaY)

self.snake:SetDir(dir)

end

local listener = cc.EventListenerTouchOneByOne:create()

listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN)

local eventDispatcher = self:getEventDispatcher()

eventDispatcher:addEventWithSceneGraphPriority(listener,self)


end


function MainScene:onExit()

end



return MainScene


写回答 关注

1回答

  • 还好了
    2016-08-18 09:22:12
    已采纳

    是addEventListenerWithSceneGraphPriority

    慕丝8128...

    非常感谢!

    2016-10-18 14:12:12

    共 1 条回复 >

Cocos2d-x游戏开发之贪吃蛇(上)

贪吃蛇都玩过~有没有想过自己实现呢,一起学习来吧

32439 学习 · 122 问题

查看课程

相似问题