I there !
Playing with scrolling, I meet a strange behavior : scrollRect works great on Neko/Html5/C++, but not on Flash target !
I tried applying it on the Main sprite, and on a “scene” child sprite, and had the same result.
Works perfect on Neko/Html5/C++, not at all on Flash - no effect at all.
Here is a sample of my Camera class :
class Camera extends Rectangle {
public static var scene:Sprite;
public function new(scene_:Sprite){ // triggered by Engine.new()
super(0, 0, Lib.width, Lib.height);
scene = scene_;
// hop ceci devient le viewport !
scene.scrollRect = this;
}
public function setPosition(){}
public function moveBy(x_:Float, y_:Float=0){
x += x_; y += y_;
for (i in 0 ... fixedSprites.length) {
if(fixedSprites[i] != null) fixedSprites[i].moveBy(x_, y_);
}
}
}
On Flash it’s kind of fun, my fixed children Sprites go right slowly, while the viewport doesn’t change at all.
You may watch it happen here : Flash Html5 (works as wanted)
I’m glad it works fine with Html5, though, it has been a serious issue with HaxePunk on a previous project, that’s why I’m building my tools with openfl directly.
It’s kind of fun to meet that kind of issue on the historical target of OpenFL !
Hmm, Flash scroll rects are sort of funny, I’m trying to think if there’s a good way to make it behave. It uses Adobe’s implementation, so it really isn’t something we have any control over
public function moveBy(x_:Float, y_:Float=0){
x += x_; y += y_;
for (i in 0 ... fixedSprites.length) {
if(fixedSprites[i] != null) fixedSprites[i].moveBy(x_, y_);
}
#if flash
scene.scrollRect = this;
#end
}
When you set scene.scrollRect = this, Flash makes a copy of your Rectangle object. It remembers this copy instead of yours, so that changing yours won’t change Flash’s. If you stop calling scene.scrollRect = this, the scroll rectangle will stay where it is.
There’s probably a reason for this. Perhaps the DisplayObject needs to be notified when there’s a change so that it can be redrawn. Or maybe it’s just to annoy you; I wouldn’t know.
on enter frame would work on every target, as I would address the flash copy of my rectangle object…
But nope, flash doesn’t seem to remember it (Neko and Html5 do).
But it’s fine with tour hack, so I’ll go with it !
@player_03 don’t worry, I’m not questionning what you said, and your solution works perfectly
I just felt I could be smart and find a more elegant fix by myself…
But nope !
The process you describe is surprising, I can’t see why Flash would do that… but there’s more important : your fix works !
Thanks for that, and for your explanation.