Open IQAndreas opened 10 years ago
Also, this would make it easy to add FollowStyles that only follow the target on the x
or y
axis.
This suggestion is amazing! It cleans up FlxCamera#follow()
code and allows the creation of fancy following patterns as you mentioned.
Maybe we could change follow()
to:
follow(Target:FlxBasic, FollowStyle:uint, FollowStyleClass:Class = FollowStyle)
That way the method is responsible for instantiating the requested follow style. The "official" styles could be implemented within the FollowStyle
class itself, e.g.:
class FollowStyle {
public static const STYLE_LOCKON:uint = 0;
public static const PLATFORMER :uint = 1;
(...)
public function FollowStyle(Style :uint) {
switch(Style) {
case STYLE_LOCKON: deadzone = new FlxRectangle();
(...)
}
}
}
Then in FlxCamera#follow()
:
public function follow(Target:FlxBasic, FollowStyle:uint, FollowStyleClass:Class = FollowStyle) :void {
target = Target;
followStyle = new FollowStyleClass(this, FollowStyle);
}
New follow styles can be easily created and used by developers e.g.
camera.follow(target, MyCustomFollowStyle.LOCKON, MyCustomFollowStyle);
class MyCustomFollowStyle extends FollowStyle {
(...)
}
This will allow you to create your own
FollowStyle
for the camera (perhaps you want it to pan easily whenever something moves instead of "jumping" immediately to the correct position?And if you want a custom deadzone, you would either extend the class, or call something like
camera.follow(target, new FollowStyle(cutomDeadzone));
.But primarily, it will use things like
FollowStyle.LOCKON
, and second, it will reduce the code inFlxCamera#follow()
to something like:Bleh, maybe it's just easier to show these proposed changes with actual code once we get to that point. This is probably the least clear suggestion I have written so far. :/