flixel icon indicating copy to clipboard operation
flixel copied to clipboard

Investigate replacing Reflection with macros where possible (FlxTween, FlxBar, FlxSlider...)

Open Gama11 opened this issue 10 years ago • 6 comments

This would be a lot faster than the current VarTweens that use Reflection and more convenient than NumTweens with callbacks (probably also faster since callback functions are not typed statically), basically the perfect solution if we can get it to work. Tweens in tinkerbell seem to do this.

Also, tweening properties does not work on js. Using a macro would potentially allow us to work around that problem and generate tweens that call the setter function.

Gama11 avatar May 07 '14 09:05 Gama11

Cool idea!

kevinresol avatar May 08 '14 14:05 kevinresol

The same can go for FlxBar and FlxSlider. It gets a bit trickier when it comes to watching values with these, though. The current technique for watching can cause a single frame delay in many cases.

JoeCreates avatar May 15 '14 18:05 JoeCreates

@Gama11 did you get anywhere with this?

I wonder how a VarTween with e.g. 3 properties ( ~ x, y, alpha ) performs vs 3 separate num Tweens.

Also used the setter functions on NumTweens - would be nice if this would be detected on compile time so otherwise useless Float setters wouldn't have to be added in the code, and the Tween Function Callback could be simply the Float itself.

mastef avatar Nov 21 '16 16:11 mastef

Also Vartweens could detect on new() through Reflection what types it's bound to, so it could either switch over to Numtweens, or call the proper methods instead of using Reflection api. That could be interesting, too

mastef avatar Nov 21 '16 16:11 mastef

Just an update. I've made working tweens for Lycan with macros and no reflection or dynamics. It would change the Flixel api a lot to do something similar, but would ultimately make it more convenient as well as more performant.

// There is no need for tweens to have a target, so you can target any number of objects
// with a single tween. The tween function simply uses any field access expression. Even locals work.

var myLocal:Float = 0;
FlxTween.tween([player.x => 10, player.scale.x => 2, ob.x => 50, myLocal=> 1], 2)

// Or even compounding fields for the same objects...

FlxTween.tween([player => [x => 100, y => 100, scale => [x => 2, y => 2]]], 2)

// "a...b" means "tweens from a to b", allowing you to easily specify start values

FlxTween.tween([player.x => 100...200]);

// Last but not least, we are not restricted to only tweening fields. We can also tween methods...
FlxTween.tween([player.scale.set(1...2, 1...2)]);

JoeCreates avatar Jun 22 '17 05:06 JoeCreates

That looks really nice! Wouldn't even have to be a breaking change if tween() is kept and the macro version has a different name.

Gama11 avatar Jun 22 '17 06:06 Gama11