Using Two Images With Backdrop [SOLVED]


(Zouhair Elamrani Abou Elassad) #1

I’ve been using backdrop for parllax recently, here is my code :

	private var _background:Backdrop;

            [Embed(source="../assets/images/parallax/parallax.png")]
	private static const PARALLAX_BACKGROUND:Class;
	
	public function CaveBackground() 
	{
		this.x = 0;
		this.y = 0;
		
		initCaveBackground();
		
		layer = 10;
	}
	
	override public function added():void {
		
		graphic = _background;
	}
	
	
	private function initCaveBackground():void 
	{			
		_background = new Backdrop(PARALLAX_BACKGROUND, true, false);
		_background.scrollX = 0.2;
	}

The parallax is working great, i was just wondering is there a way to use two images instead of a one for the same parallax, Images : A and B and the parallax goes like this : A-B-A-B-A-B … etc


(Martí Angelats i Ribera) #2

The solution is create a custom BitmapData with both in there:

[embed(etc.)]
public const A:Class;
[embed(etc.)]
public const B:Class;

private var _bg:Backdrop;

public function initBg():void
{
	var a:BitmapData = FP.getBitmap(A);
	var b:BitmapData = FP.getBitmap(B);
	
	var r:BitmapData = new BitmapData(a.width + b.width, (a.height > b.height) ? a.height : b.height, true, 0);
	r.copyPixels(a, a.rect, new Point);
	r.copyPixels(b, b.rect, new Point(a.width));
	
	_bg = new Backdrop(r, true, false);
	_bg.scrollX = 0.2;
}

I haven’t test it but theorically this should work (too lazzy to create all the stuff needed to test it).


(Zouhair Elamrani Abou Elassad) #3

Thanks man, that’s working great :smile:


(Martí Angelats i Ribera) #4

I’m glad it has been usefull.

If you don’t understand anything about that code just ask me ^^


(Zouhair Elamrani Abou Elassad) #5

Thank’s, you’re doing me a great help :smile: