Background - depth perception

Hi all, am playing around with corona, using the ghosts vs monsters code to learn.

I’d like to create some depth in the background. By default ghosts vs monsters background slides as the camera moves, how can I add a second background layer that stays still or has limited movement, while the background in front of this slides with the camera?

Thanks [import]uid: 113162 topic_id: 21850 reply_id: 321850[/import]

While you have a moving background in the “front”, you could add a static image in the “back” with the same method you would to display any other object on your scene… in my scenario i use something like;

add the below on top of your scrolling image code.

[lua]-- my static background
local background = display.newImageRect(“image.png”, 320, 480)
– add all the properties to your background image here (setReferencePoint, x, y, etc)[/lua]

I’m assuming since you’re using the Ghosts vs. Monster template you have already a moving/scrolling background code?

[import]uid: 10379 topic_id: 21850 reply_id: 86886[/import]

Thanks for the reply but im not to sure where to position it, i’ve created a new group but no matter where it is positioned it aleways overlays the group containing the foreground of the game… [import]uid: 113162 topic_id: 21850 reply_id: 86905[/import]

Seb Lee did a demo using Corona and program Angry Bird like game in 30 minutes. He included in the final code a parallax effect which I think what you are after, if i’m not mistaken. It’s also very easy to follow specially if you’re just starting out.

You can go to his blog and read about it here:

http://seb.ly/2011/09/angry-birds-in-30-minutes-at-update-2011/

or download it directly here:

http://dl.dropbox.com/u/5096013/ConfStuff/UpdateAssets.zip
[import]uid: 121875 topic_id: 21850 reply_id: 86959[/import]

Groups and objects will overlay depending on the order they are added.
Add the background image first. [import]uid: 10389 topic_id: 21850 reply_id: 86973[/import]

Thank you all for the pointers - I’ve made some progress.

I have a second layer to my background. The initial transition works great. In ghosts vs monsters the camera starts on the level end and pans to the level start. I have added my rear background image in two parts that spans a total width of 720, with the front two parts spanning 960 - this then gives the illusion of the closer background sliding past quicker than the rear as the game goes to level start.

The problem I have is in the game - when the ghost is fired my front background transitions with the ghosts movement but my rear background doesn’t move relatively, it goes with the front background and then slides to the right once the camera is still, I need this to move slower.

I appreciate this is a stab in the dark without any code to pick at, but appreciate all thoughts [import]uid: 113162 topic_id: 21850 reply_id: 87071[/import]

Right - sorted!

For anyone facing something similar in the future, when the character moves both background layers moved with this, instead I have my rear background move relative to my front background - works great! [import]uid: 113162 topic_id: 21850 reply_id: 87128[/import]

I’m trying to implement this in ghosts vs monsters myself. Could you post the code? [import]uid: 135180 topic_id: 21850 reply_id: 98796[/import]

Hi, my code is far too long to paste, but I can help you achieve what you need.

How far have you got so far? I used 3 background groups, each at varying total widths, and moving at a speed so that they are all relative e.g. My nearest background group runs the entire width of my stage, but the 2nd layer is only two thirds the width of my stage, so when the camera scrolls from the start to the end of the level, the nearest background group can scroll the whole way, but group 2 must move slower so that it does not get to the end of the image before the stage end! I do this by moving it relative to background 1

Look at both the ‘swipetween’ and ‘move ca,era to see effect’’ code in GvM to implement this

Post your code and I can be a bit more clear [import]uid: 125592 topic_id: 21850 reply_id: 98804[/import]

I have not gotten very far at all, just trying to get my head around the logic here:

You are essentially splitting gameGroup into 3 different groups (gameGroup1, gameGroup2, gameGroup3) at different widths and then calling them all in swipetween and “move camera”. Applying different speeds via the “time=” function so that they are moving independently of each other?

Or am I totally off here? [import]uid: 135180 topic_id: 21850 reply_id: 98863[/import]

Has anyone had any luck with this?

I would love to emulate the parallax effect in Seb.ly’s example. However, it seems like the background and layered groupings in Seb’s example (as well as the camera control) are handled differently in the Ghosts vs. Monsters group.

If anyone has any insight as to how to do this - perhaps expand out the gameGroup parameters a bit, or at the very least have some sort of parallax effect - that would be very very helpful. Seriously sleepless nights at this end trying to tinker with it and make it work. [import]uid: 75582 topic_id: 21850 reply_id: 109946[/import]