Correct Parallax movement

In my game i have multiple layers to help give depth, as far as the X axis is concerned it seems to work fairly well. Where i have problems is on the Y axis. when my player jumps i would like the background layers to move slightly down. but as of now i can only get them to move up when the player jumps. somehow i cannot wrap my mind around how this needs to be coded to make a display group move the opposite direction of the players jump. here is what i have going on.

local function moveCamera()  
 if Tm.cameraActive == true then  
 if (Tm.tireObject.x \> 0 and Tm.tireObject.x \< 8500) then  
 gameScreen.x = -Tm.tireObject.x + 80  
 foreGround.x = -Tm.tireObject.x + 80  
 backgroundGroup.x = -Tm.tireObject.x / 8  
 farGroup.x = -Tm.tireObject.x \* 0.2  
 midGroup.x = -Tm.tireObject.x \* 0.4  
 closeGroup.x = -Tm.tireObject.x \* 0.6  
end   
 if (Tm.tireObject.y \> 0 and Tm.tireObject.y \< 3000) then  
 gameScreen.y = -Tm.tireObject.y + 220  
 foreGround.y = -Tm.tireObject.y + 220  
 backgroundGroup.y = -Tm.tireObject.y \* 0.5   
 farGroup.y = gameScreen.y   
 midGroup.y = -Tm.tireObject.y \* 0.5  
 closeGroup.y = -Tm.tireObject.y   
end   
  
end   
end  

as you can see “tireObject” is the Player that the camera follows. any suggestions would be great thanks [import]uid: 19620 topic_id: 8130 reply_id: 308130[/import]

How about…

background.y = player.y * .5

And just update the various values when something changes, or on enterFrame, no? [import]uid: 8271 topic_id: 8130 reply_id: 28966[/import]

Yea i do have a enterFrame listener for the camera so its constantly updated on the values. i just tried what you suggested again and it still moves the display group upwards. its so crazy because no matter how i seem to change the values as far as + or - it seems to react the same [import]uid: 19620 topic_id: 8130 reply_id: 28971[/import]

Well, I’m not sure what other logic you’ve got going on, but here at least you’ve not got any additions being applied to your y values, as far as I can see… [import]uid: 8271 topic_id: 8130 reply_id: 28979[/import]

so i i were to say for example

midGroup.y = Tm.tireObject.y \*.5  

that would be considered a positive value because im not writing it “-Tm.tireObject”?

so ive tried it like the above in the code brackets and it still jumps upwards when my player jumps

thanks for your comments by the way [import]uid: 19620 topic_id: 8130 reply_id: 28986[/import]

Well, using the code above would cause the background y value to be relative to the player y value consistently. Any more than that relies on your code. Can you post a larger sample? [import]uid: 8271 topic_id: 8130 reply_id: 28989[/import]

Yea i guess thats my main problem, is im not sure how to make that display group react without having it refer to the players y value.

i dont have alot more code but ill post everthing that is at least somewhat relative.

  
----Visual Layers---  
local verizonGroup = display.newGroup()  
local backgroundGroup = display.newGroup()  
local farGroup = display.newGroup()  
local midGroup = display.newGroup()  
local closeGroup = display.newGroup()  
local gameScreen = display.newGroup()  
local foreGround = display.newGroup()  
  
-- I then have a ton of objects that build my level, and i --insert them into the different display groups  
  
local function moveCamera()  
 if Tm.cameraActive == true then  
 if (Tm.tireObject.x \> 0 and Tm.tireObject.x \< 8500) then  
 gameScreen.x = -Tm.tireObject.x + 80  
 foreGround.x = -Tm.tireObject.x + 80  
 backgroundGroup.x = -Tm.tireObject.x / 8  
 farGroup.x = -Tm.tireObject.x \* 0.2  
 midGroup.x = -Tm.tireObject.x \* 0.4  
 closeGroup.x = -Tm.tireObject.x \* 0.6  
end   
 if (Tm.tireObject.y \> 0 and Tm.tireObject.y \< 3000) then  
 gameScreen.y = -Tm.tireObject.y + 220  
 foreGround.y = -Tm.tireObject.y + 220  
 backgroundGroup.y = -Tm.tireObject.y \* 0.5   
 farGroup.y = gameScreen.y   
 midGroup.y = Tm.tireObject.y + 25  
 closeGroup.y = -Tm.tireObject.y   
end   
  
 end   
end  
--The values on the camera function are pretty screwy because --im testing various values, any can be changed.  
  
--CAMERA LISTENER  
Runtime:addEventListener( "enterFrame", moveCamera )  

and thats pretty much it, i then have buttons that call functions to move my player and also jump the player, then in the camera all those layers react depending on the x and y of the players values… not sure if that is helpful for you. can you think of some other way that i can refer my display groups to rather than the player object? seems like it would need to be the player so that it operates like a camera should… [import]uid: 19620 topic_id: 8130 reply_id: 28991[/import]

Ok well i got it to a place where i can live with it. i wanted the background layers to actually move downward, but right now i have it so they will stay aligned with the Y of ground of the level, so it looks decent. here is what im doing.

local function moveCamera()  
 if Tm.cameraActive == true then  
 if (Tm.tireObject.x \> 0 and Tm.tireObject.x \< 8500) then  
 gameScreen.x = -Tm.tireObject.x + 80  
 foreGround.x = -Tm.tireObject.x + 80  
 backgroundGroup.x = -Tm.tireObject.x / 8  
 farGroup.x = -Tm.tireObject.x \* 0.2  
 midGroup.x = -Tm.tireObject.x \* 0.4  
 closeGroup.x = -Tm.tireObject.x \* 0.6  
end   
 if (Tm.tireObject.y \> 0 and Tm.tireObject.y \< 5000) then  
 gameScreen.y = -Tm.tireObject.y + 220  
 foreGround.y = gameScreen.y  
 backgroundGroup.y = Tm.tireObject.y \* -0.5   
 farGroup.y = gameScreen.y   
 midGroup.y = gameScreen.y  
 closeGroup.y = gameScreen.y  
end   
end  

maybe this will help someone else [import]uid: 19620 topic_id: 8130 reply_id: 29003[/import]