Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - IQAndreas

Pages: 1 [2]
21
help / Re: "Sub-FlxState"
« on: Thu, Dec 22, 2011 »
Actually, this might be done perhaps a lot simpler with a modified FlxDialog object.
Thanks for the code example!

But that's still a bit of code you have to re-write each time. By just adding a "setSubState" function and a "FlxSubState" class, you can reduce the amount of work needed to create such a dialog. It's not a huge save, but anything that makes rapid development easier is a step in the right direction in my opinion. :)

I think you could post this sort of thing in the Releases forum, which is lower traffic, and it's less likely it'll be overlooked.
Good idea! I created a new thread for the changes in that section, so just let this one die (or better yet, if a moderator can lock it)

http://forums.flixel.org/index.php/topic,5663.0.html

If you guys have any thoughts or ideas for the changes, let me know.

22
These changes to Flixel allow for "SubStates", where another state is displayed on top of the current one, and has the capability of having a different background color, as well as preventing the "parent state" from updating or receiving keyboard and mouse input.

I still haven't merged the changes to "my" master flixel branch, but instead still have everything stored in a separate branch:
https://github.com/IQAndreas/flixel/tree/dev_FlxSubState

The example game (a branch of AdamAtomic's EZPlatformer) can be found here (with the sample SWF in the "bin" folder):
https://github.com/IQAndreas/EZPlatformer


DETAILS
You can set the sub state from any FlxState as follows:
Code: [Select]
this.setSubState(new PauseMenu(), <optional callback when the menu closes>);
The current "FlxState" (likely named "GameState") is still running in the background and still in memory. The new FlxSubState (named "PauseMenu" in the example) does not replace "FlxG.currentState", but is in a sense a "child" of the current GameState instance. (but it won't show up in the list of the GameState members and interfere with other children)

You can extend "FlxSubState" which works just like a "FlxState" but adds a "isBlocking" option which if set to true prevents the parent FlxState from running it's "update" method. (Note that the parent state's "draw" method is always run, even if the subState is blocking the update command)

So for instance, the "Pause Menu" in MineCraft would have "isBlocking" set to true, so the "game state" stops.
The "Opening Chest" menu in MineCraft would not be blocking, since the world keeps playing in the background.

 - FlxSubState can have a different background color (even transparent or partially transparent, so the "parent state" still shows up behind it.)
 - The SubState will ALWAYS be rendered on top of the parent state.
 - When opening a FlxSubState, you can add a callback for when the state closes.
 - When the FlxSubState closes, you can pass a string to the parent state with information (for instance, why the state closed).

Nitty gritty:
 - The SubState does not have a public reference to it's parent. This is to adhere to proper encapsulation so the SubState doesn't need to know anything about it's parent state. You can however pass parameters to the constructor of the SubState if needed.
 - You can use the FlxSubState as a regular FlxState without any problems. Just make sure you override the "close()" function to handle the behavior properly. You can use "isSubState" to see if the current instance is the main state, or a sub state.
 - There are two additional parameters added to the standard "FlxState" class, "bgColor" and "useMouse". Instead of using the "FlxG" commands for setting those two properties, this will ensure that FlxSubStates also have those properly set.
 - If a parent state has "useMouse" set to false, but the sub state has it to true (such as if there are buttons on the screen), when the sub state closes, it will go back to the parent's mouse settings, hiding the mouse (and vice versa)

23
help / Re: "Sub-FlxState"
« on: Wed, Dec 21, 2011 »
And done! (note, not my best work, but it looks nice at least :-\

The example game (a branch of AdamAtomic's EZPlatformer) can be found here:
https://github.com/IQAndreas/EZPlatformer

The SWF is in the "bin" folder, and I'm too tired at the moment to wrap it in a HTML file and put it up on a server somewhere. ;)

I still haven't merged the changes to "my" master flixel, but instead still have everything stored in a separate branch:
https://github.com/IQAndreas/flixel/tree/dev_FlxSubState

24
help / Why is a Class (not instance) passed to FlxGame?
« on: Wed, Dec 21, 2011 »
Is there a reason that in the initial constructor of "FlxGame" you pass a "Class", but in "FlxG.switchState()" you pass an instance? Is this an oversight, or is there a good reason for that?

Personally, I would prefer if an instance is passed as you can pass starting values along to the constructor of the FlxState.

And if someone really stubbornly wants to pass a class, perhaps that parameter could be untyped allowing either a class or instance?


I wasn't sure if this was a question for the GitHub issue tracker, or if that's reserved for bugs. In fact, is there any place where the contributors have written out the logic behind various decisions of how they structured Flixel (more than what can be found scattered about in the code comments)?

25
help / Re: Detect if any key is "just pressed"
« on: Wed, Dec 21, 2011 »
Changes made, and recommended merging with the library:
https://github.com/AdamAtomic/flixel/pull/215


I hope the developers don't feel like I'm harassing them with all my pull requests. Maybe I should just leave my changes for my own fork... :-\

26
help / Re: Detecting when game doesn't have focus.
« on: Wed, Dec 21, 2011 »
The problem is, Flixel uses the events "Event.ACTIVATE" and "Event.DEACTIVATE" to tell if a SWF is in focus or not, but since those events don't trigger until the focus actually "happens", the SWF can't tell off the top of the bat if it has focus or not.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/EventDispatcher.html#event:activate

Perhaps if you use some mix of JavaScript to notify your SWF when it has focus or not.

You could have it paused until the mouse is ever over the SWF (MouseEvent.MOUSE_MOVE). If the SWF is in focus, it will detect the mouse which is very likely to move over your SWF.

But yes, I have found it annoying on several occasions when sites have a "heavy SWF" embedded onto the page that runs immediately rather than wait for the user to press a "start" button, (*cough cough* http://www.photonstorm.com/flixel-power-tools ) especially on my little netbook. :P

27
help / Detect if any key is "just pressed"
« on: Wed, Dec 21, 2011 »
I don't want to detect if any key is down (done with [ic]FlxG.key.any()[/ic] ) but instead if any key was just pressed.

Does this already exist, or should I add such a function?

28
I realize this is an old topic, but since it's so high in Google's search results, I thought I'd post the solution in case anyone else comes across it.

This problem is due to key jamming. More details can be found in this thread:
http://forums.flixel.org/index.php/topic,5621.0.html

29
help / "Graphics.clear" for FlxSprites
« on: Tue, Dec 20, 2011 »
What is the FlxSprite equivalent for Graphics.clear? For instance if you have drawn a square using "makeGraphics", how would I reset that line?

I read in another post someone using "flxSprite.fill(0x00000000)", but will that even reset the size of the sprite to the way it was before?


What about for loaded graphics, how are they best cleared without resetting the position, visibility, and existence of a FlxSprite?

30
help / Re: "Sub-FlxState"
« on: Mon, Dec 19, 2011 »
So do we have to "transit" to this state? If so, how do we keep everything from the previous state? And how to keep the game in the background?
For this example, let's assume your current, plain old FlxState is an instance of your own class "GameState". You switch to the new state by calling this inside of your GameState:
Quote
this.setState(new PauseMenu(), <optional callback when the menu closes>);

That will draw the new state right on top of EVERYTHING in the current state (but if the top state is only a little "Alert" window etc, you can still see the "game state" behind it.)

Also, if the new state is blocking (like the standard "pause menu" usually is), the "update" command won't run on the GameState until the menu has closed.

The current "GameState" is still running in the background and still in memory. The new PauseMenu sub-state does not replace "FlxG.currentState", but is in a sense a "child" of the current GameState instance. (but it won't show up in the list of the GameState members)


Since FlxSubState extends FlxState, it too has a "subState" property, so you can keep stacking on these states, such as having a "ControlsMenu" or "AboutMenu" on top of the current "PauseMenu" sub-state.


Would it be clearer if I modified a project to use this system?

31
help / Re: "Sub-FlxState"
« on: Sun, Dec 18, 2011 »
As for the reply I was going to make before I removed the thread...

Thanks for the input. (Also thanks to Arkeus on IRC for letting me glean his code)

I ended up adding in my own system into the Flixel framework and can be found on this branch:
https://github.com/IQAndreas/flixel/tree/dev_FlxSubState
(I could have used separate classes, but by modifying the core classes, I kept my code simpler and avoided a few potential complications)

In a nutshell, you can extend "FlxSubState" which works just like a "FlxState" but adds a "isBlocking" option which if set to true prevents the parent FlxState from running it's "update" method. (Note that the parent state's "draw" method is always run, even if the subState is blocking the update command)

So for instance, the "Pause Menu" in MineCraft would have "isBlocking" set to true, so the "game state" stops.
The "Opening Chest" menu in MineCraft would not be blocking, since the world keeps playing in the background.

 - When opening a SubState, you can add a callback for when the state closes.
 - When the SubState closes, you can pass a string to the parent state with information (for instance, why the state closed).
 - The SubState does not have a public reference to it's parent. This is to adhere to proper encapsulation so the SubState doesn't need to know anything about it's parent state. You can however pass parameters to the constructor of the SubState if needed.
 - The SubState will ALWAYS be rendered on top of the parent state.

Code: [Select]
class PauseMenu extends FlxSubState
{

    public static const QUIT:String = "PauseMenu::quit";
    public static const RESUME:String = "PauseMenu::resume";
   
    public function PauseMenu()
    {
        // 'true' here means the state is blocking the parent state
        super(true);
    }
   
    public override function create():void
    {
        // ... display buttons and add listeners
    }
   
    //Sample handlers
    public function onQuitButtonClicked(event:Event):void
    {
        this.close(PauseMenu.QUIT);
    }
    public function onResumeButtonClicked(event:Event):void
    {
        this.close(PauseMenu.Resume);
    }
}

Code: [Select]
class PlayState extends FlxState
{
    // ...
   
    //No need to add anything to "update()" as it will pause automatically
   
    function openPauseMenu():void
    {
        this.setState(new PauseMenu(), onMenuClosed);
    }
   
    function onMenuClosed(state:FlxSubState, result:String):void
    {
        if (result == PauseMenu.QUIT)
        {
            trace("Exit to main menu");
        }
        //else - keep playing
    }
}



I haven't actually applied it to any project yet, but it should work in theory.

32
help / "Sub-FlxState"
« on: Sun, Dec 18, 2011 »
Noo! I was on autopilot, and while thinking I hit the "Reply to Topic", it turns out that button said "Remove Topic" ???

Anyway, this is just reposting that old topic. There were two replies already as well, so I'll just copy and paste them in (luckily the topic was cached, so the back button brought it up again)



Take for instance MineCraft, you are still in the "Play state", but when you open a chest, a GUI appears on top of the current state, and all user input (keyboard, mouse, the works) go to this new state.

However, the background play state still keeps all variables and is essentially "paused" in the background until you exit the current "sub-state".


Is there already a built in way of creating these "sub states" in Flixel, or should I "take matters into my own hands"?

Quote from: test84
I think you can have a boolean for being in a menu and in your update, check and if you are in menu, skip everything and draw and handle menu. But I'm sure there are better ways to do it.

Quote from: auriplane
I didn't use Flixel's state system at all, and implemented maybe 3 global state machines for my game.  Of course, my code is hardly a shining example ;-)  But implementing state machines is easy, so I recommend not getting too hung up on specifics, and just pick a solution and keep your forward momentum.  If it's ever a problem down the road, it shouldn't be a big deal to refactor.

33
releases / What is the current state of Flixel?
« on: Sun, Dec 18, 2011 »
Checking GitHub, the last release was in August, and the last modifications in the "dev" build were in October. Two months really isn't that long, but I'm still curious why there is a standstill while there are a handful of open issues as well as changes in the other branch.

I don't mean to pester the maintainers at all (it's really no hurry, the current build of Flixel works like gold), I'm just curious of how things are coming along. :)

Second, which changes are in the dev build that are planned to be released in the very near future? (I could look at the actual code, but I'm looking for the ideas and thoughts behind the changes) EDIT: Turns out the dev builds only contained two small bug fixes, so no major changes there. What is in the master build is essentially the "latest".

34
help / Re: Detecting clicks on a FlxSprite or FlxGroup
« on: Fri, Dec 16, 2011 »
Thanks, just what I needed!

While we are on the topic of the Flixel Power Tools, do you think you could generate the ASDoc and either include it in the repository, or perhaps throw it up on a server somewhere? I really like the way you have set up the test suite to show off the features of the library, but sometimes I need to double check function parameters or other details when I don't have the IDE open.

35
help / Detecting clicks on a FlxSprite or FlxGroup
« on: Thu, Dec 15, 2011 »
Is there any "Flixely" way to handle clicks and hovers on Flixel display objects, or do I just add a "plain old" Flash event listener?

Since I'm assuming all FlxSprites are bittled onto one single screen, I'm assuming there is some sort of process.

Pages: 1 [2]