Thank you! I will try this out.
“has been deleted or changed. Please refresh the page.” I am getting this error Or do I have to donate first? (I would have done it anyway )
ill check it it should be a free download
hold on
not sure why yet tried re uploading but didnt work
msg me your email and ill send to you
Message sent
It´s me again. I have made my own (pretty easy) function to solve this problem and this is what I´ve got so far:
function updateBackgrounds() --check whether the player is running or not: if player.isRunning == true then if player.x \<= \_W/2 then else if player.xScale == 1 then if (ground1.x \<= player.x - 495) then ground1.x = player.x + 465 end if (ground2.x \<= player.x - 495) then ground2.x = player.x + 465 end if (brownMountains1.x \<= player.x - 495) then brownMountains1.x = player.x + 465 end end end end
This code works as long as I do not change the parallax-ratio in my camera settings (again, I am using the perspective module!)
So my ground1 and ground 2 object are both moving by a ratio of 1. But I want to have other background images like “brownMountains1” that are moving with a ratio of 0.6 for example.
So I need to edit the above function in order to spawn the other layers accordingly to the player.
As far as I understand Perspective, it only moves the focussed object, the player, so only his x-values are changing.
Ok, sorry for not noticing sooner
Perspective actually doesn’t move the focus itself - it moves each layer around the player. When the player moves left, all the layers move right; when the player moves up, all the layers move down, etc. You might want to check out the :contentToLocal() and :localToContent() functions. They give the position of an object in comparison to the screen without taking position into account.
Perhaps like so:
(Warning: This is from the top of my head; it’s not even tested once)
[lua]
local objWrapTable={ – Put all your objects you want to wrap inside of here
brownMountains1,
ground1,
ground2
}
local wrapBoundX1=display.screenOriginX – Wrapping bound 1 (low)
local wrapBoundX2=display.contentWidth-display.screenOriginX – Wrapping bound 2 (high)
local wrapIncr=wrapBoundsX2-wrapBoundX1 – Don’t edit
local function wrapObjects()
for i=1, #objWrapTable do
local obj=objWrapTable[i]
local contentX, contentY=obj:localToContent(0, 0)
if contentX<=wrapBoundsX1-obj.contentWidth*0.5 then
obj:translate(wrapIncr, 0)
elseif contentX>=wrapBoundsX2+obj.contentWidth*0.5 then
obj:translate(-wrapIncr, 0)
end
end
end
[/lua]
- C
Hey Caleb,
This kind of works, I have to change the paramaters though But the general concept works just fine. Thank you very much!
local function wrapObjects() for i=1, #objWrapTable do local obj = objWrapTable[i] local contentX, contentY = obj:localToContent(0, 0) if contentX \<= wrapBoundX1 - obj.contentWidth\*0.5 then obj:translate(wrapIncr\*2, 0) print(obj) elseif contentX \>= wrapBoundX2 + obj.contentWidth\*0.5 then obj:translate(-wrapIncr\*2, 0) end end end
Well, after some trial and error I got this to work. I doubled the wrapIncr value and now it works as expected!
Glad you got it working, and thanks for using Perspective
- C