Hi.
This is example with two simple classes "ParallaxLayer" and "ParallaxBackground".
It help us to make scrolling backgrounds very easily in just few lines of code and
"unlimited" number of layers.
You can set scrolling speed of any individual layer.
Example on using it:
and in "LG_Render" method we call
The code of those classes is not mine, I fond it somewhere on the internet (java) and
adapted it to work with B4A and Informatix libGDX library.
So all the credits goes to them![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
See the attached example.
You'll need version 1.0 of the libGDX library.
screenshoot of attached example:
![1.jpg 1.jpg](https://www.b4x.com/android/forum/data/attachments/19/19536-35e1eeb726c31ac71c177acb7af6af11.jpg)
the file is too big for the forum, so there is a mine dropbox link
https://dl.dropboxusercontent.com/u/40815149/parallaxExample.zip
second example: (see the post #5)
https://dl.dropboxusercontent.com/u/40815149/parallaxExample2.zip
CheerS!
This is example with two simple classes "ParallaxLayer" and "ParallaxBackground".
It help us to make scrolling backgrounds very easily in just few lines of code and
"unlimited" number of layers.
You can set scrolling speed of any individual layer.
Example on using it:
B4X:
'Horizontal Scrolling
Dim Layer1 As ParallaxLayer: Layer1.Initialize(backgroundRegion,.1,0): ParalaxLayers.Add(Layer1): Layer1.Name = "Hills" ' the "Name" parameter is just helper (like a Tag property of a button)
Dim Layer2 As ParallaxLayer: Layer2.Initialize(cloudsRegion,.2,0) : ParalaxLayers.Add(Layer2): Layer2.Name = "clouds"
Dim Layer3 As ParallaxLayer: Layer3.Initialize(MidleRegion,.4,0) : ParalaxLayers.Add(Layer3): Layer3.Name = "fence"
Dim Layer4 As ParallaxLayer: Layer4.Initialize(landRegion,4,0) : ParalaxLayers.Add(Layer4): Layer4.Name = "land"
myParallaxBackground.Initialize(ParalaxLayers,Camera,Batch)
and in "LG_Render" method we call
B4X:
If myParallaxBackground.ScrolingHorizontal = True Then
myParallaxBackground.moveX(Velocity * DeltaTime)
myParallaxBackground.render
Else
myParallaxBackground.moveY(Velocity * DeltaTime)
myParallaxBackground.render
End If
The code of those classes is not mine, I fond it somewhere on the internet (java) and
adapted it to work with B4A and Informatix libGDX library.
So all the credits goes to them
See the attached example.
You'll need version 1.0 of the libGDX library.
screenshoot of attached example:
![1.jpg 1.jpg](https://www.b4x.com/android/forum/data/attachments/19/19536-35e1eeb726c31ac71c177acb7af6af11.jpg)
the file is too big for the forum, so there is a mine dropbox link
https://dl.dropboxusercontent.com/u/40815149/parallaxExample.zip
second example: (see the post #5)
https://dl.dropboxusercontent.com/u/40815149/parallaxExample2.zip
CheerS!
Last edited: