Moving The 'Camera' On The Screen

Hey Guys,
So I'm developing my first Corona app, & I can't figure out how to move the 'camera' (that's what we called it at GameSalad). Basically I need to know if the screen is 500 pixels long (can only display 480 at a time), sometimes I'd like the camera to show the other part of the screen.

Can someone show me how to do this?

Thanks,
Matt

Add your elements (i.e. background, ground, etc...) into a group (cameraGroup = display.newGroup()) and then manipulate the x value of that group (cameraGroup.x = 100).

Ahh ok. But then how exactly would I get a player to control the camera when hes moving all around? And some other objects are moving around in different directions too. Wouldn't that cause many problems? There's not a function or something to move the camera?

Groups make it mostly easy. Regardless of what directions objects within that group move, the screen will draw correctly when you move the group. The objects within it will move relative to the group their in.

If your character moves right, move the group left (group.x = group.x - moveSpeed). If your character moves left, move the group right. There are a few ways you can go about that, but the easiest way is to move the character and group the same speed (similar to Sonic the Hedgehog).

Finally, add bounding checks to ensure if you move left, it stops. Same for right.

views:1477 update:2011/10/11 8:57:46
corona forums © 2003-2011