From 58bfba6c1e4a75523f76b8f73195f15a84ea7ec3 Mon Sep 17 00:00:00 2001 From: 47rooks <47rooks@gmail.com> Date: Fri, 15 Dec 2023 08:39:15 -0800 Subject: [PATCH 1/6] Fix FlxSpriteGroup origin (#2981) * update children origins relative to their positions * add originTransform unit test --- flixel/group/FlxSpriteGroup.hx | 2 +- .../src/flixel/group/FlxSpriteGroupTest.hx | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/flixel/group/FlxSpriteGroup.hx b/flixel/group/FlxSpriteGroup.hx index 4f0c1b4955..26914d4d54 100644 --- a/flixel/group/FlxSpriteGroup.hx +++ b/flixel/group/FlxSpriteGroup.hx @@ -1057,7 +1057,7 @@ class FlxTypedSpriteGroup extends FlxSprite Sprite.offset.copyFrom(Offset); inline function originTransform(Sprite:FlxSprite, Origin:FlxPoint) - Sprite.origin.copyFrom(Origin); + Sprite.origin.set(x + origin.x - Sprite.x, y + origin.y - Sprite.y); inline function scaleTransform(Sprite:FlxSprite, Scale:FlxPoint) Sprite.scale.copyFrom(Scale); diff --git a/tests/unit/src/flixel/group/FlxSpriteGroupTest.hx b/tests/unit/src/flixel/group/FlxSpriteGroupTest.hx index 9218668a9e..744a07baf4 100644 --- a/tests/unit/src/flixel/group/FlxSpriteGroupTest.hx +++ b/tests/unit/src/flixel/group/FlxSpriteGroupTest.hx @@ -137,6 +137,33 @@ class FlxSpriteGroupTest extends FlxTest Assert.isFalse(member2.revived); return group; } + @Test + /** + * Ensure that member origins are correctly set when + * the group origin is set. + */ + function testOriginTransform() + { + var f1 = new FlxSprite(-10, 100); + var f2 = new FlxSprite(50, 50); + group.add(f1); + group.add(f2); + + group.setPosition(280, 300); + group.origin.set(300, 400); + + // Verify positions are updated - absolute + Assert.areEqual(270, f1.x); + Assert.areEqual(400, f1.y); + Assert.areEqual(330, f2.x); + Assert.areEqual(350, f2.y); + + // Verify origins are correct - relative + Assert.areEqual(310, f1.origin.x); + Assert.areEqual(300, f1.origin.y); + Assert.areEqual(250, f2.origin.x); + Assert.areEqual(350, f2.origin.y); + } } class Member extends FlxSprite From c07122d6b9d9934e0d957517950d8e74587ff470 Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Fri, 15 Dec 2023 11:07:48 -0600 Subject: [PATCH 2/6] Better framerate independant camera lerping (#2922) * adjust lerp based on the current frame rate * better framerate independant camera lerping * fix error * remove setter * docs * fix default lerp in follow() * fix typo --- flixel/FlxCamera.hx | 54 +++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index acf179f8a4..542ec606ee 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -126,12 +126,12 @@ class FlxCamera extends FlxBasic public var targetOffset(default, null):FlxPoint = FlxPoint.get(); /** - * Used to smoothly track the camera as it follows: - * The percent of the distance to the follow `target` the camera moves per 1/60 sec. - * Values are bounded between `0.0` and `60 / FlxG.updateFramerate` for consistency across framerates. - * The maximum value means no camera easing. A value of `0` means the camera does not move. + * The ratio of the distance to the follow `target` the camera moves per 1/60 sec. + * Valid values range from `0.0` to `1.0`. `1.0` means the camera always snaps to its target + * position. `0.5` means the camera always travels halfway to the target position, `0.0` means + * the camera does not move. Generally, the lower the value, the more smooth. */ - public var followLerp(default, set):Float = 60 / FlxG.updateFramerate; + public var followLerp:Float = 1.0; /** * You can assign a "dead zone" to the camera in order to better control its movement. @@ -1147,6 +1147,7 @@ class FlxCamera extends FlxBasic if (target != null) { updateFollow(); + updateLerp(elapsed); } updateScroll(); @@ -1194,7 +1195,7 @@ class FlxCamera extends FlxBasic * Updates camera's scroll. * Called every frame by camera's `update()` method (if camera's `target` isn't `null`). */ - public function updateFollow():Void + function updateFollow():Void { // Either follow the object closely, // or double check our deadzone and update accordingly. @@ -1271,15 +1272,21 @@ class FlxCamera extends FlxBasic _lastTargetPosition.y = target.y; } } - - if (followLerp >= 60 / FlxG.updateFramerate) + } + + function updateLerp(elapsed:Float) + { + final boundLerp = FlxMath.bound(followLerp, 0, 1); + // Adjust lerp based on the current frame rate so lerp is less framerate dependant + final adjustedLerp = 1.0 - Math.pow(1.0 - boundLerp, elapsed * 60); + if (adjustedLerp >= 1) { scroll.copyFrom(_scrollTarget); // no easing } else { - scroll.x += (_scrollTarget.x - scroll.x) * followLerp * (60 / FlxG.updateFramerate); - scroll.y += (_scrollTarget.y - scroll.y) * followLerp * (60 / FlxG.updateFramerate); + scroll.x += (_scrollTarget.x - scroll.x) * adjustedLerp; + scroll.y += (_scrollTarget.y - scroll.y) * adjustedLerp; } } @@ -1456,29 +1463,23 @@ class FlxCamera extends FlxBasic /** * Tells this camera object what `FlxObject` to track. * - * @param Target The object you want the camera to track. Set to `null` to not follow anything. - * @param Style Leverage one of the existing "deadzone" presets. Default is `LOCKON`. + * @param target The object you want the camera to track. Set to `null` to not follow anything. + * @param style Leverage one of the existing "deadzone" presets. Default is `LOCKON`. * If you use a custom deadzone, ignore this parameter and * manually specify the deadzone after calling `follow()`. - * @param Lerp How much lag the camera should have (can help smooth out the camera movement). + * @param lerp How much lag the camera should have (can help smooth out the camera movement). */ - public function follow(Target:FlxObject, ?Style:FlxCameraFollowStyle, ?Lerp:Float):Void + public function follow(target:FlxObject, style = LOCKON, lerp = 1.0):Void { - if (Style == null) - Style = LOCKON; - - if (Lerp == null) - Lerp = 60 / FlxG.updateFramerate; - - style = Style; - target = Target; - followLerp = Lerp; + this.style = style; + this.target = target; + followLerp = lerp; var helper:Float; var w:Float = 0; var h:Float = 0; _lastTargetPosition = null; - switch (Style) + switch (style) { case LOCKON: if (target != null) @@ -1925,11 +1926,6 @@ class FlxCamera extends FlxBasic return contained; } - function set_followLerp(Value:Float):Float - { - return followLerp = FlxMath.bound(Value, 0, 60 / FlxG.updateFramerate); - } - function set_width(Value:Int):Int { if (width != Value && Value > 0) From 13bb9ab5213cf32aa0d045b74bf387b8e92a9278 Mon Sep 17 00:00:00 2001 From: George FunBook Date: Fri, 15 Dec 2023 14:33:28 -0600 Subject: [PATCH 3/6] add #2981 and #2922 --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3043d1a132..9179ef1edb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +6.0.0 (TBD) +#### Changes and improvements: +- `FlxSpritegroup`: Setting `origin` now causes members to pivot around the same point ([#2981](https://github.com/HaxeFlixel/flixel/pull/2981)) +- `FlxCamera`: Smoother camera lerping, particularly with non-fixed timesteps ([#2922](https://github.com/HaxeFlixel/flixel/pull/2922)) + 5.6.0 (TBD) #### New features: From 1d3d529e2c3bb1038b8625000cf4c58493ce2b9c Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Fri, 5 Jan 2024 17:43:51 -0600 Subject: [PATCH 4/6] Flxstate new (#2733) * take FlxState constructor instead of FlxState * add NextState type * 4.0.5 fixes * more 4.0.5 fixes * fix deprecation warnings in unit tests * take nextState in VCRFrontEnd * remove @from Instance in InitialState * use is operator * improve docs * rename method * more docs * more modular FlxSplash, set _gameJustStarted in FlxGame * allow splash to be skipped by a switchState call --- flixel/FlxG.hx | 41 +++---------- flixel/FlxGame.hx | 18 +++--- flixel/FlxState.hx | 20 +----- flixel/util/typeLimit/NextState.hx | 26 ++------ tests/unit/src/TestMain.hx | 2 +- tests/unit/src/flixel/FlxCameraTest.hx | 2 +- tests/unit/src/flixel/FlxObjectTest.hx | 2 +- tests/unit/src/flixel/FlxStateTest.hx | 61 ++++--------------- tests/unit/src/flixel/FlxSubStateTest.hx | 24 +++++--- .../src/flixel/system/replay/FlxReplayTest.hx | 5 +- 10 files changed, 54 insertions(+), 147 deletions(-) diff --git a/flixel/FlxG.hx b/flixel/FlxG.hx index 37e3b5e4d6..6ddbe8f81d 100644 --- a/flixel/FlxG.hx +++ b/flixel/FlxG.hx @@ -377,34 +377,13 @@ class FlxG public static inline function switchState(nextState:NextState):Void { final stateOnCall = FlxG.state; - - if (!nextState.isInstance() || canSwitchTo(cast nextState)) + state.startOutro(function() { - state.startOutro(function() - { - if (FlxG.state == stateOnCall) - game._nextState = nextState; - else - FlxG.log.warn("`onOutroComplete` was called after the state was switched. This will be ignored"); - }); - } - } - - /** - * Calls state.switchTo(nextState) without a deprecation warning. - * This will be removed in Flixel 6.0.0 - * @since 5.6.0 - */ - @:noCompletion - @:haxe.warning("-WDeprecated") - static function canSwitchTo(nextState:FlxState) - { - #if (haxe < version("4.3.0")) - // Use reflection because @:haxe.warning("-WDeprecated") doesn't work until haxe 4.3 - return Reflect.callMethod(state, Reflect.field(state, 'switchTo'), [nextState]); - #else - return state.switchTo(nextState); - #end + if (FlxG.state == stateOnCall) + game._nextState = nextState; + else + FlxG.log.warn("`onOutroComplete` was called after the state was switched. This will be ignored"); + }); } /** @@ -413,13 +392,7 @@ class FlxG */ public static inline function resetState():Void { - if (state == null || state._constructor == null) - FlxG.log.error("FlxG.resetState was called while switching states"); - else if(!state._constructor.isInstance()) - switchState(state._constructor); - else - // create new instance here so that state.switchTo is called (for backwards compatibility) - switchState(Type.createInstance(Type.getClass(state), [])); + switchState(state._constructor); } /** diff --git a/flixel/FlxGame.hx b/flixel/FlxGame.hx index 572958f885..912ed232bb 100644 --- a/flixel/FlxGame.hx +++ b/flixel/FlxGame.hx @@ -253,7 +253,8 @@ class FlxGame extends Sprite * [`scaleMode`](https://api.haxeflixel.com/flixel/system/scaleModes/index.html) * will determine the actual display size of the game. * @param initialState A constructor for the initial state, ex: `PlayState.new` or `()->new PlayState()`. - * Note: Also allows `Class` for backwards compatibility. + * Note: Before Flixel 6, this took a `Class`, this has been + * deprecated, but is still available, for backwards compatibility. * @param updateFramerate How frequently the game should update. Default is 60 fps. * @param drawFramerate Sets the actual display / draw framerate for the game. Default is 60 fps. * @param skipSplash Whether you want to skip the flixel splash screen with `FLX_NO_DEBUG`. @@ -628,7 +629,7 @@ class FlxGame extends Sprite // Finally assign and create the new state _state = _nextState.createInstance(); - _state._constructor = _nextState; + _state._constructor = _nextState.getConstructor(); _nextState = null; if (_gameJustStarted) @@ -639,7 +640,10 @@ class FlxGame extends Sprite _state.create(); if (_gameJustStarted) - gameStart(); + { + FlxG.signals.postGameStart.dispatch(); + _gameJustStarted = false; + } #if FLX_DEBUG debugger.console.registerObject("state", _state); @@ -648,12 +652,6 @@ class FlxGame extends Sprite FlxG.signals.postStateSwitch.dispatch(); } - function gameStart():Void - { - FlxG.signals.postGameStart.dispatch(); - _gameJustStarted = false; - } - /** * This is the main game update logic section. * The `onEnterFrame()` handler is in charge of calling this @@ -904,4 +902,4 @@ private class FlxIntroSplash extends FlxSplash FlxG.game._gameJustStarted = true; super.startOutro(onOutroComplete); } -} \ No newline at end of file +} diff --git a/flixel/FlxState.hx b/flixel/FlxState.hx index 24051dad25..3691071d39 100644 --- a/flixel/FlxState.hx +++ b/flixel/FlxState.hx @@ -11,10 +11,6 @@ import flixel.util.typeLimit.NextState; * It is for all intents and purpose a fancy `FlxGroup`. And really, it's not even that fancy. */ @:keepSub // workaround for HaxeFoundation/haxe#3749 -#if FLX_NO_UNIT_TEST -@:autoBuild(flixel.system.macros.FlxMacroUtil.deprecateOverride("switchTo", "switchTo is deprecated, use startOutro")) -#end -// show deprecation warning when `switchTo` is overriden in dereived classes class FlxState extends FlxGroup { /** @@ -52,7 +48,7 @@ class FlxState extends FlxGroup */ @:allow(flixel.FlxGame) @:allow(flixel.FlxG) - var _constructor:NextState; + var _constructor:()->FlxState; /** * Current substate. Substates also can be nested. @@ -105,7 +101,7 @@ class FlxState extends FlxGroup */ public function create():Void {} - override public function draw():Void + override function draw():Void { if (persistentDraw || subState == null) super.draw(); @@ -186,18 +182,6 @@ class FlxState extends FlxGroup super.destroy(); } - /** - * Called from `FlxG.switchState()`. If `false` is returned, the state - * switch is cancelled - the default implementation returns `true`. - * - * Useful for customizing state switches, e.g. for transition effects. - */ - @:deprecated("switchTo is deprecated, use startOutro") - public function switchTo(nextState:FlxState):Bool - { - return true; - } - /** * Called from `FlxG.switchState()`, when `onOutroComplete` is called, the actual state * switching will happen. diff --git a/flixel/util/typeLimit/NextState.hx b/flixel/util/typeLimit/NextState.hx index d563541526..31825e809a 100644 --- a/flixel/util/typeLimit/NextState.hx +++ b/flixel/util/typeLimit/NextState.hx @@ -35,7 +35,7 @@ import flixel.FlxState; abstract NextState(Dynamic) { @:from - // @:deprecated("use `MyState.new` or `()->new MyState()` instead of `new MyState()`)") // wait until 6.0.0 + @:deprecated("use `MyState.new` or `()->new MyState()` instead of `new MyState()`)") public static function fromState(state:FlxState):NextState { return cast state; @@ -47,23 +47,11 @@ abstract NextState(Dynamic) return cast func; } - @:allow(flixel.FlxG) - inline function isInstance():Bool - { - return this is FlxState; - } - - @:allow(flixel.FlxG) - inline function isClass():Bool - { - return this is Class; - } - public function createInstance():FlxState { - if (isInstance()) + if (this is FlxState) return cast this; - else if (isClass()) + else if (this is Class) return Type.createInstance(this, []); else return cast this(); @@ -71,18 +59,13 @@ abstract NextState(Dynamic) public function getConstructor():()->FlxState { - if (isInstance()) + if (this is FlxState) { return function ():FlxState { return cast Type.createInstance(Type.getClass(this), []); } } - else if (isClass()) - return function ():FlxState - { - return cast Type.createInstance(this, []); - } else return cast this; } @@ -144,3 +127,4 @@ abstract InitialState(Dynamic) to NextState return cast this; } } + diff --git a/tests/unit/src/TestMain.hx b/tests/unit/src/TestMain.hx index bc092e7186..5a4936b3d2 100644 --- a/tests/unit/src/TestMain.hx +++ b/tests/unit/src/TestMain.hx @@ -21,7 +21,7 @@ class TestMain public function new() { // Flixel was not designed for unit testing so we can only have one instance for now. - Lib.current.stage.addChild(new FlxGame(640, 480, FlxState, 60, 60, true)); + Lib.current.stage.addChild(new FlxGame(640, 480, FlxState.new, 60, 60, true)); var suites = new Array>(); suites.push(TestSuite); diff --git a/tests/unit/src/flixel/FlxCameraTest.hx b/tests/unit/src/flixel/FlxCameraTest.hx index 62eeb63819..85459f6094 100644 --- a/tests/unit/src/flixel/FlxCameraTest.hx +++ b/tests/unit/src/flixel/FlxCameraTest.hx @@ -47,7 +47,7 @@ class FlxCameraTest extends FlxTest function testDefaultCamerasStateSwitch():Void { FlxCamera._defaultCameras = [FlxG.camera]; - switchState(new FlxState()); + switchState(FlxState.new); Assert.areEqual(FlxG.cameras.defaults, FlxCamera._defaultCameras); } diff --git a/tests/unit/src/flixel/FlxObjectTest.hx b/tests/unit/src/flixel/FlxObjectTest.hx index 292048bba0..69f3fafa70 100644 --- a/tests/unit/src/flixel/FlxObjectTest.hx +++ b/tests/unit/src/flixel/FlxObjectTest.hx @@ -159,7 +159,7 @@ class FlxObjectTest extends FlxTest function velocityCollidingWith(ground:FlxObject) { - switchState(new CollisionState()); + switchState(CollisionState.new); ground.setPosition(0, 10); object1.setSize(10, 10); diff --git a/tests/unit/src/flixel/FlxStateTest.hx b/tests/unit/src/flixel/FlxStateTest.hx index 0bf2d46a0d..5f81512a98 100644 --- a/tests/unit/src/flixel/FlxStateTest.hx +++ b/tests/unit/src/flixel/FlxStateTest.hx @@ -16,15 +16,6 @@ class FlxStateTest extends FlxTest @Ignore // TODO: investigate function testSwitchState() { - final state = new FlxState(); - - Assert.areNotEqual(state, FlxG.state); - switchState(state); - Assert.areEqual(state, FlxG.state); - - // Make sure this compiles - switchState(FlxState.new); - var nextState:FlxState = null; function createState() { @@ -37,19 +28,20 @@ class FlxStateTest extends FlxTest } @Test - function testResetStateInstance() + @:haxe.warning("-WDeprecated") + function testResetStateLegacy() { - var state = new TestState(); - switchState(state); + switchState(TestState.new); + var state = FlxG.state; Assert.areEqual(state, FlxG.state); resetState(); Assert.areNotEqual(state, FlxG.state); - Assert.isTrue((FlxG.state is TestState)); + Assert.isTrue(FlxG.state is TestState); } @Test - function testResetStateFunction() + function testResetState() { var nextState:TestState = null; function createState() @@ -68,28 +60,11 @@ class FlxStateTest extends FlxTest } @Test // #1676 - function testCancelStateSwitchInstance() - { - var finalState = new FinalStateLegacy(); - switchState(finalState); - Assert.areEqual(finalState, FlxG.state); - - switchState(new FlxState()); - Assert.areEqual(finalState, FlxG.state); - - resetState(); - Assert.areEqual(finalState, FlxG.state); - } - - @Test // #1676 - function testCancelStateSwitchFunction() + function testCancelStateSwitch() { switchState(FinalState.new); final finalState = FlxG.state; - switchState(new FlxState()); - Assert.areEqual(finalState, FlxG.state); - switchState(FlxState.new); Assert.areEqual(finalState, FlxG.state); @@ -100,27 +75,15 @@ class FlxStateTest extends FlxTest @Test function testOutro() { - var outroState = new OutroState(); - - FlxG.switchState(outroState); + FlxG.switchState(OutroState.new); step(); - Assert.areEqual(outroState, FlxG.state); + Assert.isType(FlxG.state, OutroState); - FlxG.switchState(new FlxState()); + FlxG.switchState(FlxState.new); step(); - Assert.areEqual(outroState, FlxG.state); + Assert.isType(FlxG.state, OutroState); step(); - Assert.areNotEqual(outroState, FlxG.state); - - } -} - -class FinalStateLegacy extends FlxState -{ - /* prevents state switches */ - override function switchTo(state) - { - return false; + Assert.isNotType(FlxG.state, OutroState); } } diff --git a/tests/unit/src/flixel/FlxSubStateTest.hx b/tests/unit/src/flixel/FlxSubStateTest.hx index af0389574a..acc26c9a96 100644 --- a/tests/unit/src/flixel/FlxSubStateTest.hx +++ b/tests/unit/src/flixel/FlxSubStateTest.hx @@ -41,28 +41,25 @@ class FlxSubStateTest extends FlxTest @Test // #1971 function testOpenPersistentSubStateFromNewParent() { - var state1 = new FlxState(); - var state2 = new FlxState(); - state1.destroySubStates = false; - FlxG.switchState(state1); + FlxG.switchState(FlxStateNoDestroySubState.new.bind(false)); step(); FlxG.state.openSubState(subState1); step(); - Assert.areEqual(state1.subState, subState1); + Assert.areEqual(FlxG.state.subState, subState1); subState1.close(); step(); - Assert.isNull(state1.subState); + Assert.isNull(FlxG.state.subState); - FlxG.switchState(state2); + FlxG.switchState(FlxStateNoDestroySubState.new.bind(true)); step(); FlxG.state.openSubState(subState1); step(); - Assert.areEqual(state2.subState, subState1); + Assert.areEqual(FlxG.state.subState, subState1); subState1.close(); step(); - Assert.isNull(state2.subState); + Assert.isNull(FlxG.state.subState); } @Test // #2023 @@ -87,3 +84,12 @@ class FlxSubStateTest extends FlxTest Assert.isTrue(closed); } } + +class FlxStateNoDestroySubState extends FlxState +{ + public function new (destroySubStates) + { + super(); + this.destroySubStates = destroySubStates; + } +} \ No newline at end of file diff --git a/tests/unit/src/flixel/system/replay/FlxReplayTest.hx b/tests/unit/src/flixel/system/replay/FlxReplayTest.hx index 85a6d564a5..84212a11d1 100644 --- a/tests/unit/src/flixel/system/replay/FlxReplayTest.hx +++ b/tests/unit/src/flixel/system/replay/FlxReplayTest.hx @@ -90,12 +90,11 @@ class FlxReplayTest extends FlxTest createFrameRecord(3, JUST_RELEASED) ]; var recording = frames.map(function(r) return r.save()).join("\n"); - var state = new ReplayState(); - FlxG.vcr.loadReplay(recording, state); + FlxG.vcr.loadReplay(recording, ReplayState.new); step(10); - Assert.isTrue(state.called); + Assert.isTrue((cast FlxG.state:ReplayState).called); } function createFrameRecord(i:Int, mouseState:FlxInputState):FrameRecord From b03dbacafcbb7164ea01afb0f2af137485c51a41 Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Sun, 7 Jan 2024 18:57:17 -0600 Subject: [PATCH 5/6] touch-ups for #2733 (#3003) * take FlxState constructor instead of FlxState * add NextState type * 4.0.5 fixes * more 4.0.5 fixes * fix deprecation warnings in unit tests * take nextState in VCRFrontEnd * remove @from Instance in InitialState * use is operator * improve docs * rename method * more docs * more modular FlxSplash, set _gameJustStarted in FlxGame * allow splash to be skipped by a switchState call * touch-ups --- flixel/FlxGame.hx | 13 ++++++++----- flixel/util/typeLimit/NextState.hx | 5 ++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/flixel/FlxGame.hx b/flixel/FlxGame.hx index 912ed232bb..d49f7640db 100644 --- a/flixel/FlxGame.hx +++ b/flixel/FlxGame.hx @@ -640,10 +640,7 @@ class FlxGame extends Sprite _state.create(); if (_gameJustStarted) - { - FlxG.signals.postGameStart.dispatch(); - _gameJustStarted = false; - } + gameStart(); #if FLX_DEBUG debugger.console.registerObject("state", _state); @@ -651,6 +648,12 @@ class FlxGame extends Sprite FlxG.signals.postStateSwitch.dispatch(); } + + function gameStart() + { + FlxG.signals.postGameStart.dispatch(); + _gameJustStarted = false; + } /** * This is the main game update logic section. @@ -902,4 +905,4 @@ private class FlxIntroSplash extends FlxSplash FlxG.game._gameJustStarted = true; super.startOutro(onOutroComplete); } -} +} \ No newline at end of file diff --git a/flixel/util/typeLimit/NextState.hx b/flixel/util/typeLimit/NextState.hx index 31825e809a..7192878532 100644 --- a/flixel/util/typeLimit/NextState.hx +++ b/flixel/util/typeLimit/NextState.hx @@ -74,7 +74,7 @@ abstract NextState(Dynamic) /** * A utility type that allows methods to accept multiple types, when dealing with "future" `FlxStates`. * Prior to haxeFlixel 6, the `FlxGame` constructor took a `FlxState` class which meant initial - `FlxStates`could not have constructor args. In version 6.0.0 and higher, it now takes a function + * `FlxStates`could not have constructor args. In version 6.0.0 and higher, it now takes a function * that returns a newly created instance. * * ## examples: @@ -126,5 +126,4 @@ abstract InitialState(Dynamic) to NextState else return cast this; } -} - +} \ No newline at end of file From eb78d5c80d91f9a1304a37fc4c7f05ed1aea5d69 Mon Sep 17 00:00:00 2001 From: George FunBook Date: Wed, 24 Jan 2024 14:19:06 -0600 Subject: [PATCH 6/6] add #2733 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54793c3e18..b555e2facc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ #### Changes and improvements: - `FlxSpritegroup`: Setting `origin` now causes members to pivot around the same point ([#2981](https://github.com/HaxeFlixel/flixel/pull/2981)) - `FlxCamera`: Smoother camera lerping, particularly with non-fixed timesteps ([#2922](https://github.com/HaxeFlixel/flixel/pull/2922)) +- `FlxState`: Remove deprecated `switchTo` ([#2733](https://github.com/HaxeFlixel/flixel/pull/2733))Z +- `FlxG`: Add deprecation warning on `switchState` with instances ([#2733](https://github.com/HaxeFlixel/flixel/pull/2733))Z 5.6.0 (TBD)