Posted on by

Tim is taking a break this week from his “Game in 8 Minutes” series, but has still provided you with a very useful tutorial on dragging physical objects. (somebody could make a really cool shuffleboard game with this!)


Posted by . Thanks for reading...

9 Responses to “Corona Tutorial: Dragging Physics”

  1. Matt W

    Please add 3 things: multi-touch dragging, resizing of objects using multi-touch and replacing the squares with images ;)

    Yes, you know where I’m going with that, but the principle is widely useful and often implemented in many iPhone apps.

    Awesome Hetal, thanks again.

    Reply
  2. Tim

    Thanks for the comment, Matt. Two of the improvements you suggest are pretty easy:

    To use images, in place of the for() loop that calls newRect() you can use newImage(), e.g.:

    local puck1 = display.newImage(“image1.png”)
    local puck2 = display.newImage(“image2.png”)
    local puck3 = display.newImage(“image3.png”)

    (http://developer.anscamobile.com/reference/index/displaynewimage)

    To enable multitouch, you just have add one line of code:

    system.activate(“multitouch”)

    (http://developer.anscamobile.com/content/events-and-listeners#Using_multitouch)

    To resize images with multi-touch requires some more work, but the PinchZoomGesture sample in the Corona SDK (Interface/PinchZoomGesture) provides a good starting point.

    Tim

    Reply
  3. Krst

    Hi Tim

    Great tutorial and many thanks!

    However i want to ask where the sample code is? I could not find it (or i did not know where to look for it) in the latest corona sdk version?!

    Thanks!

    Reply
  4. krst

    Hi Tim

    I loved the tutorial, very good, thanks! But I could not find the tutorial in the sdk sample code for this in the latest sdk? Or maybe i misunderstood?

    Thanks

    Reply
  5. Ben

    Hey Tim i’m new to Corona and i was wondering if you could help me with a problem i was having on my app, so i have an object following my “touch” and i want a second object to follow the first object at a certain rate/speed( like a game of tag) but i have been searching for the code but haven’t had any luck finding anything about it so i was wondering if you could help me.

    Reply
  6. David

    I am enjoying the tutorials very much. Corona is definitely expediting the development process. I noticed several others in various forums have asked a question similar to the one I have, but there doesn’t appear to be any solid guidance anywhere. Specifically, there are a few of us out here that are having issues combining physics functionality with dragging functionality.

    Specifically, when I add the following three lines of code to this demo, it breaks.

    —————————–
    physics = require(‘physics’)
    physics.start()


    physics:addBody( button, {density=3.0, friction=1.0, bounce=0.03})
    ——————————

    Specifically, there error message presented is “…bad argument #-2 to ‘addBody’ (Proxy expected, got nil)”

    Can you shed some light on what issues there are on dragging physical objects in a gravitational world? Any insight/direction would be greatly appreciated.

    David

    Reply
  7. David

    Sorry, I typed that too quickly. Actual physics code is as follows:

    local physics = require(‘physics’);
    physics.start();

    Still get the same “…bad argument #-2 to ‘addBody’ (Proxy expected, got nil)” error message. :-(

    Reply

Leave a Reply

  • (Will Not Be Published)