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 [import]uid: 50842 topic_id: 14679 reply_id: 314679[/import]

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). [import]uid: 44767 topic_id: 14679 reply_id: 54295[/import]

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?

[import]uid: 50842 topic_id: 14679 reply_id: 54296[/import]

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. [import]uid: 23693 topic_id: 14679 reply_id: 54304[/import]

Is it also possible to use groups to create, in effect, a rotating and zooming camera? Can I just apply a rotation to the group? [import]uid: 96427 topic_id: 14679 reply_id: 60475[/import]

Rotation should work just fine. Zooming might be a bit trickier. There may be some example code in the angry birds example.

I posted some code about a camera I’m working on at the moment. It’s super loose and throws up some problems which I’ve yet to resolve, but if you want a simple drag and drop code example, take a look.

http://developer.anscamobile.com/forum/2011/10/11/camera-not-functioning-it-should-drag-and-drop-code-example

Hope it helps. [import]uid: 67933 topic_id: 14679 reply_id: 60478[/import]

Great, thank you very much. :slight_smile: Normally I would use matrices for this sort of thing, but I’m not sure that’s a common use case in Corona. [import]uid: 96427 topic_id: 14679 reply_id: 60502[/import]