Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a bezier path tween. #46

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions com/stencyl/models/Actor.hx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import com.stencyl.models.GameModel;
import com.stencyl.utils.Utils;

import motion.Actuate;
import motion.MotionPath;
import motion.easing.Back;
import motion.easing.Cubic;
import motion.easing.Elastic;
Expand Down Expand Up @@ -3601,6 +3602,26 @@ class Actor extends Sprite
Actuate.tween(tweenLoc, duration, {x:x, y:y}).ease(easing).onComplete(onTweenPositionComplete);
}

//The actor will touch the control point
public function bezierPathMoveTo(destX:Float, destY:Float, controlX:Float, controlY:Float, duration:Float = 1, easing:Dynamic = null )
{
var x1 = getX(false);
var y1 = getY(false);
var tempX = Math.round(((x1 + destX) / 2));
var tempY = Math.round(((y1 + destY) / 2));
var tempCX = (tempX + ((cx - tempX) * 2));
var tempCY = (tempY + ((cy - tempY) * 2));
tweenLoc.x = getX(false);
tweenLoc.y = getY(false);
if(easing == null)
{
easing = Linear.easeNone;
}
activePositionTweens++;
var path = new MotionPath().bezier(destX, destY, tempCX, tempCY);
Actuate.motionPath(tweenLoc,duration,{x:path.x,y:path.y}).ease(easing).onComplete(onTweenPositionComplete);
}

//In degrees
public function spinBy(angle:Float, duration:Float = 1, easing:Dynamic = null)
{
Expand Down