Group objects and relative camera positioning

I’ve searched the forum and found a few posts about groups and collision. I seem to have the same problem, but in a slightly different manner. Every single object I’ve added to my game, I have put into my one and only group, called Game( I took this from the Egg demo ). Specifically, I have a ragdoll( lots of square objects bound together with joints ), and some static objects on each side of the screen for collision. When I apply a force to the ragdoll, launching it into the air, the graphics and physics separate. You can see this best using Hybrid drawing mode. I have an update event that moves the group Game y component up or down, based on where the ragdoll goes. If I comment out the Game y component changing, and simply let the ragdoll go without having the camera follow it, the physics and graphics are in sync with each other, appearing to be one and the same, like I’d want. I assume this has something to do with my group, and how I am manipulating it. Can anyone help? Its pretty similar to the Egg demo, but instead of going left/right, I’m going up/down.

Thanks! [import]uid: 8673 topic_id: 2250 reply_id: 302250[/import]

Here is a simple program to demonstrate part of my problem. In the function moveCamera(), if you comment out the line that sets the y location of the game group, everything looks and works as expected. If you leave it as it is, The “floor” is drawn above the square, but the floor physics is below the square.

Ansca, can you please let me know if this is a bug, or am I using the group display concept for moving the camera incorrectly?

Thanks!
Mark

local physics = require(“physics”)
physics.start()
physics.setDrawMode( “hybrid” )

– Create master display group (for global “camera” scrolling effect)
local game = display.newGroup();
game.x = 0

mainObject = display.newRoundedRect( 120, 220, 25, 30, 12 )
mainObject:setFillColor(205,133,63,255 )
physics.addBody( mainObject, “dynamic”,{ density=3, friction=0.5, bounce=0.5 })
mainObject.isBullet = true

shelf = display.newRoundedRect( 0, 420-10, 1600, 16, 5 )
shelf:setFillColor(225,143,33,255 )
physics.addBody( shelf, “static”,{ density=3, friction=0.5, bounce=0.5 })
game:insert( shelf )

– Camera follows object automatically
local function moveCamera()
game.y = -mainObject.y
end

Runtime:addEventListener( “enterFrame”, moveCamera )
[import]uid: 8673 topic_id: 2250 reply_id: 6847[/import]

Hi Mark,

This is my first time using Corona. I think I fixed your problem:

local physics = require(“physics”)
physics.setDrawMode( “hybrid” )
physics.start()

– Create master display group (for global “camera” scrolling effect)
local game = display.newGroup();
game.x = 0

mainObject = display.newRoundedRect( 120, 220, 25, 30, 12 )
mainObject:setFillColor(205,133,63,255 )
physics.addBody( mainObject, “dynamic”,{ density=3, friction=0.5, bounce=0.5 })
game:insert( mainObject ) – added main object to game group
– mainObject.isBullet = true – it’s not a bullet

shelf = display.newRoundedRect( 0, 420-10, 1600, 16, 5 )
shelf:setFillColor(225,143,33,255 )
physics.addBody( shelf, “static”,{ density=3, friction=0.5, bounce=0.5 })
game:insert( shelf )

– Camera follows object automatically
local function moveCamera()
game.y = -mainObject.y + 240 – offset by 1/2 height
end

Runtime:addEventListener( “enterFrame”, moveCamera ) [import]uid: 8741 topic_id: 2250 reply_id: 6887[/import]

Thanks ORBZ. I’ve tried offsets, it works if you don’t leave the screen area. If you give the object an impulse so it travels up and off the screen, the camera fails to track. I suppose I should have been more specific in my post. What I want is the ability for the camera to follow an object up/down. It appears to work fine if the object travels along the x axis. Does anyone know how to set the camera focus/position?
Thanks for your help ORBZ.

Ansca, do you read these posts, or should I be posting this in the Bug sub-forum?

Thanks,
Mark [import]uid: 8673 topic_id: 2250 reply_id: 6976[/import]

I think prob is that you left mainObject out of group (changes marked with **):

local physics = require("physics")  
physics.start()  
physics.setDrawMode( "hybrid" )  
  
local midY = display.contentHeight/2 -- \*\*  
  
-- Create master display group (for global "camera" scrolling effect)  
local game = display.newGroup();  
game.x = 0  
  
mainObject = display.newRoundedRect( 120, 220, 25, 30, 12 )  
mainObject:setFillColor(205,133,63,255 )  
physics.addBody( mainObject, "dynamic",{ density=3, friction=0.5, bounce=0.5 })  
game:insert(mainObject) -- \*\*  
--mainObject.isBullet = true -- \*\* not needed  
  
shelf = display.newRoundedRect( 0, 420-10, 1600, 16, 5 )  
shelf:setFillColor(225,143,33,255 )  
physics.addBody( shelf, "static",{ density=3, friction=0.5, bounce=0.5 })  
game:insert( shelf )  
  
-- Camera follows object automatically  
local function moveCamera()  
 game.y = -mainObject.y + midY -- \*\* change  
end  
  
Runtime:addEventListener( "enterFrame", moveCamera )  

[import]uid: 3953 topic_id: 2250 reply_id: 7047[/import]

You didn’t actually test my code huh? There was more to it than offsets. As mark pointed out, you didn’t put your main object in the group AND you needed the offset. [import]uid: 8741 topic_id: 2250 reply_id: 7078[/import]

Quite right. ORBZ had already given the answer. My post was unnecessary. [import]uid: 3953 topic_id: 2250 reply_id: 7106[/import]

Thanks to everyone. Centering and adding mainObject to the group was the solution. Thanks again!
[import]uid: 8673 topic_id: 2250 reply_id: 7131[/import]