Tween a camera's angle with FlxTween.tween
Vs FlxTween.angle
#4135
-
I'm not sure if it's a bug or a syntax error on my end but trying to tween the angle a camera with import funkin.play.PlayState;
import funkin.Conductor;
import funkin.modding.events.ScriptEvent;
import funkin.modding.module.Module;
import funkin.ui.AtlasText;
import flixel.FlxG;
import flixel.tweens.FlxTween;
import flixel.util.FlxTimer;
import flixel.tweens.FlxEase;
import flixel.FlxCamera;
import funkin.graphics.FunkinSprite;
import funkin.Paths;
import openfl.utils.Assets;
import funkin.util.ReflectUtil;
import funkin.play.event.SongEvent;
import funkin.data.event.SongEventSchema;
import funkin.modding.PolymodErrorHandler;
// import funkin.modding.module.ModuleHandler;
class CameraRotateEvent extends SongEvent {
function new() {
super("cameraRotateEvent", 2);
}
public var DEFAULT_ANGLE:Float = 45.0;
public var DEFAULT_DURATION:Float = 4.0;
public var DEFAULT_EASE:String = 'linear';
public var cameraTween:FlxTween = null;
override function handleEvent(data):Void {
if (PlayState.instance == null || PlayState.instance.currentStage == null) return;
// PlayState.instance.camGame.angle = 45;
// Does nothing if in minimal mode.
if (PlayState.instance.isMinimalMode) return;
var duration:Float = data.getFloat('duration') != null ? data.getFloat('duration') : DEFAULT_DURATION;
var toAngle:Float = data.getFloat('angle') != null ? data.getFloat('angle') : DEFAULT_ANGLE;
var ease:String = data.getString('ease') != null ? data.getString('ease') : DEFAULT_EASE;
var easeFunction:Null<Float->Float>;
var durSeconds = Conductor.instance.stepLengthMs * duration / 1000;
switch (ease) {
case 'INSTANT':
// Cancel the tween here, so it doesn't tween (haven't tested it yet)
// if (cameraTween != null) cameraTween.cancel();
PlayState.instance.camGame.angle = toAngle;
return;
default:
// var easeFunction:Null<Float->Float> = ReflectUtil.getAnonymousField(FlxEase, ease);
easeFunction = ReflectUtil.getAnonymousField(FlxEase, ease);
if (easeFunction == null){
trace("Invalid easing function: " + ease);
return;
}
rotateCamGame(toAngle, durSeconds, easeFunction);
}
trace("Angle: " + toAngle + " | Duration: " + duration + " | Easing: " + ease + " | Ease Function: " + easeFunction);
}
public function rotateCamGame(?toAngle:Float, ?duration:Float, ?ease:Null<Float->Float>):Void {
cancelCameraRotateTween();
// cameraTween = FlxTween.angle(PlayState.instance.camGame, PlayState.instance.camGame.angle, toAngle, duration, {ease: ease}, function(tween:FlxTween){
// trace("Tween done!\ncamGame angle: " + PlayState.instance.camGame.angle);
// });
cameraTween = FlxTween.tween(PlayState.instance.camGame, {angle: toAngle}, duration, {ease: ease});
}
public function cancelCameraRotateTween(){
if (cameraTween != null){
cameraTween.cancel();
}
}
public override function getTitle() {
return 'Camera Rotate';
}
override function getEventSchema()
{
return [
{
name: 'angle',
title: 'angle',
defaultValue: 45.0,
step: 0.5,
type: "float",
units: 'degrees'
},
{
name: 'duration',
title: 'Duration',
defaultValue: 4.0,
step: 0.5,
type: "float",
units: 'steps'
},
{
name: 'ease',
title: 'Easing Type',
defaultValue: 'linear',
type: "enum",
keys: [
'Linear' => 'linear',
'Instant (Ignores Duration)' => 'INSTANT',
'Sine In' => 'sineIn',
'Sine Out' => 'sineOut',
'Sine In/Out' => 'sineInOut',
'Quad In' => 'quadIn',
'Quad Out' => 'quadOut',
'Quad In/Out' => 'quadInOut',
'Cube In' => 'cubeIn',
'Cube Out' => 'cubeOut',
'Cube In/Out' => 'cubeInOut',
'Quart In' => 'quartIn',
'Quart Out' => 'quartOut',
'Quart In/Out' => 'quartInOut',
'Quint In' => 'quintIn',
'Quint Out' => 'quintOut',
'Quint In/Out' => 'quintInOut',
'Expo In' => 'expoIn',
'Expo Out' => 'expoOut',
'Expo In/Out' => 'expoInOut',
'Smooth Step In' => 'smoothStepIn',
'Smooth Step Out' => 'smoothStepOut',
'Smooth Step In/Out' => 'smoothStepInOut',
'Elastic In' => 'elasticIn',
'Elastic Out' => 'elasticOut',
'Elastic In/Out' => 'elasticInOut'
]
}
];
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
KoloInDaCrib
Feb 13, 2025
Replies: 1 comment 3 replies
-
THe HaxeFlixel API points that FlxTween.angle only expects a FlxSprite as an argument. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FlxBasic does not have an angle property in it, which is why FlxSprites are used as the first argument
Think of it like a tree, the root of the tree is FlxBasic and FlxSprite and FlxCamera are it's branches, all of them having different characteristics in form of properties. Just because two branches have similar characteristics does not necessarily mean that one is a descendant from the other or that they are the same. You also cannot expect that, just because these two branches have the same predecessor, they are the same.
The
angle
of FlxCamera's is a different one than theangle
of FlxSprites, even if they have the same name. Therefore, FlxTween.angle, which normally expects an FlxSpr…