Centred character in a tiled world

What would anyone suggest is a good way to have a character (the player) stay in the centre of a tiled, top-down game while moving the view, or camera, around them?

I see the problem as being that if physics are involved, moving a global parent display group to provide the camera motion would have odd effects on physics objects.

Has anyone seen this (and beaten it)?

Thanks

Matt [import]uid: 8271 topic_id: 5165 reply_id: 305165[/import]

I see the problem as being that if physics are involved, moving a global parent display group to provide the camera motion would have odd effects on physics objects.

Are you sure? I haven’t had a chance to test this myself, but the Egg Breaker sample that comes with Corona does this.

Refer to this page in the documentation
http://developer.anscamobile.com/content/game-edition-box2d-physics-engine

search for the paragraph that ends: this is demonstrated in the “EggBreaker” sample code, which uses a single moving display group to create a “moving camera” effect. [import]uid: 12108 topic_id: 5165 reply_id: 17132[/import]

Good point; I’d not read that (or forgot it) - big thanks!

M [import]uid: 8271 topic_id: 5165 reply_id: 17145[/import]

You just have to make sure all your physics objects are in the same display group to avoid the odd effects you were talking about. [import]uid: 10835 topic_id: 5165 reply_id: 17148[/import]

Cool, thanks guys

m [import]uid: 8271 topic_id: 5165 reply_id: 17151[/import]

The easy way to do anything like this is to think outside the application loop…

You first move the character, normal, move x,y etc… This has to be like this for physics.

You then get the x and y of the character from the centre point.

You then move the background the opposite x and y and reset the character at 0
Because you are doing everything in 1 app frame you wont see the character moving around but instead the character in the centre and the background moved. [import]uid: 5354 topic_id: 5165 reply_id: 17250[/import]

Yup - that’s the direction I was heading in. (please forgive bad pun)

How about this… Let all characters move where and when they will and shift view in the enterFrame event.

I’m thinking this would keep the game logic a bit simpler and hopefully require only the one display group change in the event.

m

Ps: perhaps that’s what you were meaning and i misfired? [import]uid: 8271 topic_id: 5165 reply_id: 17261[/import]

Yup thats what I was getting at.

You basically move the camera ( ie the outer most group or whatever ) once you have finished every other calculation sin the loop. [import]uid: 5354 topic_id: 5165 reply_id: 17262[/import]