RG Camera problem

Hi all,

I am trying to create something similar to Doodle Jump game, and i am using RGCamera library:

https://github.com/roaminggamer/RGCamera

Tnx RoamingGamer!

I have two problems:

  1. When “Smiley” (the player) jumps he gets to close to the upper edge of the screen (portrait orientation).

How to keep player in 2/3 or half of bottom part of screenHeight?

  1. I have applied physics to the player (dynamic object) and to the circles (static objects).

My problem is when “Smiley” (the player) jumps (setLinearVelocity) and then falls down, as he is falling down the circles (static objects) are moving up.

How to make that as he falls down the circles (static objects) are NOT moving up (like in Doodle Jump)?

Basically I want that camera follows circles only in -Y direction ** (UP) **  -_-

Many many many thanks!  :smiley:

GG

Code here (you have it on above link also).

-- ============================================================= -- Step 1. - Load RGCamera -- ============================================================= local camera = require "RGCamera" -- ============================================================= -- Step 2. - The example -- ============================================================= -- -- Tip: Camera selection is at bottom of this file. -- -- -- a. Set up some useful variables -- local centerX     = display.contentCenterX local centerY      = display.contentCenterY local w                  = display.contentWidth local h                   = display.contentHeight local fullw           = display.actualContentWidth local fullh            = display.actualContentHeight local left                              = centerX - fullw/2 local right            = centerX + fullw/2 local top                              = centerY - fullh/2 local bottom      = centerY + fullh/2 -- -- b. Create rendering layers for our game with this --    final Layer Order (bottom-to-top) -- --[[                display.currentStage\                                                                                               |---\underlay                                                                                               |                                                                                               |---\content                                                                                               |                                                                                               |---\overlay --]] layers                                                   = display.newGroup() layers.underlay                = display.newGroup() layers.content                  = display.newGroup() layers.overlay                   = display.newGroup() layers:insert( layers.underlay ) layers:insert( layers.content ) layers:insert( layers.overlay ) -- -- c. Randomly populate the world with random circles -- for i = 1, 250 do                 local x = math.random( left - fullw, right + fullw )                 local y = math.random( top - fullw, bottom + fullw )                 local radius = math.random(10,15)                 local circle = display.newCircle( layers.content, x, y, radius )                 circle:setFillColor( math.random(), math.random(), math.random() )                 circle.alpha = 0.25                 physics.addBody(circle, "static", {desity = 1.0, friction = 1.0, bounce = 0.2}) end -- -- d. 'Frame' legal bounds of 'world' -- local tmp = display.newRect( layers.content, centerX, centerY, fullw, fullh ) tmp:setFillColor(0,0,0,0) tmp:setStrokeColor(1,0,0) tmp.strokeWidth = 2 -- -- Move the player upwards local function movePlayer(event)       player:setLinearVelocity(0, -500) end -- -- e. Create a 'player' as the camera target -- local player = display.newImageRect( layers.content, "smiley.png", 40, 40) player.x = centerX player.y = centerY physics.addBody(player, "dynamic", {desity = 1.0, friction = 1.0, bounce = 0.2}) player:addEventListener("tap", movePlayer) -- -- g. Attach a camera to the player and the 'world' -- -- Uncomment any ONE of the following lines to see that camera in action -- camera.tracking( player, layers.content ) --camera.tracking( player, layers.content, { lockX = true, lockY = false } ) --camera.tracking( player, layers.content, { lockX = false, lockY = true } ) --camera.trackingLooseSquare( player, layers.content, { boundarySize = 100 } ) --camera.trackingLooseSquare( player, layers.content, { boundarySize = 160 } ) --camera.trackingLooseCircle( player, layers.content, { debugEn = true } ) --camera.trackingLooseCircle( player, layers.content, { bufferSize = fullh/2, deadRadius = 0, debugEn = true } ) --camera.trackingLooseCircle( player, layers.content, { bufferSize = 10, deadRadius = fullh/2 - 10, debugEn = true } )

#1 - Simply start the player in the position you want to center on.  Right now it starts in the center of the screen, so the (tracking) camera locks to that position.  If the player starts 100 pixels above the bottom of the screen, the camera will lock there.

Don’t forget look at the code and you’ll notice a number of parameters like: 

  • lockX, lockY - Lock motion on the x or y axis respectively.
  • centered - Overrides initial position and lock to center (not what you want).

Also, play with the loose square and circle versions.  if you’re not happy w/ tracking.

#2 - This camera code isn’t designed to exclude objects from the motion and it would take some engineering to make it work that way, because the premise of this code is that the group the player is in (and all other content) is moved in the opposite direction of the player’s motion thus keeping the player in the same screen position.

The good news is, you have the code and can experiment with it, to make your own camera algorithm(s).

Also, if you do put objects outside the group, their physics bodies will no longer interact correctly with other bodies.

PS - I’m slightly familiar w/ doodle jump but have hardly played it.  Can you include a link to a YouTube video showing the interaction you are talking about including a MM:SS time stamp where I should look to see it?  That will save me having to download and play the game, then find the interaction you mean.

more on #2 - If you mean, the camera only moves up and not down, that’s easy.  Just modify the algorithm to only update if the new player position is above the old tracked Y.

Hi Ed,
I will try that!
I am out of the house so I will try thia later.

I will let you know the results!

But for #2: If I would do that I assume the player would get closer everytime to the screen Top?
That cannot be done via bulldin function?
It can be only done if I modify your code?

Thx.
G

Just watch first 15 seconds of this video and you will see what I am talking about:

https://youtu.be/wjofzwaC_Oo

I am on a cell so sorry for not linking this link :slight_smile:

re: #2 - No, it would simply not move down below the startY.  

Also, the very basic camera I supplied won’t do exactly what you’re looking for.

The closest thing I have to this movement is an OLD template: 

https://www.youtube.com/watch?v=Uh7GRt1_hfA

However, that template is very out of date.  (Note: It is included in an updated format in EAT).

Note: Not trying to sell you anything here.  You can get there from the free code you have.  I’m just saying I can’t help much more than this.  :(

Ok. Thanks Ed :slight_smile:
I will think this over :slight_smile:

I have tried for few days to put everything in a displayGroup, and move that around.
Main problems are:

  • either you mess collisions
  • or the player escapes above screen Top

Many thanks!
G

Hi Ed :slight_smile:

With only addition of “if dy < 0 then”  problem solved!  :smiley:

I have the Doodle Jump scene  :smiley:

Many many many thanks!!

G

I knew you could resolve it.  Good job.

Thank you! :slight_smile:

Hi Ed :smiley:

I do not know why, but this code works slightly different in Composer.

When playing it in main.lua ( no Composer ) player jumps from screenBottom (initial player position) to the centerY, and then camera follows (player is centered).
So you get nice jump simulation.

When moving code to Composer player is always (fixed) at screenBottom (player initial position).
Camera follows but it does not look nice (no jump simulation).

Any ideas why is this happening?
Maybe due to Composer sceneGroup?
I tried to insert layers.content into Composer sceneGroup (no help).

Also I have to run "** camera.tracking( player, layers.**content)" before scene:create and scene:show (otherwise following does not work).

Many many thanks! :slight_smile:
G

I do not know what I did, but everything works fine! :slight_smile: Case closed! Thanks Ed! :slight_smile:

#1 - Simply start the player in the position you want to center on.  Right now it starts in the center of the screen, so the (tracking) camera locks to that position.  If the player starts 100 pixels above the bottom of the screen, the camera will lock there.

Don’t forget look at the code and you’ll notice a number of parameters like: 

  • lockX, lockY - Lock motion on the x or y axis respectively.
  • centered - Overrides initial position and lock to center (not what you want).

Also, play with the loose square and circle versions.  if you’re not happy w/ tracking.

#2 - This camera code isn’t designed to exclude objects from the motion and it would take some engineering to make it work that way, because the premise of this code is that the group the player is in (and all other content) is moved in the opposite direction of the player’s motion thus keeping the player in the same screen position.

The good news is, you have the code and can experiment with it, to make your own camera algorithm(s).

Also, if you do put objects outside the group, their physics bodies will no longer interact correctly with other bodies.

PS - I’m slightly familiar w/ doodle jump but have hardly played it.  Can you include a link to a YouTube video showing the interaction you are talking about including a MM:SS time stamp where I should look to see it?  That will save me having to download and play the game, then find the interaction you mean.

more on #2 - If you mean, the camera only moves up and not down, that’s easy.  Just modify the algorithm to only update if the new player position is above the old tracked Y.

Hi Ed,
I will try that!
I am out of the house so I will try thia later.

I will let you know the results!

But for #2: If I would do that I assume the player would get closer everytime to the screen Top?
That cannot be done via bulldin function?
It can be only done if I modify your code?

Thx.
G

Just watch first 15 seconds of this video and you will see what I am talking about:

https://youtu.be/wjofzwaC_Oo

I am on a cell so sorry for not linking this link :slight_smile:

re: #2 - No, it would simply not move down below the startY.  

Also, the very basic camera I supplied won’t do exactly what you’re looking for.

The closest thing I have to this movement is an OLD template: 

https://www.youtube.com/watch?v=Uh7GRt1_hfA

However, that template is very out of date.  (Note: It is included in an updated format in EAT).

Note: Not trying to sell you anything here.  You can get there from the free code you have.  I’m just saying I can’t help much more than this.  :(

Ok. Thanks Ed :slight_smile:
I will think this over :slight_smile:

I have tried for few days to put everything in a displayGroup, and move that around.
Main problems are:

  • either you mess collisions
  • or the player escapes above screen Top

Many thanks!
G

Hi Ed :slight_smile:

With only addition of “if dy < 0 then”  problem solved!  :smiley:

I have the Doodle Jump scene  :smiley:

Many many many thanks!!

G

I knew you could resolve it.  Good job.