Screen Limits

But if I use these variables Field the background will no longer be responsive

Well, than change the values to be responsive :wink:

That are just dummy values I chose, can be any values you want.

does not work, have changed the code a few times and still not can get to work :frowning: :frowning: :frowning: :frowning:

David,

See if this helps.

Start a new app.  

Paste into main.lua the code I show below.

Run the app. 

Drag any of the circles onto the field and release where you want them.  If you drag them off the field and release them, they return automatically to their original position, just off the bottom edge of the field.

Is that what you are wanting your code to do?

local tokens = {} local tokenColors = { {.7, .1, .1}, {.8, .8, .8}, {.1, .1, .7} } local leftEdge, topEdge, rightEdge, botEdge local field = display.newRect(display.contentCenterX, display.contentCenterY, 250, 200) field:setFillColor(.1,.8,.1) leftEdge = field.x - (field.width \* .5) topEdge = field.y - (field.height \* .5) rightEdge = field.x + (field.width \* .5) botEdge = field.y + (field.height \* .5) local function moveToken(e) local t = e.target if e.phase == "began" then display.getCurrentStage():setFocus( t ) t.isFocus = true -- Store initial position t.x0 = e.x - t.x t.y0 = e.y - t.y elseif t.isFocus then if e.phase == "moved" then t.x = e.x - t.x0 t.y = e.y - t.y0 elseif e.phase == "ended" then if t.x \< leftEdge then t.x = t.base.x t.y = t.base.y elseif t.x \> rightEdge then t.x = t.base.x t.y = t.base.y end if t.y \< topEdge then t.x = t.base.x t.y = t.base.y elseif t.y \> botEdge then t.x = t.base.x t.y = t.base.y end -- note that the token is set in place display.getCurrentStage():setFocus(nil) end end return true end for i = 1 , 3 do table.insert(tokens, display.newCircle(50,50,20)) tokens[i]:setFillColor(tokenColors[i][1],tokenColors[i][2], tokenColors[i][3] ) tokens[i].x = i \* 80 tokens[i].y = field.y + (field.height \* .6) tokens[i]:addEventListener("touch", moveToken) tokens[i].base = {x = tokens[i].x, y = tokens[i].y} end

Hope it helps!

Bob

WORK!!! WORK!!!

I have to do some changes but WORK !!!

TY MAN !! :wub: :wub: :wub: