- 
                Notifications
    You must be signed in to change notification settings 
- Fork 357
Demo of Slide
        marcel euchner-martinez edited this page Jul 9, 2022 
        ·
        3 revisions
      
    This is a short demo of how slide can be implemented in Heaps.
Slide is described as a framework agnostic tweening library. In the sample below we use it
to give our h2d.Object (a h2d.Graphics finally) a predefined path to move along.
Slide can be installed with:
haxelib install slide
or
haxelib git slide https://github.com/AndreiRudenko/slide.git

import slide.Slide;
class SlideLibDemo extends hxd.App {
    static function main() { new SlideLibDemo(); }
    override function init() {
        var g = new h2d.Graphics( s2d );
        g.beginFill( 0xFFFFFF );
        g.drawRect( 0, 0, 50, 50 );
        g.setPosition(60,60);
        var foo = ()->{ trace("Cycle accomplished!"); };
        var fin = ()->{ trace("Slide finished."); };
        Slide.tween( g )
            .to({x:400}, 1.5)
            .to({y:300}, 1  )
            .wait(0.5)
            .to({x:60,y:60}, 0.5)
            .ease(slide.easing.Quad.easeIn)
            .call( (o)->{ foo(); trace(o,o.x,o.y); o.rotate(0.3); } )
            .onComplete( fin )
            .repeat(-1) // -1 = infinity (actually prevents function fin to be called here)
            .start();
    }
    override function update(dt:Float) {
        Slide.step(dt); // tell Slide how many seconds have elapsed
    }
}Note that in the end we pass our update method's dt parameter on to Slide, thus the latter knows how many time has passed and can adapt it's tweens accordingly.
-lib heaps
-lib hlsdl
-lib slide
-main SlideLibDemo
-hl slide_demo.hl