It looks like you're new here. If you want to get involved, click one of these buttons!
local function onMouseDown(self, event) if self:hitTestPoint(event.x, event.y) then self.isFocus = true self.x0 = event.x self.y0 = event.y event:stopPropagation() end end local function onMouseMove(self, event) if self.isFocus then self:setColorTransform(1,0.7,0.2,1) local dx = event.x - self.x0 local dy = event.y - self.y0 self:setX(self:getX() + dx) self:setY(self:getY() + dy) self.x0 = event.x self.y0 = event.y event:stopPropagation() end end local function onMouseUp(self, event) if self.isFocus then self.isFocus = false event:stopPropagation() end --this is my problem if event.x>80 and event.x <120 then self:setX(80) end end local n = 5 local lett = {} for i=1,n do lett[i] = Shape.new() lett[i]:setFillStyle(Shape.SOLID,0x566765,0.5) lett[i]:setLineStyle(1, 0x0066FF, 2) lett[i]:beginPath() lett[i]:moveTo(0, 0) lett[i]:lineTo(0, 50) lett[i]:lineTo(50, 50) lett[i]:lineTo(50, 0) lett[i]:lineTo(0, 0) lett[i]:endPath() lett[i].isFocus = false stage:addChild(lett[i]) lett[i]:setPosition(i*60-40,26) lett[i]:addEventListener(Event.MOUSE_DOWN, onMouseDown, lett[i]) lett[i]:addEventListener(Event.MOUSE_MOVE, onMouseMove, lett[i]) lett[i]:addEventListener(Event.MOUSE_UP, onMouseUp, lett[i]) end |
Comments
if event.x>80 and event.x <120 then self:setX(80) end
before
event:stopPropagation()<pre escaped='true' lang="lua">
local function onMouseDown(self, event)
if self:hitTestPoint(event.x, event.y) then
self.isFocus = true
self.x0 = event.x
self.y0 = event.y
event:stopPropagation()
end
end
local function onMouseMove(self, event)
if self.isFocus then
self:setColorTransform(1,0.7,0.2,1)
local dx = event.x - self.x0
local dy = event.y - self.y0
self:setX(self:getX() + dx)
self:setY(self:getY() + dy)
self.x0 = event.x
self.y0 = event.y
event:stopPropagation()
end
end
local function onMouseUp(self, event)
if self.isFocus then
self.isFocus = false
--this is my problem
print(event.x)
if event.x>80 and event.x <120 then self:setX(80) end
event:stopPropagation()
end
end
local n = 5
local lett = {}
for i=1,n do
lett[i] = Shape.new()
lett[i]:setFillStyle(Shape.SOLID,0x566765,0.5)
lett[i]:setLineStyle(1, 0x0066FF, 2)
lett[i]:beginPath()
lett[i]:moveTo(0, 0)
lett[i]:lineTo(0, 50)
lett[i]:lineTo(50, 50)
lett[i]:lineTo(50, 0)
lett[i]:lineTo(0, 0)
lett[i]:endPath()
lett[i].isFocus = false
stage:addChild(lett[i])
lett[i]:setPosition(i*60-40,26)
lett[i]:addEventListener(Event.MOUSE_DOWN, onMouseDown, lett[i])
lett[i]:addEventListener(Event.MOUSE_MOVE, onMouseMove, lett[i])
lett[i]:addEventListener(Event.MOUSE_UP, onMouseUp, lett[i])
end
@vitalitymobile - thanks for your suggestion.solved