ScrollFactor problem



  • Hello,

    I'm using scrollFactor to make a parallax effect and I would like to reuse assets when they leave entirely the screen on left to add them to the right.
    So should I use getScreenXY(); to know if they are outside?
    For example:

    override public function update():Void 
    	{
    		super.update();
    		var pt = getScreenXY();
    		if(pt.x < -width){
    			x += nextX;
    		}
    		pt.put();
    		
    	}
    

    But the problem I'm running into is that the first time update is executing x=0 but getScreenXY().x=-2860 but are we all agree that getScreenXY should be 0 the first time?

    The only way to have correct positioning is to set scrollFactor.set(0,1); but I don't have parallax anymore of course so I guess there is a misunderstanding of how scrollFactor works. Any help? Thanks.



    • You can use isOnScreen to check if the sprite is... on the screen
    • For parallax to work, you need to set the x or y value or both between 0 and 1 like scrollFactor.set(.5, 1);
    • You can also use FlxBackdrop for infinitely scrolling background


  • If I change Camera style from STYLE_LOCKON to STYLE_NO_DEAD_ZONE, I have correct values and my code works as expected.
    But I need my character stay in the far left and I soon I add a deadzone, the problem comes back.



  • @DleanJeans Thanks for your answer.

    • I can't use isOnScreen because I need to keep the assets from the right. I just need to replace assets when they are leaving the screen on the left.

    • My example with scrollFactor.set(0,1); was just to say that as soon as I set different values, the x position of my assets are wrong. They should start at 0, 1000, etc. but they start at -2860,-1860 and I don't know why.

    • Maybe FlxBackdrop can resolve my problem. Thanks



  • If you wanna look more into parallax, check this demo



  • @DleanJeans So FlxBackdrop solves my problem for repeated assets at least. Thanks :)
    But I still need to understand why Flixel is playing with my coordinates at start for other kind of parallax assets :)



  • I'm using Flixel 3.3.12 and there is definitely something wrong with FlxCamera.updateFollow() because I've got this traces in FlxCamera.update():

    	trace(scroll.x);//0 is OK
    	if (target != null)
    	{
    		updateFollow();
    	}
    	trace(scroll.x);// -1.#IND (wrong value)  
    

    So I'm currently looking if there was a bug which hopefully has been fixed in more recent Flixel release.



  • So I've fixed my issue by updating FlxCamera.updateFollow with last flixel code. I have now correct values when starting a parallax effect.


Log in to reply
 

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.