Corona Tutorial: Dragging Physics

Posted 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!)

Ready to get started?

Create amazing games and apps for iOS & Android

9 Comments

Matt WNovember 4th, 2010 at 5:45 am

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.

TimNovember 4th, 2010 at 8:33 am

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

KrstNovember 9th, 2010 at 11:39 am

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!

krstNovember 9th, 2010 at 11:40 am

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

TimNovember 9th, 2010 at 12:08 pm

Hi, thanks for the feedback, I’m glad you liked it. Here’s the code:

http://developer.anscamobile.com/sites/default/files/GameUI-DragBody.zip

Tim

[...] off the Quick Start Guide and video tutorials that we’ve recently created for you, we now bring you a newly revamped Sample Apps [...]

BenMarch 10th, 2011 at 12:06 pm

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.

DavidJuly 6th, 2011 at 8:26 pm

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

DavidJuly 6th, 2011 at 9:06 pm

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. :-(

Leave a comment

Your comment