Parallax Scrolling Module posted to Code Exchange

Hello all,
I have just posted a Parallax Scrolling Module in the Code Exchange section. I wrote this module partially because there have been questions in recent weeks (especially from new Corona users) about how to utilize the "camera" in Corona. This module shows one method, along with the ability to set up multiple parallax scrolling layers for scrolling around a "world" of some user determined size.

This module is not designed for unlimited/endless scrolling games, i.e. a side-scrolling space shooter where the screen scrolls right-to-left indefinitely. This module is for scrolling around a set-size world/map/level, keeping the "camera" within the world limits.

Download the .zip file from the following page. The zip file includes the "main.lua" file, along with the associated image files.

Comments and testing reports would be appreciated... I didn't test this module to any extreme degree, and it can probably use some improvements to boost the flexibility, and perhaps the performance too. I'm curious to see/hear the results of others using this. :)

http://developer.anscamobile.com/code/parallax-scrolling-module

Brent Sorrentino
Ignis Design LLC

great thanks, will check tonight

Thank you so much for this code Brent, just what I needed.

Just one or two questions.

Firstly am using this with a joystick and buttons, the joystick works great a sits on top all the other layers. The buttons also sit on top of the other layers, but when I "touch" them also has an effect on the scrollable area and the buttons block. is there anyway for a touch on the button only to effect the buttons and not what is under them???

Also, I use pinch and zoom with this type of coding???

Sorry for all the questions, trying to get my head around lua, I am another one of those GS converts and love all the features corona offers.

Many thanks in advance
Chris

Chris you need to remove the touch/tap events on p0 etc and then modify the moveCamera function to take coordinates based on your joystick

Hi, I thought it sounded a bit complicated, but I still want to scroll using my finger on the screen, the joystick is just there to move an actor around.

Sorry for the misunderstanding

Hi Chris,

Give the following module a try... I made a few modifications to include a "joystick" object. This is just a placeholder and you'll need to follow the "Joystick 1.0" demo that somebody else created, if you haven't already. Anyway, this should be a start... it simply sets a flag when the joystick is in use, preventing the screen from scrolling.

parallax-joystick.zip

Of course, if I understand correctly, you want both the joystick and scrolling working in tandem in real time, i.e. the user's thumb controls the joystick while other finger drags, pinches, etc. to move the screen around. In this case, the whole scenario could get very very complicated, because you'll have to be asking Corona to determine multiple touches, their positions, movements, phases, etc.

Best of luck... I don't have time to truly enhance this module right now (I need to get cracking on my own game again, ha ha). Hopefully you can figure it out!

Brent

Hi,

Thanks for the response, but I already have the joystick and it works great, but I also have 2 buttons, and they block when pressed for some reason.

also can I zoom and pinch with the moveCaemra function??

sorry for the the bother
Chris

Hi Chris,

Pinch and zoom scaling would require a second function, but I think it's relatively straightforward using the same parallax layers. The front layer would scale at a higher ratio than the layers further back, for a realistic visual effect. I might try to tinker with that today, for my own curiousity...

This would make the module basically like "Angry Birds". I wasn't trying to mimic Angry Birds with this module, but afterwards I realized it could be used for a similar purpose. Everybody likes Angry Birds right? :)

Brent

Hi Brent,

You are so right the whole world likes angrybirds including me. I think that game and doodle jump are good examples of what works on mobile platforms. The secret I think for game developers now is not to make copies of these games but include features that work on mobile platforms and incorporate them into there own games to give the end user the best possible experience even if a game only costs a few cents. Unfortunately I see many copy cats. That is why I took the plunge from gs here to corona, the end user now wants facebook integration and scoreboards. Anyway rant/opinion over, wrong thread

Hello...Thanks for the great parallax code!! It has been fun implementing it into my game...

but I have a question, just like Chris, I have several buttons in my app that when pressed don't do their function anymore after putting in the parallax

once I remove this

Runtime:addEventListener( "touch", moveCamera )

They work again, but obviously that stops the parallax from scrolling

I tried several other things to get it to work, but to no avail

so, I was wondering if you could help me with whats going on.

Thanks!

Hi hiphopsded,

This parallax module was rather old: something I wrote months ago and haven't thought about much since. I just fixed up the code and used some different methods which should allow buttons to work. You just need to place them in a new layer in front of everything else. It's all outlined in the latest version of the module... just re-download it and let me know if anything goes wrong.

http://developer.anscamobile.com/code/parallax-scrolling-module

I admit this code still isn't as efficient or full-featured as it could be. Not even close. Someday I'd like to add pinch-stretch zooming, but since I'm not actually using this parallax code in my current game, I don't have the incentive at this time.

Anyway, best of luck with it!
Brent Sorrentino

Is it possible to have a parallax effect using the accelerometer/gyroscope?

views:1930 update:2011/12/29 9:44:01
corona forums © 2003-2011