Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Moving object — Gideros Forum

Moving object

a00zaa00za Member
edited March 2013 in General questions
hello i am sorry that i always ask silly questions.
I have an object that i can move it using a function but when i added the function that make the object move circularly i could not move and drag it .
here is the code for the drag function and the circular movment:
-------------
self.safron=Bitmap.new(Texture.new("pics/coffee/safron.png"))
self.safron:setAnchorPoint(0.5,0.5)
rotationRadius = 520 --radius to rotate around
radius = rotationRadius - self.safron:getWidth() / 2 --radius = rotation radius minus bitmap radius
speed = 30 / rotationRadius --speed relative to the rotation radius
angle = 0 --initial angle
posX = (1480) + radius --x position
posY = (500) --y position
self.safron:setPosition(posX, posY)
self:addChild(self.safron)
----------
self:addEventListener(Event.ENTER_FRAME, self.circular,self)
self.safron:addEventListener(Event.MOUSE_DOWN, self.DragonMouseDownSa, self)
self.safron:addEventListener(Event.MOUSE_MOVE, self.DragonMouseMoveSa, self)
self.safron:addEventListener(Event.MOUSE_UP, self.DragonMouseUpSa, self)
------------
function coffee_p4:circular()
angle = angle + speed
posX = (1480)+ radius * math.cos(angle)
posY = (500)+ radius * -math.sin(angle)
self.safron:setPosition(posX, posY)
end
-----------
function coffee_p4:DragonMouseDownSa(event)
if self.safron:hitTestPoint(event.x, event.y) then
self.safron.isFocus = true -- mark to chk whether it is selected or not
self.safron.x0 = event.x--store initial position of touch
self.safron.y0 = event.y
event:stopPropagation() --stop all the touch events or mouse event
end
end

function coffee_p4:DragonMouseMoveSa(event)
if self.safron.isFocus then
local dx = event.x - self.safron.x0--get the diff of initial pos and current touch pos
local dy = event.y - self.safron.y0
self.safron:setX(self.safron:getX() + dx) -- add this diff to img's x and y pos
self.safron:setY(self.safron:getY() + dy)
self.safron.x0 = event.x -- change the initial pos with new one
self.safron.y0 = event.y
event:stopPropagation()
end
end

function coffee_p4:DragonMouseUpSa(event)
if self.safron.isFocus then
self.safron.isFocus = false --unmark
event:stopPropagation()
else
self.safron.isFocus = false --unmark
event:stopPropagation()
end
end
end

Comments

  • ar2rsawseenar2rsawseen Maintainer
    edited March 2013 Accepted Answer
    if you mean to stop it from circulating while dragging than try to modifying your circle function as this:
    function coffee_p4:circular()
        if not self.safron.isFocus then
            angle = angle + speed
            posX = (1480)+ radius * math.cos(angle)
            posY = (500)+ radius * -math.sin(angle)
            self.safron:setPosition(posX, posY)
        end
    end

    Likes: a00za

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.