I have one image: background.png. How to create continuously repeating scrolling background image with android OpenGL ES or AndEngine library or other technology you know?
Example:<br/>
<img src="https://mycriticalapproachtotechnologyandsociety.files.wordpress.com/2007/02/cloudsscroll.gif" alt="moving cloud">
Currently, I use two-adjacent-image technique. I load image (background.png) two times and I put them adjacently, then I move them. So it looks like just one image scrolling continuously.
But, somehow I think there might be a better solution with just using one image instance. Anyone can share?
<strong>UPDATE</strong>:<br/>
For the one who curious, this is the two-adjacent-image code (using AndEngine library):
Above code is about making a background image repeatedly & vertically scrolling from top to bottom.
Note:<br/>
* movingBackgroundSprite is a Sprite class that load the background.png image. You can see there are two instances of the background Sprite.<br/>
* registerEntityModifier -> apply modifier/behaviour for the Sprite<br/>
* LoopEntityModifier -> looping behaviour<br/>
* MoveYModifier -> moving behaviour by y-position. The 1st argument is the duration (you can ignore this since it's nothing to do with the question), the 2nd argument is the Source-Y position, the 3rd argument is the Destination-Y position.<br/>
* CAMERA_HEIGHT -> constant that define the height of background image.<br/>
Example:<br/>
<img src="https://mycriticalapproachtotechnologyandsociety.files.wordpress.com/2007/02/cloudsscroll.gif" alt="moving cloud">
Currently, I use two-adjacent-image technique. I load image (background.png) two times and I put them adjacently, then I move them. So it looks like just one image scrolling continuously.
But, somehow I think there might be a better solution with just using one image instance. Anyone can share?
<strong>UPDATE</strong>:<br/>
For the one who curious, this is the two-adjacent-image code (using AndEngine library):
Code:
movingBackgroundSprite.registerEntityModifier(new LoopEntityModifier(
new MoveYModifier(10, -CAMERA_HEIGHT, 0)));
movingBackgroundSprite2.registerEntityModifier(new LoopEntityModifier(
new MoveYModifier(10, 0, CAMERA_HEIGHT)));
Above code is about making a background image repeatedly & vertically scrolling from top to bottom.
Note:<br/>
* movingBackgroundSprite is a Sprite class that load the background.png image. You can see there are two instances of the background Sprite.<br/>
* registerEntityModifier -> apply modifier/behaviour for the Sprite<br/>
* LoopEntityModifier -> looping behaviour<br/>
* MoveYModifier -> moving behaviour by y-position. The 1st argument is the duration (you can ignore this since it's nothing to do with the question), the 2nd argument is the Source-Y position, the 3rd argument is the Destination-Y position.<br/>
* CAMERA_HEIGHT -> constant that define the height of background image.<br/>