Problem getting camera following player Y axis

Hi guys,

I’ve started to use corona and I’m struggling to get this little game to work. I’m trying to make a simple platform game that goes up to y axis like a tower game.

And I wanted that the player as he goes trough the y Axis the camera follow him and the level too. But no success so far.

Here’s the code and a screenshot to try to explain you better:

http://pastebin.com/Z6vKYwV3

https://www.dropbox.com/s/tba1p80pt7bwjkl/Untitled.png

And recently I’ve discovered this lib that I tried to use on the game

http://developer.coronalabs.com/code/camera

Is there a simpler or different way to do this? 

Thanks!

You really don’t need a library for the camera. To add a camera you can do the following:

camera = display.newGroup()

By creating a newGroup that means whatever you put into this will act as one big object, you can imagine an invisible border go around all the objects. When you move the group, it movings everything in it. Thus you can easily create your own camera without any library. Things like the arrow keys dont need to be added to any group, keeping them on screen all the time.

Just add all the tiles and your character and when you move your character do camera.x = guy.x and camera.y = guy.y - display.contentHeight * 0.3 and it should work the way you want it I think. Haven’t done a camera movement in forever, if you need more help let me know

hatethinkingofnames

Thanks my friend it works but not at 100% I have to tweak the code a bit

Glad to see you got it to work on your own. What do you have to tweak? Did you get it to work perfectly or need help with something? Feel free to ask

Well I really wanted that the “camera” focus only on the player so when he jumps the camera follows his movement to the top of the platform, i don’t know if its something with the controls or with the camera and btw thanks for your help :slight_smile:

Try this:

local function moveguy (event)         guy.x = guy.x + motionx;  camera.x = guy.x camera.y = guy.y - display.contentHeight \* 0.3      end Runtime:addEventListener("enterFrame", moveguy)

Hmm didn’t work , or I’m putting it on the wrong place?

here’s the code so far

http://pastebin.com/As4qHxdg

Try this:

http://pastebin.com/eSCf5DB0

It works now! Thank you my friend!

My pleasure

You really don’t need a library for the camera. To add a camera you can do the following:

camera = display.newGroup()

By creating a newGroup that means whatever you put into this will act as one big object, you can imagine an invisible border go around all the objects. When you move the group, it movings everything in it. Thus you can easily create your own camera without any library. Things like the arrow keys dont need to be added to any group, keeping them on screen all the time.

Just add all the tiles and your character and when you move your character do camera.x = guy.x and camera.y = guy.y - display.contentHeight * 0.3 and it should work the way you want it I think. Haven’t done a camera movement in forever, if you need more help let me know

hatethinkingofnames

Thanks my friend it works but not at 100% I have to tweak the code a bit

Glad to see you got it to work on your own. What do you have to tweak? Did you get it to work perfectly or need help with something? Feel free to ask

Well I really wanted that the “camera” focus only on the player so when he jumps the camera follows his movement to the top of the platform, i don’t know if its something with the controls or with the camera and btw thanks for your help :slight_smile:

Try this:

local function moveguy (event)         guy.x = guy.x + motionx;  camera.x = guy.x camera.y = guy.y - display.contentHeight \* 0.3      end Runtime:addEventListener("enterFrame", moveguy)

Hmm didn’t work , or I’m putting it on the wrong place?

here’s the code so far

http://pastebin.com/As4qHxdg

Try this:

http://pastebin.com/eSCf5DB0

It works now! Thank you my friend!

My pleasure