It looks like you're new here. If you want to get involved, click one of these buttons!
--Setup-- local bg1 = Bitmap.new(Texture.new("background_a.png"),true) local bg2 = Bitmap.new(Texture.new("background_a.png"),true) local bg3 = Bitmap.new(Texture.new("background_b.png"),true) local bg4 = Bitmap.new(Texture.new("background_b.png"),true) local bgFarY=0 local bgNearY=0 --OnEnterFrame-- function drawParallaxBackGround() bgFarY = bgFarY -1 bgNearY = bgNearY -4 local newFarY = bg1:getHeight() -(-bgFarY) if newFarY <=0 then bgFarY = 0 bg1:setY(bgFarY) else bg1:setY(bgFarY) bg2:setY(newFarY) end local newNearY = bg3:getHeight() -(-bgNearY) if newNearY <=0 then bgNearY = 0 bg3:setY(bgNearY) else bg3:setY(bgNearY) bg4:setY(newNearY) end end --Event-- stage:addEventListener(Event.ENTER_FRAME, drawParallaxBackGround) --Stage-- stage:addChild(bg1) stage:addChild(bg2) stage:addChild(bg3) stage:addChild(bg4) |
Likes: atilim
Comments
<pre lang="lua">
</pre>
to highlight.
In Aftermath Alvin we implemented parallax layers with different coefficients and call each one of them upon enter_frame, using a common "delta X". Every layer then applies its own factor.
of course, move far enough and the bitmap "ends". which then creates its own problems..
http://www.giderosmobile.com/forum/discussion/1158/class-and-example-for-parallax-background/p1