Help with dragging

Hi, i used this code for dragging objects:

[lua]

– create object

local myObject = display.newRect( 0, 0, 100, 100 )

myObject:setFillColor( 255 )

– touch listener function

function myObject:touch( event )

if event.phase == “began” then

    

   self.markX = self.x – store x location of object

   self.markY = self.y – store y location of object

    

elseif event.phase == “moved” then

    

   local x = (event.x - event.xStart) + self.markX

   local y = (event.y - event.yStart) + self.markY

   self.x, self.y = x, y – move object based on calculations above

end

return true

end

– make ‘myObject’ listen for touch events

myObject:addEventListener( “touch”, myObject )

[/lua]

It’s work great but how change this code to allow players to move object just up?

Hi @wojtekswieton,

Changing it like this should restrict movement to vertical only:

[lua]

–local x = (event.x - event.xStart) + self.markX

local y = (event.y - event.yStart) + self.markY

self.y = y – move object based on calculations above

[/lua]

Yep, what he said. :slight_smile:

You just don’t tell Corona anything about movement on the X Axis.

Thx, but i know this.

My question was imprecise.

I want to let player move on the Y Axis but only up(not down). /only let increase Y

Hi @wojtekswieton,

Changing it like this should restrict movement to vertical only:

[lua]

–local x = (event.x - event.xStart) + self.markX

local y = (event.y - event.yStart) + self.markY

self.y = y – move object based on calculations above

[/lua]

Yep, what he said. :slight_smile:

You just don’t tell Corona anything about movement on the X Axis.

Thx, but i know this.

My question was imprecise.

I want to let player move on the Y Axis but only up(not down). /only let increase Y