KLowe
KLowe

Reputation: 483

Error setting scrollFactor on FlxSprite after update to HaxeFlixel 3.3.0

I just finished updating my HaxeFlixel install to 3.3.0 and after ironing out all the other upgrade changes I am still getting one error I can't find any explanation for. I am setting the scrollFactor property on the FlxSprites that make up my background elements, and had no problem with it before 3.3.0. I can't seem to find any references to that property changing with the update.

Here is the relevant code where I am setting the property:

//Setup bg
var bg:FlxSprite;
var scrollFactor:FlxPoint;
for (i in 0...loader.bgArray.length){
    bg = new FlxSprite(0, 0, loader.bgArray[i][0]);
    scrollFactor = new FlxPoint(
        Std.parseFloat(loader.bgArray[i][1]),
        Std.parseFloat(loader.bgArray[i][2]));
    bg.scrollFactor = scrollFactor;
    add(bg);
}

Here is my output from haxelib list:

flixel: [3.3.0]
hxcpp: [3.1.30]
lime-tools: [1.4.0]
lime: [0.9.7]
openfl-html5: [1.4.0-beta]
openfl-native: [1.4.0]
openfl-samples: [1.3.0]
openfl: [1.4.0]

When I run lime test flash in my project folder with the above snippet I get:

source/PlayState.hx:54: characters 3-33 : Cannot access field or identifier scrollFactor for writing

Line 54 is the one where I am setting bg.scrollFactor.

Upvotes: 0

Views: 450

Answers (1)

stroncium
stroncium

Reputation: 1430

I'm not sure about notices about this update, but indeed the current situation is that scrollFactor accessors are (default, null), so there is no chance you could set it up like that.

It also isn't even the most proper way to do that, since in HaxeFlixel FlxPoints could and mostly should be pooled, so you would usually use not new FlxPoint(x, y), but FlxPoint.get(x, y) which will make your code run much faster.

Anyhow, down to your current situation, just use

bg.scrollFactor.set(
  Std.parseFloat(loader.bgArray[i][1]),
  Std.parseFloat(loader.bgArray[i][2])
);

instead of

scrollFactor = new FlxPoint(
  Std.parseFloat(loader.bgArray[i][1]),
  Std.parseFloat(loader.bgArray[i][2])
);
bg.scrollFactor = scrollFactor;

and it will work perfectly (and faster).

Upvotes: 3

Related Questions