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 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 end for i=1,5 do shape = Shape.new() shape:setLineStyle(3, 0x000000) shape:setFillStyle(Shape.SOLID, 0xff0000, 0.5) shape:beginPath() shape:moveTo(0, 0) shape:lineTo(100, 0) shape:lineTo(100, 50) shape:lineTo(0, 50) shape:closePath() shape:endPath() shape:setX(math.random(0, 320 - 100)) shape:setY(math.random(0, 480 - 50)) shape.isFocus = false stage:addChild(shape) shape:addEventListener(Event.MOUSE_DOWN, onMouseDown, shape) shape:addEventListener(Event.MOUSE_MOVE, onMouseMove, shape) shape:addEventListener(Event.MOUSE_UP, onMouseUp, shape) end |
Comments
For "i" variable, because shape is table, so you can assign i to shape, and get it later.
Likes: pie
Thank you so much, worked well in my own implementation! I have still to learn about variable names, what is what on either side of a . (dot) etc