为啥我的上下左右行,page up 和down 没反应
require "app.Common"
local Fence = require "app.Fence"
require "app.CollideManager"
local Block = require "app.Block"
local EditorScene = class("EditorScene",function ()
return display.newScene("EditorScene")
end)
function EditorScene:onEnter()
self.fence = Fence.new(cBound,self)
self.curX = 0
self.curY = 0
self.curIndex = 0
self:SwitchCursor(1)
self:ProcessInput()
end
local cMaxBlock = 3
function EditorScene:SwitchCursor( delta )
if self.cur == nil then
self.cur = Block.new(self)
end
local newIndex = self.curIndex + delta
newIndex = math.max(newIndex,1)
newIndex = math.min(newIndex,cMaxBlock)
self.curIndex = newIndex
self.cur:Set(newIndex)
self.cur:SetPos(self.curX,self.curY)
end
function EditorScene:MoveCursor( deltaX,deltaY )
self.cur:SetPos(self.curX+deltaX,self.curY+deltaY)
self.curX = self.cur.x
self.curY = self.cur.y
end
function EditorScene:ProcessInput( )
local function keyboardPressed(keyCode,event )
--up
if keyCode == 28 then
self:MoveCursor(0,1)
--down
elseif keyCode == 29 then
self:MoveCursor(0,-1)
--left
elseif keyCode == 26 then
self:MoveCursor(-1,0)
--right
elseif keyCode == 27 then
self:MoveCursor(1,0)
--page up
elseif keyCode == 38 then
self:SwitchCursor(-1)
--page down
elseif keyCode == 44 then
self:SwitchCursor(1)
end
end
local listener = cc.EventListenerKeyboard:create()
listener:registerScriptHandler(keyboardPressed,cc.Handler.EVENT_KEYBOARD_PRESSED)
local eventDispatcher = self:getEventDispatcher()
eventDispatcher:addEventListenerWithSceneGraphPriority(listener,self)
end
return EditorScene