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

Show transitions above everything else #410

Merged
merged 17 commits into from
Nov 16, 2023
Merged

Show transitions above everything else #410

merged 17 commits into from
Nov 16, 2023

Conversation

MAJigsaw77
Copy link
Contributor

@MAJigsaw77 MAJigsaw77 commented Nov 14, 2023

I made this pr mostly because when the FlxG.camera has a zoom like 0.9 the transition looks weird, this is fixing it.

@MAJigsaw77
Copy link
Contributor Author

Idk why nightly fails, the another ones seems to not have an issue?

@Geokureli
Copy link
Member

nightly is failing on all branches - HaxeFoundation/haxe#11353

@MAJigsaw77
Copy link
Contributor Author

Oh, I see

@Geokureli
Copy link
Member

Geokureli commented Nov 14, 2023

I assume this is so that the transition is always on top of all other cameras? Please add a basic description to all PRs, and always provide simple test cases that highlight the change's need. The fact that the first commit didn't compile makes me think this is untested, and perhaps a theoretical feature rather than a practical one.

Shouldn't the camera be removed and destroyed when the transition is done, particularly for intro transitions

@MAJigsaw77
Copy link
Contributor Author

I assume this is so that the transition is always on top of all other cameras? Please add a basic description to all PRs, and always provide simple test cases that highlight the change's need. The fact that the first commit didn't compile makes me think this is untested, and perhaps a theoretical feature rather than a practical one.

Shouldn't the camera be removed and destroyed when the transition is done, particularly for intro transitions

I made this pr mostly because when the FlxG.camera has a zoom like 0.9 the transition looks weird, this is fixing it.

@Geokureli
Copy link
Member

then can you share an example showing that the old system looks weird and the new one does not?

@MAJigsaw77
Copy link
Contributor Author

then can you share an example showing that the old system looks weird and the new one does not?

Sure

@MAJigsaw77
Copy link
Contributor Author

MAJigsaw77 commented Nov 14, 2023

then can you share an example showing that the old system looks weird and the new one does not?

Sure

Before:
https://streamable.com/bof6up

After:
https://streamable.com/xvn1hk

@Geokureli
Copy link
Member

Geokureli commented Nov 15, 2023

Don't know if you saw this

Shouldn't the camera be removed and destroyed when the transition is done, particularly for intro transitions

Also in the future please provide simple code for test cases, so I can check it out locally and look for potential issues or unintended side effects. if you just provide videos, I'll end up making my own test cases when I have time, but it'll take longer

@MAJigsaw77
Copy link
Contributor Author

MAJigsaw77 commented Nov 15, 2023

Don't know if you saw this

Shouldn't the camera be removed and destroyed when the transition is done, particularly for intro transitions

Also in the future please provide simple code for test cases, so I can check it out locally and look for potential issues or unintended side effects. if you just provide videos, I'll end up making my own test cases when I have time, but it'll take longer

FlxTransitionableState.defaultTransIn = new TransitionData(FADE, FlxColor.BLACK, 1, FlxPoint.weak(0, -1));
FlxTransitionableState.defaultTransOut = new TransitionData(FADE, FlxColor.BLACK, 0.7, FlxPoint.weak(0, 1));

@MAJigsaw77
Copy link
Contributor Author

About the camera, I don't think it's necessary to destroy it.

@MAJigsaw77
Copy link
Contributor Author

But I'll do something about it

@Geokureli
Copy link
Member

Geokureli commented Nov 15, 2023

About the camera, I don't think it's necessary to destroy it.

Tools should clean up after themselves and it this case it's trivially easy to do so, otherwise every state with an intro transition will have an useless camera drawing blank alpha over the entire game every frame.

Also I worked on a project that used these transition effects for cinematic events, without switching to or from another state, so this code could have added dozens of cameras to the state

@Geokureli Geokureli closed this Nov 15, 2023
@Geokureli Geokureli reopened this Nov 15, 2023
@Geokureli
Copy link
Member

Geokureli commented Nov 15, 2023

mis-clicked and accidentally closed this before, sorry

Edit: whoops

@Geokureli
Copy link
Member

Geokureli commented Nov 15, 2023

this is the test state I made. It works as desired on outros but not intros (after fixing the above issue)

package states;

import flixel.FlxCamera;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.math.FlxPoint;
import flixel.math.FlxRect;
import flixel.addons.transition.TransitionData;
import flixel.addons.transition.Transition;
import flixel.addons.transition.FlxTransitionableState;
import flixel.util.FlxColor;

/**
 * https://github.com/HaxeFlixel/flixel-addons/pull/410
 */
class TransitionCameraTestState extends FlxTransitionableState
{
    public function new ()
    {
        FlxTransitionableState.defaultTransIn = new TransitionData(FADE, FlxColor.BLACK, 1, FlxPoint.weak(0, -1));
        FlxTransitionableState.defaultTransOut = new TransitionData(FADE, FlxColor.BLACK, 1, FlxPoint.weak(0, 1));
        
        super();
    }
    
    override function create()
    {
        super.create();
        
        FlxG.camera.bgColor = 0xFFffffff;
        
        var bg = new FlxSprite(50, 50);
        bg.makeGraphic(FlxG.width - 100, FlxG.height - 100, 0xFF000080);
        add(bg);
        
        var fg = new FlxSprite(10, 10);
        fg.makeGraphic(FlxG.width - 20, 100, 0xFFa00000);
        fg.camera = new FlxCamera();
        fg.camera.bgColor = 0x0;
        FlxG.cameras.add(fg.camera, false);
        add(fg);
    }
    
    override function update(elapsed)
    {
        super.update(elapsed);
        
        if (FlxG.keys.justPressed.SPACE)
            FlxG.switchState(new TransitionCameraTestState());
    }
}

@MAJigsaw77
Copy link
Contributor Author

MAJigsaw77 commented Nov 15, 2023

this is the test state I made. It works as desired on outros but not intros

Weird, on the videos I send it worked.

@Geokureli
Copy link
Member

this is the test state I made. It works as desired on outros but not intros

Weird, on the videos I send it worked.

This is why it's important to make easily sharable small tests rather than a video of a massive game

@MAJigsaw77
Copy link
Contributor Author

MAJigsaw77 commented Nov 15, 2023

this is the test state I made. It works as desired on outros but not intros

Weird, on the videos I send it worked.

Maybe put super.create(); after add(fg);.

@MAJigsaw77
Copy link
Contributor Author

MAJigsaw77 commented Nov 15, 2023

this is the test state I made. It works as desired on outros but not intros (after fixing the above issue)

Hmm

Maybe the issue has something to do with persistentDraw.

@Geokureli
Copy link
Member

It does have to do with the order of super.create() because the FG camera is created after the intro starts, but I'm wondering if there is a way to account for this, since it's a common way to structure code?

@Geokureli
Copy link
Member

Geokureli commented Nov 15, 2023

I moved the adding of the camera to the transition's start so it happens after create() to prevent ordering issues

@Geokureli
Copy link
Member

if (FlxG.cameras.list.contains(_effectCamera))
	FlxG.cameras.remove(_effectCamera, false);

_effectCamera = FlxDestroyUtil.destroy(_effectCamera);

this should go back to what it was before, if the camera was removed from the state switch calling FlxG.cameras.reset(), then it has also been destroyed

@MAJigsaw77
Copy link
Contributor Author

So?

@MAJigsaw77
Copy link
Contributor Author

I need to remove that code and replace the FlxG.camera.add to that?

@Geokureli
Copy link
Member

sorry, working on something else right now, should get back to this soon, I want to double check a few things before merging

@Geokureli
Copy link
Member

Geokureli commented Nov 15, 2023

Made some changes,

  • Added a cameraMode option to TransitionData allowing the following values:
    • TOP: (default value) the current "top" camera is used
    • NEW: a new camera is created and destroyed by the transition, useful if the top camera has some unwanted effect on it
    • DEFAULT: transitions use the default cameras
  • moved the camera handling logic from Transition to TransitionEffect so the mode is honored even when using transitions effects without transition substates
  • changed the hxFormat of flixel-addons to match flixels
  • using lower case args for methods
  • some better enum handling

@MAJigsaw77
Copy link
Contributor Author

Made some changes,

  • Added a cameraMode option to TransitionData allowing the following values:

    • TOP: (default value) the current "top" camera is used
    • NEW: a new camera is created and destroyed by the transition, useful if the top camera has some unwanted effect on it
    • DEFAULT: transitions use the default cameras
  • moved the camera handling logic from Transition to TransitionEffect so the mode is honored even when using transitions effects without transition substates

  • changed the hxFormat of flixel-addons to match flixels

  • using lower case args for methods

  • some better enum handling

What's left to do in order to get this pushed?

@Geokureli
Copy link
Member

Geokureli commented Nov 15, 2023

gonna go run an errand, then merge when i come back assuming CI passes (cept nightly)

@Geokureli Geokureli changed the title Added a camera for the transition substrate and probably destroy the effect sprite. Show transitions above everything else Nov 16, 2023
@Geokureli Geokureli merged commit 105f37a into HaxeFlixel:dev Nov 16, 2023
10 of 15 checks passed
@Geokureli
Copy link
Member

Geokureli commented Nov 16, 2023

Note: I put @since 5.6.0 but that's flixel's next minor version, it should be flixel-addon's nextversion which is going to be 3.3.0

this is why I like to wait at least a day on most PRs, so i can look over it for any mistakes with fresh eyes

@MAJigsaw77 MAJigsaw77 deleted the patch-1 branch November 16, 2023 16:30
@Geokureli Geokureli added this to the 3.2.2 milestone Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants