我有一个角色对象,我可以用这段代码顺利拖动它,但是当我释放它时它并没有消除对它的关注。我怎样才能解决这个问题?
W=display.contentWidth
H=display.contentHeight
local character = display.newImage("moni.png")
character.x=W/2; character.y=H-50
character.type="character"
local function move(self, event)
if event.phase=="began" then
--set focus on the moved object, so it won't interfere with other objects
display.getCurrentStage():setFocus(self,event.id)
self.isFocus=true
--record first position of the object
self.x0=self.x; self.y0=self.y
elseif event.phase=="moved" then
self.y=self.y0; --we force the object not to change its first y location
self.x=self.x0+(event.x-event.xStart)
elseif event.phase=="canceled" or event.phase=="end" then
display.getCurrentStage():setFocus(self, nil)
self.isFocus=false
end
return true
end
character.touch=move
character:addEventListener("touch", character)