It looks like you're new here. If you want to get involved, click one of these buttons!
stack = Core.class(Sprite) function stack:init(_elementsSize, _cubeSize, _positionX, _positionY) elementsSize = _elementsSize cubeSize = _cubeSize positionX = _positionX positionY = application:getContentHeight() - _positionY self.element = {} index = 1 end function stack:addSprite(sprite) if index <= elementsSize then self.element[index] = sprite if index >= 2 then self.element[index - 1]:removeEventListener(Event.MOUSE_DOWN, self.onMouseDown, self.element[index - 1]) self.element[index - 1]:removeEventListener(Event.MOUSE_MOVE, self.onMouseMove, self.element[index - 1]) self.element[index - 1]:removeEventListener(Event.MOUSE_UP, self.onMouseUp, self.element[index - 1]) end self.element[index]:addEventListener(Event.MOUSE_DOWN, self.onMouseDown, self.element[index]) self.element[index]:addEventListener(Event.MOUSE_MOVE, self.onMouseMove, self.element[index]) self.element[index]:addEventListener(Event.MOUSE_UP, self.onMouseUp, self.element[index]) self.element[index]:setPosition(positionX, positionY - index * 55) self:addChild(self.element[index]) index = index + 1 end end function stack:removeSprite() self: removeChild(self.element[index]) index = index - 1 self.element[index]:addEventListener(Event.MOUSE_DOWN, self.onMouseDown, self.element[index]) self.element[index]:addEventListener(Event.MOUSE_MOVE, self.onMouseMove, self.element[index]) self.element[index]:addEventListener(Event.MOUSE_UP, self.onMouseUp, self.element[index]) end function stack:onMouseDown(event) if self:hitTestPoint(event.x, event.y) then self.isFocus = true self.x0 = event.x self.y0 = event.y event:stopPropagation() end end function stack:onMouseMove(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 function stack:onMouseUp(event) if self.isFocus then if (event.x > 150) or (event.x < 100) then print("yes") self:removeSprite() end self.isFocus = false event:stopPropagation() end end |
Comments
self.elements would onyl be reachable if you added mouse events like this: