Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a few ways to do this.</p> <p>You could set up some static physics bodies as walls (just outside the edges of the screen), and the attach dynamic physics bodies to your draggable objects. You would need to set custom collision filters if you didn't want multiple draggable objects to collide with each other though.</p> <p>The easiest way (assuming your objects are not already physics objects) is to put all of your draggable items into a table. Then in a Runtime listener, constantly check the x and y positions of your objects. E.g</p> <pre><code>object1 = display.newimage..... local myObjects = {object1, object2, object3} local minimumX = 0 local maximumX = display.contentWidth local minimumY = 0 local maximumY = display.contentHeight local function Update() for i = 1, #myObjects do --check if the left edge of the image has passed the left side of the screen if myObjects[i].x - (myObjects[i].width * 0.5) &lt; minimumX then myObjects[i].x = minimumX --check if the right edge of the image has passed the right side of the screen elseif myObjects[i].y + (myObjects[i].width * 0.5) &gt; maximumX then myObjects[i].x = maximumX --check if the top edge of the image has passed the top of the screen elseif myObjects[i].y - (myObjects[i].height * 0.5) &lt; minimumY then myObjects[i].y = minimumY --check if the bottom edge of the image has passed the bottom of the screen elseif myObjects[i].x + (myObjects[i].height * 0.5) &gt; maximumY then myObjects[i].y = maximumY end end end Runtime:addEventListener("enterFrame", Update) </code></pre> <p>That loop presumes that the reference point of your images is in the center, you would need to adjust it if they are not.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload