Flixel Forums

development => help => Topic started by: photonstorm on Thu, Jun 16, 2011

Title: Flixel Power Tools
Post by: photonstorm on Thu, Jun 16, 2011
Latest Version: 1.9
Released: October 11th 2011
Example Demos: 86

Quite frankly flixel is awesome. It allows for very rapid game development. And while it does a lot for you, it is lacking in a few  areas. After all itís just a framework, and frameworks are meant to be built-upon.

That is where the Flixel Power Tools come in. They are a set of classes, all neatly arranged in a single package that use the new plugin architecture of Flixel 2.5. They push flixel just that bit further and cover a lot of fundamental ground for you. The Flixel Power Tools are for Flixel 2.5+ only, they will not work with earlier versions.

Classes

The following classes are available in the latest version:


The FlxSpecialFX class supports its own plugins for creating special effects. Currently this includes:


Demos

There's also a Demo Test Suite which include loads of easy-to-follow examples of the tools in action, with a funky menu system and a visual way to actually see what they do. I always find it easier to learn by looking and then dissecting code! The full source code is on github, including all 77 demos.

(http://sandbox.photonstorm.com/flixelpowertools/titlepage.png)

Be sure to try the Credits button :)

Getting Started Guide

There is now a comprehensive 6-page Getting Started Guide in the Docs folder (https://github.com/photonstorm/Flixel-Power-Tools/tree/master/Docs). Download the zip or checkout from github and get reading! It should help beginners get started a lot faster.

The library and Test Suite will continue to expand, and they will be kept in-line with the flixel codebase, which is rapidly changing at the moment.

Download

The Flixel Power Tools can be found on github:

https://github.com/photonstorm/Flixel-Power-Tools

You can download a zip file containing everything or checkout the repo. There is a dev branch, which contains the "bleeding edge" and work in progress stuff. "master" is the most current stable version.

Any questions about any of the tools? Ask me here :)
Title: Re: Flixel Power Tools
Post by: photonstorm on Thu, Jun 16, 2011
(http://www.photonstorm.com/wp-content/uploads/2011/06/grab222255.png)

Itís been a month in development but itís finally here Ė Version 1.7 of the Flixel Power Tools has now gone from dev to master Ė and I urge you all to give it a play! I have also re-organised my site so that the tools and all sub-classes are now easily accessible from the right-hand side bar. More info, more screen shots, less scrolling

V1.7 includes a brand new Demo Suite system (donít forget to try the Credits button  ). Itís now easier and quicker to get to the examples, which is just as well as weíve over 60 of them in this release. Donít forget to download the whole package from github, as it includes a Getting Started manual PDF, the full source code to all of the demos, all of the graphical and audio assets (warning: copyright, donít use commercially!), as well as the tools themselves.

As well as a suite overhaul there are some great new classes, and updates to nearly everything. FlxHealthBar is gone, replaced with the much more versatile FlxBar. This new bar can be used for anything, from progress meters to sprite health. It can fill in one of 8 different directions, can be hooked to a parent sprite or not, and be hooked to any value of that sprite Ė in short it doesnít have to be just a health bar any longer.

The biggest new addition is FlxWeapon. A comprehensive weapon manager for games. Handles creation, pooling and re-use of bullets and a heck of a lot more. Angled bullets, sounds, callbacks, fire at the mouse, fire from the mouse, fire from a parent sprite, fire from a fixed position, bullet speeds, firing rates. Phew! Combined with FlxControl this is a powerful combo.

FlxVelocity has been updated with lots of new functions: moveTowardsPoint, distanceToPoint, angleBetweenPoint, velocityFromAngle, accelerateTowardsObject, accelerateTowardsMouse and accelerateTowardsPoint! And FlxControl now supports rotation, thrusting and reversing.

So you can now make an asteroids style ship movement in a couple lines of code. Of course I couldnít resist adding some new Special FX including Blur and Center Slide. Enjoy!
Title: Re: Flixel Power Tools
Post by: Ramontique on Fri, Jun 17, 2011
Nice job, those new bars are just what I was looking for to quickly complete my project :)
Title: Re: Flixel Power Tools
Post by: foosety on Mon, Jun 20, 2011
Wow awesome updates, I really have to hand it to you this time!
I have a question relating to FlxButtonPlus. So, basically I started using FlxButtonPlus in place of FlxButton because I have a ton of buttons and only want one callback function (each button sending in its unique param 1,2,3 , etc).
However I ran into a problem. The problem being, I realized I can't scale my button sprite down to size (I don't care about highlight). You can do this in FlxButton, but not in FlxButtonPlus :(
Title: Re: Flixel Power Tools
Post by: photonstorm on Mon, Jun 20, 2011
How were you scaling down to size?
Title: Re: Flixel Power Tools
Post by: tomii on Tue, Jun 21, 2011
Hi Photonstorm!

I'm using your power tools for a game I'm working on atm, but I'm having some problems with the FlxBitmapfont class. It seems that whatever I put as the alignment, it's always aligned to the right :( Anyone else having this problem?
Title: Re: Flixel Power Tools
Post by: photonstorm on Tue, Jun 21, 2011
Throw me a bit of source so I can see, should be fine though! (in the Test Suite there are a couple of Bitmap Font tests that use align center)
Title: Re: Flixel Power Tools
Post by: tomii on Tue, Jun 21, 2011
Well, I just copied your example, so it's really strange that it won't work, but here you are:

Code: [Select]
// Score font
scoreFont = new FlxBitmapFont(ImgScoreFont, 14, 19, "0123456789", 10, 0);
scoreFont.setText("0", true, 1, 0, FlxBitmapFont.ALIGN_CENTER);
scoreFont.x = 140;
scoreFont.y = 90;
add(scoreFont);

This snippet is added after super.update();

Code: [Select]
scoreFont.text = String(FlxG.score);
Here's the other stuff..

Code: [Select]
[Embed(source = '../../../_assets/numberFont.png')] private var ImgScoreFont:Class;
private var scoreFont:FlxBitmapFont;

I found a bug aswell (I think). The text property wants a String, right? But, if you do: apple.text = "" + variable;
Then it works anyways. Right now I have: apple.text = String(NumberVariable);
And that works too. Which would you recommend?




Title: Re: Flixel Power Tools
Post by: zuperxtreme on Tue, Jun 21, 2011
Hey Photon, is there any reason why you didn't include in FlxVelocity, something like "moveTowardsPoint" ?

Seems like it would be useful, apart from moveTowardsObject. Just wondering, trivial to add.
Title: Re: Flixel Power Tools
Post by: tomii on Tue, Jun 21, 2011
I also have an idea for a new power tool; A health bar which is not a bar per se, but a group of FlxSprites. Think Mega Mans life bar, which is a pile of flat, white pixels, or the hearts in Zelda.
Title: Re: Flixel Power Tools
Post by: photonstorm on Tue, Jun 21, 2011
tomii - can you trace out the width of scoreFont for me please. Trace it after your call to setText. My guess is that because you've only got 1 character, the width will be the size of the character+1 (so 15 pixels)

As for text needing a string, the reason "" + var works is that it's casting it to a string for you automatically because of the "" + part (i.e. var gets cast to a string, then concatenated to ""). You can do that, or you can do String(var) or maybe cleaner: text = var.toString();
Title: Re: Flixel Power Tools
Post by: foosety on Tue, Jun 21, 2011
How were you scaling down to size?

I'm saying that in FlxButton class you can just scale the buttons with scale.x and scale.y but those don't exist in FlxButtonPlus.
Title: Re: Flixel Power Tools
Post by: photonstorm on Tue, Jun 21, 2011
zuper, FlxVelocity:

 * v1.5 New methods: velocityFromAngle, accelerateTowardsObject, accelerateTowardsMouse, accelerateTowardsPoint
 * v1.4 New methods: moveTowardsPoint, distanceToPoint, angleBetweenPoint

tomii - you can achieve the same effect (hearts, mega man life) using FlxBar empty and full images: Full is all of the hearts in a row, the other is a black bar (or whatever the background is) that is placed on the top.
Title: Re: Flixel Power Tools
Post by: photonstorm on Tue, Jun 21, 2011
I'm saying that in FlxButton class you can just scale the buttons with scale.x and scale.y but those don't exist in FlxButtonPlus.

It's because it extends a FlxGroup, But you can scale the buttons by scaling FlxButtonPlus.buttonNormal and FlxButtonPlus.buttonHighlight

Title: Re: Flixel Power Tools
Post by: foosety on Tue, Jun 21, 2011
I'm saying that in FlxButton class you can just scale the buttons with scale.x and scale.y but those don't exist in FlxButtonPlus.

It's because it extends a FlxGroup, But you can scale the buttons by scaling FlxButtonPlus.buttonNormal and FlxButtonPlus.buttonHighlight

Oh I didn't know that, that's perfect ill just scale those!
Title: Re: Flixel Power Tools
Post by: zuperxtreme on Tue, Jun 21, 2011
zuper, FlxVelocity:

 * v1.5 New methods: velocityFromAngle, accelerateTowardsObject, accelerateTowardsMouse, accelerateTowardsPoint
 * v1.4 New methods: moveTowardsPoint, distanceToPoint, angleBetweenPoint

I'll see my self out.  Haha, thanks.  :P
Title: Re: Flixel Power Tools
Post by: tomii on Tue, Jun 21, 2011
Code: [Select]
scoreFont = new FlxBitmapFont(ImgScoreFont, 14, 19, "0123456789", 10, 0);
scoreFont.setText("0", true, 1, 0, FlxBitmapFont.ALIGN_RIGHT);
trace("scoreFont: " +scoreFont.width);

Gives me // scoreFont: 15

Here's what it looks like. http://img848.imageshack.us/img848/2686/scorefont.png
Right now I've made it so that it ticks up from 0 -> 1000. New characters are added to the RIGHT, no matter what kind of alignment I choose.

What I want to do, is to have it aligned to the left, so that I can move the whole thing to the right-hand side.



Title: Re: Flixel Power Tools
Post by: photonstorm on Tue, Jun 21, 2011
The problem is that the width of the sprite is 15px, i.e. the width of 1 character (zero). So it can't align it anywhere as it fills up the whole width. If you then make the text "10" the width of the sprite will change to 30px, so again it's not aligned because it fills the whole width up.

The way align works is that in multi-line text it takes the longer line and makes the sprite the width of that, then the other lines are aligned based on the new sprite width. But if you only have 1 character (or 4 characters: 1000) that IS the width of the sprite. It's not that it isn't aligning it, it's that it is filling the whole sprite up.

The easiest way is probably to simply place the font like so:

Code: [Select]
var px:int = where-ever the right-hand side of the font should be;
font.x = (px - font.width);

then as the font expands in width, it'll adjust the x coordinate to the left to compensate, keeping it visually right-aligned in the box.

I may add in support to give the font a fixed width, so alignment would be based off of that, maybe in a future version.
Title: Re: Flixel Power Tools
Post by: tomii on Tue, Jun 21, 2011
Alright, I'll use that method then!

But, I thought it WAS fixed width? Isn't that why you have the 2nd and 3rd parameter (width and height) there?
Title: Re: Flixel Power Tools
Post by: photonstorm on Tue, Jun 21, 2011
That's character width/height.

I will rename them to characterWidth and characterHeight now for v1.8 :)
Title: Re: Flixel Power Tools
Post by: tomii on Tue, Jun 21, 2011
The main problem (for me at least), might be that people are expecting the align feature to work like in Illustrator or whatever, so it might seem odd why it's not working like this at first.

I think I now understand what you mean about the "Sprite's width" and stuff, now when I read your post again.

Thanks for the help!
Title: Re: Flixel Power Tools
Post by: photonstorm on Tue, Jun 21, 2011
Ok I have updated FPT on github dev branch. Grab the new FlxBitmapFont class (and the updated test BitmapFontTest3). You can now set a fixed width for the sprite and use the align parameter to control where the text is written. Example:

Code: [Select]
font1 = new FlxBitmapFont(AssetsRegistry.knightHawksPurpleFontPNG, 31, 25, FlxBitmapFont.TEXT_SET6, 10, 1, 1);
font1.setFixedWidth(290, FlxBitmapFont.ALIGN_RIGHT);

This gives the resulting sprite (which is what font really is) a width of 290px regardless of the text inside it, and the text is aligned to the right of that width.
Title: Re: Flixel Power Tools
Post by: tomii on Tue, Jun 21, 2011
Awesome!! I'll give it a go!
Btw, it wouldn't be possible to update the sprite's width in real time, would it?
Then you could do something like...

abc.Spritewidth = (abc.charW * String(abc.text).length);

and then in the update or render function or whatever you check to see if the length of the String is the same as last update - and skip the update if it IS - to save some CPU power.
Title: Re: Flixel Power Tools
Post by: photonstorm on Tue, Jun 21, 2011
You can change the width as often as you like, but it won't take effect until the next call to either setText or text =
Title: Re: Flixel Power Tools
Post by: tomii on Tue, Jun 21, 2011
I tested the new FlxBitmap and it works really good! You da man! - as always :D
The only adjustment I had to do was...

Code: [Select]
scoreFont.setFixedWidth(140, FlxBitmapFont.ALIGN_RIGHT);
scoreFont.x = scoreFontX -140;
scoreFont.y = scoreFontY;

When I was using the master-branch version, I used a variable to set it's x and y position, but as you can see I had to add -140 for it to appear at the same spot again. Maybe it's just natural? :p
But anyhow, this new feature is very nice, and I thank you for adding it so quickly!

Title: Re: Flixel Power Tools
Post by: photonstorm on Tue, Jun 21, 2011
scoreFont.x will set the sprite location based on the top-left corner of it. I've no idea what your scoreFontX variable holds, but if it's the right-hand side of the area in which you want the text to appear, change it to the left :)
Title: Re: Flixel Power Tools
Post by: tomii on Tue, Jun 21, 2011
Ah, alright. Thanks for clearing that up for me. I'm getting tired :) This is the second FTP class I use with this project, and I think I'll use *at least* one more before I'm done. Loving it :-*
Title: Re: Flixel Power Tools
Post by: photonstorm on Tue, Jun 21, 2011
:) feedback makes 'em get better 'n better! Simple as that.
Title: Re: Flixel Power Tools
Post by: foosety on Wed, Jun 22, 2011
Ok so I tried scaling the buttonNormal and buttonHighlight but ran into problems... First of the the picture did scale correctly and everything, however the bounding box was not affected by the scaling! The only thing I could think of was manually setting the width and height of each button's bounding box, which sort of worked, but my bounding boxes were off the screen while the image of the buttons were not. All in all I wish I could change the sprite before putting it into loadgraphic, but it doesn't work that way. Can you please help me?

Edit: Nevermind, I just scaled the sprites before hand instead of scaling them ingame....
Title: Re: Flixel Power Tools
Post by: foosety on Wed, Jun 29, 2011
Hello again :)

So lately I've been using FlxScreenGrab which is super awesome. I just wish that it would save the file as a PNG. As of right it just saves it as grab(####) without an extension. Can you look into this?

Thanks man.
Title: Re: Flixel Power Tools
Post by: photonstorm on Wed, Jun 29, 2011
It adds .png to the filename automatically - it even checks to see if you missed it out from the filename passed to it, and adds it if you did.

Look at lines 148-155 of FlxScreenGrab.as
Title: Re: Flixel Power Tools
Post by: foosety on Wed, Jun 29, 2011
I saw that... But this is all I get:
(http://dl.dropbox.com/u/20462084/error.bmp)


Here is the code I am using:
Code: [Select]
private function onPicture():void
{
FlxScreenGrab.defineCaptureRegion(Registry._body.x + 20, Registry._body.y + 20, Registry._body.width, Registry._body.height);
FlxScreenGrab.grab(null, true, false);
}
Title: Re: Flixel Power Tools
Post by: photonstorm on Wed, Jun 29, 2011
That's just Windows (well, the way Flash Player uses it) being crap. Save the file, then right-click it, Properties, and click on the Details tab. I bet under "File - Name" it says grab13113.png

Windows just hides extensions by default, by it's there.
Title: Re: Flixel Power Tools
Post by: felipe on Wed, Jun 29, 2011
I have a question about FlxWeapon. How can i detect the overlapping of a bullet with another object?
thanks!

//EDIT: Nevermind I just read the FlxWeapon class and it was written there..
Title: Re: Flixel Power Tools
Post by: foosety on Thu, Jun 30, 2011
Oh yeah, you are right. The extension is just hidden.

That's just Windows (well, the way Flash Player uses it) being crap. Save the file, then right-click it, Properties, and click on the Details tab. I bet under "File - Name" it says grab13113.png

Windows just hides extensions by default, by it's there.
Title: Re: Flixel Power Tools
Post by: zuperxtreme on Mon, Jul 4, 2011
Probably doesn't belong here, but how would I calculate the trajectory of a moving object?

I mean so that my FlxWeapon fires and always hits it's constant-speed target.
Title: Re: Flixel Power Tools
Post by: photonstorm on Tue, Jul 5, 2011
If the object is moving at a constant speed then it's relatively painless to calculate (I'll post an example later if you need) - but if the object has acceleration or changes direction, it becomes a lot harder. For that you'd really need to have a "homing missile" type bullet - which I do have planned for the next update.
Title: Re: Flixel Power Tools
Post by: zuperxtreme on Tue, Jul 5, 2011
I'll see if I can come up with something, if not, I'll post here. :)
Title: Re: Flixel Power Tools
Post by: felipe on Mon, Jul 11, 2011
Is there a way that the members from one flxgroup follow the members of other flxgroup?
Title: Re: Flixel Power Tools
Post by: initials on Tue, Jul 12, 2011
I installed Power Tools last night and it was easy and painless. Great idea and implementation to have a plugins directory.

Good work everyone involved!
Title: Re: Flixel Power Tools
Post by: photonstorm on Wed, Jul 13, 2011
Glad you found it easy. Work has been insane the past few weeks, but I've got a lot of tools updates planned. Mostly updates to existing features, bug fixes, and a couple of fun new ones :)
Title: Re: Flixel Power Tools
Post by: Mad on Sun, Jul 17, 2011
Steel yourself, I am about to go on an over-exaggerated rant.

I love this package and I think it's very useful, but I've got to be frank:

Your FlxButtonPlus class is completely useless.

Up one side and down the other it is poorly thought out as an extension to the FlxButton class. One reason is because it's not an extension of FlxButton, it's an extension of FlxGroup, which is basically kind of counter intuitive by itself. There is also no down state. Why is there no down state? And then of course there's the whole thing where every button state has to have its own image, you can't just make one sprite sheet for all three states and have the Flixel engine split it up all in one nice neat package.

And lastly, you can't use the FlxDisplay class with it, because it's not a FlxSprite... it's a subclass of FlxGroup, thus making FlxDisplay useless if you want to center a button. What happened when you were making this class??

In all seriousness, I don't intend any offense with this rant, and I think that you've done a magnificent job with Flixel Power Tools. But you should seriously reconsider reworking your FlxButtonPlus class, as it contains some major logical fallacies in its design. You are completely welcome to tear my argument apart though, I'd like to be proven wrong. :)
Title: Re: Flixel Power Tools
Post by: felipe on Tue, Jul 19, 2011
Is there a way that the members from one flxgroup follow the members of other flxgroup?
Sorry, but i wish someone could help me with this.
Title: Re: Flixel Power Tools
Post by: photonstorm on Tue, Jul 19, 2011
With what felipe?
Title: Re: Flixel Power Tools
Post by: felipe on Tue, Jul 19, 2011
Sorry, wrong quoted text, fixed :P
Title: Re: Flixel Power Tools
Post by: photonstorm on Tue, Jul 19, 2011
How do you mean one group follow another? Can you give an example how you'd use this?
Title: Re: Flixel Power Tools
Post by: felipe on Tue, Jul 19, 2011
My game has a group of zombies, and a group of "civilians", what I am trying to do is that the zombies follow the civilians, they are separated by groups .
Title: Re: Flixel Power Tools
Post by: photonstorm on Tue, Jul 19, 2011
I'm not sure what you need is a "group follow group" behaviour here - but rather some logic for your zombies. Personally I would approach it so that when the zombie and civvies groups are created, I go through each zombie and tell it to pick a random civilian to follow. Depending on the game maybe it's 1 zombie vs. 1 civ, or maybe it'd be fun to have say 3 zombies after 1 civ, and some civs with no zombies following them at all. This is a game design decision really.

Once they've picked their prey you can kick things off, and the speed at which the zombies track the civs is just down to your code really.
Title: Re: Flixel Power Tools
Post by: felipe on Tue, Jul 19, 2011
ok! thanks, gives me an idea of what to do :)
Title: Re: Flixel Power Tools
Post by: John Hutchinson (Johntron247) on Tue, Jul 19, 2011
Maybe have them pick the closest one to follow (shortest patch) and have them update which one they're following once in a while. That way zombies can change their minds if another civilian becomes easier to catch, or they can pick another one if they caught one.  That will accomplish the variable number of zombies following each civilian thing and also make it look more intelligent.
Title: Re: Flixel Power Tools
Post by: Rapid on Wed, Jul 27, 2011
Wow, that is amazing! Is there ANYTHING flixel cant do?! that is really really great, i feel i can make now game now. i kept worrying about the weapons thing, but really this is perfect.
Title: Re: Flixel Power Tools
Post by: photonstorm on Fri, Jul 29, 2011
V1.8 of the Flixel Power Tools was just made live!

http://www.photonstorm.com/archives/1484/flixel-power-tools-v1-8-released-lets-get-clicky

(http://www.photonstorm.com/wp-content/uploads/2011/07/grab26457.png)

Tonight I pushed up the final v1.8 release of the Flixel Power Tools. Thereís only really one major new class this time, but itís a big one. FlxExtendedSprite together with FlxMouseControl provide you with the ability to create FlxSprites that you can click with the mouse, drag around the game world, snap to a grid, throw or even hook to the mouse with a spring! It handles overlapping sprites with ease, has custom sort controls (to determine which mouse gets the click) and clicks can be bounding box or pixel perfect as needed. Dragging can be locked to a single axis or a FlxRect area too. The Extended Sprites also now have built-in gravity, which works wonders combined with the ability to throw them. There are no less than 14 examples in the Demo Suite to boot including a little mini-game.

Also new in this release is FlxFlectrum, a powerful addition to FlxFlod, that allows you to create your own vu-meter / spectrum analyser style display for soundtracker music. Use the built-in meter or provide your own PNG, with direction support, column/row spacing, background beat and peak or meter display modes.

Several classes have had new methods: FlxMath gained wrapAngle, angleLimit and mouseInFlxRect. FlxCollision received the new pixelPerfectPointCheck and the very handy createCameraWall, which builds an invisible collision wall out of Tile Blocks around the camera Ė you control the width. And last but not least a new FX: RevealFX.

Iím going to take a short break as I go away on summer holidays and work on my Flixel book. But I do plan on doing a v1.9 release which will be mostly (if not all!) bug fixes and new test cases. After this I have plans to work on a Window / GUI system suitable for making RPG style games, and tight Box2D integration.
Title: Re: Flixel Power Tools
Post by: foosety on Mon, Aug 1, 2011
Springs are hilarious and lots of fun. Nice update  :D
Title: Re: Flixel Power Tools
Post by: zuperxtreme on Mon, Aug 1, 2011
Very cool. You rock Photon. :D
Title: Re: Flixel Power Tools
Post by: c023-DeV on Mon, Aug 1, 2011
I'd love to check out the Flod stuff and wanted to ask if there is also a way to somehow trigger the instruments of the tracker file?

For example: I have a kick drum as instrument and use it for bullet hits and different materials (tiles) throw different pitch values and different wepons maybe even different filter settings?

Sorry if that is written somewhere but I didnt find it yet and Im a bit headcrazy the last weeks since I started coding =D ... but I love it!

Have a nice time, you earned it!
Title: Re: Flixel Power Tools
Post by: photonstorm on Mon, Aug 1, 2011
Sorry it's not possible to hook to instruments in Flod - it's because it pre-calculates a large chunk of the module into sample data in advance, and then basically keeps re-filling this buffer as it plays, so it's never really knowing about what instrument is playing currently.
Title: Re: Flixel Power Tools
Post by: wonkytonk on Tue, Aug 2, 2011
hey photon, thanks for all the great tools!
i was working with FlxControl the other day, and i wanted to build slowdown and speedup tiles, like braking or speed boost, when i noticed that there were speedup and slowdown functions already in FlxControlHandler that were still on the todo list, would these functions do exactly what i want or am i better off just figuring out another solution?
thanks!
Title: Re: Flixel Power Tools
Post by: photonstorm on Tue, Aug 2, 2011
They are place-holder functions to do what you need, but I just didn't code them yet sorry! There's no reason why you couldn't put your code in there though :)
Title: Re: Flixel Power Tools
Post by: redherring on Thu, Aug 4, 2011
Hey Photonstorm
This is some pretty cool work man. I'm new to playing around with actionscript and you've literally saved me weeks of work! Thanks for this dude.

I'm having a bit of a problem with the FlxMouseControl plugin though. If I use it like this (in the create() function for my PlayState for example), it works fine:
Code: [Select]
            ball = new FlxExtendedSprite(FlxG.width/2-3,FlxG.height/2-3);
            ball.makeGraphic(6,6,0xff000000);
            ball.enableMouseDrag();

But if I make a new class for the ball (and then add it in my PlayState), I can't seem to get it to work:
Code: [Select]
    public class Ball extends FlxExtendedSprite
    { 
        public function Ball()
        {
            super(FlxG.width/2-5,FlxG.height/2-5);
            makeGraphic(6,6,0xff000000);
            enableMouseDrag();
        }
    }

Sorry if I'm being a complete idiot, but I'd appreciate it if somebody could point out what I'm doing wrong.
Title: Re: Flixel Power Tools
Post by: xraven13 on Sat, Aug 13, 2011
Hey... :)

I am having problem with transforming HSV color to RGB...

For example if I take some color from here, I took Alizarin Crimson for example :
http://en.wikipedia.org/wiki/List_of_colors

And I take HSV values in this format  355, 77.0 / 100, 89.0 / 100.  I don't get correct RGB color back...

I converted result like this   :   result.toString(16)  just to see what is exact difference....

I get this :0xFFE23442  , while I should get : 0xffE32636  ...

So any idea what I am doing wrong :s ??

Also, since I get AARRGGBB  format, how I can transform that to RRGGBB since that is what color property of FlxG.camera accepts.  I guess if I would pass number in AARRGGBB format, it wouldn't work right ?
Title: Re: Flixel Power Tools
Post by: Kurai on Sat, Aug 13, 2011
Hi there,
first of all, thanks for making Flx Power Tools, it's helping me a lot. Just a total newbie question. I'm using FlxExtendedSprite, and I would like my sprite to change color when released from drag. I guess I should use mouseReleasedCallback, but I'm not understanding how exactly. Can you help me? Thanks!
Title: Re: Flixel Power Tools
Post by: photonstorm on Sun, Aug 14, 2011
How do you plan on colouring the sprite? With a specific sprite frame or via a filter or similar?
Title: Re: Flixel Power Tools
Post by: Kurai on Sun, Aug 14, 2011
Simply using a greyscale sprite and changing the color attribute :)
Title: Re: Flixel Power Tools
Post by: photonstorm on Sun, Aug 14, 2011
Right then I'd use mousePressedCallback, you would just set it like this:

Code: [Select]
yourExtendedSprite.mousePressedCallback = changeColour;
yourExtendedSprite.mouseReleasedCallback = changeColour;


private function changeColour(obj:FlxExtendedSprite, x:int, y:int):void
{
if (obj.isPressed)
{
// change to the mouse-pressed colour
}
else
{
// change to the not-pressed colour
}
}
 
Title: Re: Flixel Power Tools
Post by: rageace on Mon, Aug 15, 2011
I was wondering whether Flixel Power Tools can be used in a commercial project, and if so, what acknowledgements need to be made.

I read the license.txt but didn't understand what it meant.

Cheers.
Title: Re: Flixel Power Tools
Post by: photonstorm on Mon, Aug 15, 2011
Yes they can be used in a commercial project. No acknowledgements need to be made at all unless you give away the source code, in which case you should include the license file with the tools source and ensure they have all of their headers intact.

I would very much appreciate if you emailed me to tell me if you use them in a game, but you don't have to. It's just great motivation to keep on working on them when people show me they're being used.
Title: Re: Flixel Power Tools
Post by: thePalindrome on Wed, Aug 17, 2011
I installed everything according to the .pdf, but it's not working...

I create a FlxButtonPlus, and I get this:

E:\Code Projects\flash projects\What did us in\src\PlayState.as(16): col: 21 Error: Type was not found or was not a compile-time constant: FlxButtonPlus.
public var Button:FlxButtonPlus;
^
E:\Code Projects\flash projects\What did us in\src\PlayState.as(21): col: 17 Error: Call to a possibly undefined method FlxButtonPlus.
Button = new FlxButtonPlus(115, 115, clicked, null, null, 100, 20);


I have no idea why this isn't working...

Although, I have a "global" flixel at E:\flixel, am I supposed to put it there, or somewhere else?
Title: Re: Flixel Power Tools
Post by: photonstorm on Wed, Aug 17, 2011
If you have a "global" Flixel install at E:\flixel then you need to put the photonstorm folder inside its plugin folder. The error you are getting is because it can't see the plugin classes.
Title: Re: Flixel Power Tools
Post by: thePalindrome on Wed, Aug 17, 2011
If you have a "global" Flixel install at E:\flixel then you need to put the photonstorm folder inside its plugin folder. The error you are getting is because it can't see the plugin classes.

Okay, the path is this:

E:\flixel\org\flixel\plugin\photonstorm

that contains the Docs, Flixel Versions, and Test Suite folder, is it installed right?
Title: Re: Flixel Power Tools
Post by: photonstorm on Wed, Aug 17, 2011
Nope - unzip the contents of the photonstorm.zip file into the plugins folder. The rest of the stuff is the Test Suite, put it somewhere else and keep it, it contains loads and loads of example code.
Title: Re: Flixel Power Tools
Post by: thePalindrome on Wed, Aug 17, 2011
Ah, I was wondering why there was a .zip in the .zip folder!
So the classes should be at:
E:\flixel\org\flixel\plugin\photonstorm

is that right?
Title: Re: Flixel Power Tools
Post by: photonstorm on Wed, Aug 17, 2011
Yup.
Title: Re: Flixel Power Tools
Post by: wonkytonk on Sat, Aug 20, 2011
hey photon, i'm running into some collision issues in my game, i'm using FlxCollisions, and i'm wondering if i'm doing everything i need to, putting:

if(FlxCollisions.pixelPerfectCheck(Sprite1,Sprite2))
FlxG.collide(Sprite1,Sprite2);

in the update function.

the problem i'm having is that when two (rotated) sprites are moving toward or alongside one another they can sometimes overlap and push through one another.
thanks!
Title: Re: Flixel Power Tools
Post by: photonstorm on Mon, Aug 22, 2011
Could you post up the code please and the assets as they willbe vital to debug this.
Title: Re: Flixel Power Tools
Post by: wonkytonk on Mon, Aug 22, 2011
hey, i pm'd you a link to the project.
thanks
Title: Re: Flixel Power Tools
Post by: Morgan on Fri, Sep 2, 2011
Im pretty sure this is a noob question but here goes:

In your test suite examples such as simple keyboard controls for a platformer, you put the movement logic in the playstate rather than in the player class. Makes sense because you want to have all the code for the example in one class. I managed to shift your keyboard controls example into my player class without too much trouble.

Now im trying to do something similar with the space invaders weapons example. I want my character to shoot a lazer but I cant get it to work, mainly because i cant add(lazer.group) from within the player class. it gives an error "call to a possibly undefined method add".

Am I approaching this wrong?

Title: Re: Flixel Power Tools
Post by: rageace on Sat, Sep 3, 2011
Hi Morgan,
I had a similar problem in one of my games, a solution could be to give the lazer object a copy of the playstate object, (using this), in the constructor, and storing it in an object in the lazer, say called currentPlayState.
You can then do currentPlayState.lazergroup.add(this).
(Providing lazergroup is visible). You would then have that object in case you needed to access other information from the playstate.

Alternatively (I haven't tried this way but it might be food for thought), you might be able to do something with a static function, called addtolazergroup, which you create in your playstate, and then call from your lazer class. I think you might run into problems this way thought with static/non static classes and variables.

I hope I have understood your problem correctly and this might help!

Title: Re: Flixel Power Tools
Post by: photonstorm on Sat, Sep 3, 2011
This topic was covered recently in a thread by test84 called something like "need to redesign" have a look in there, failing that I'll reply later with an example.
Title: Re: Flixel Power Tools
Post by: Morgan on Sat, Sep 3, 2011
Thanks for the replies guys!

I looked up test84's thread and seemed to be able to solve my problem with the simple line
Code: [Select]
FlxG.state.add(arrow.group).

But now i seem to have a conflict within my controls where i can only fire while im jumping. Below is my player code. Ive tried to find the problem myself, ive looked through the powertool files but to no avail. I have the feeling that the problem is staring me right in the face but im hoping a kind soul can enlighten a beginner.

here is the .swf, please dont laugh :) you can also see i need to make my arrow face the right way..

http://test.oid.co.nz/design/morgan_oliver/

thanks in advance.

Code: [Select]
package
{
import org.flixel.*;
import org.flixel.plugin.photonstorm.*;

//Player is the class which hold all the player data, sprites and animations
public class Player extends FlxSprite
{
[Embed(source='data/pit1.png')] protected var ImgPlayer:Class;
[Embed(source='data/arrow2.png')] protected var ImgArrow:Class;

public var JUMP:String = "jump"
public var MOVE:String = "move"
public var FALL:String = "fall"
public var IDLE:String = "idle"

private var arrow:FlxWeapon;

public function Player(X:Number,Y:Number):void
{
super(X, Y);
//Loads the character spritesheet
loadGraphic(ImgPlayer, true, true, 48, 48 );


width = 20;
height = 48;
offset.x = 11;
offset.y = 0;

JUMP = "jump";
MOVE = "move";
FALL = "fall";
IDLE = "idle";

addAnimation(JUMP, [5], 3);
addAnimation(MOVE, [3, 2, 1, 0], 15);
addAnimation(FALL, [4], 6);
addAnimation(IDLE, [0], 2);

arrow = new FlxWeapon("arrow", this, "x", "y");

// Tell the weapon to create 50 bullets using the bulletPNG image.
// The 5 value is the x offset, which makes the bullet fire from the tip of the players ship.
arrow.makeImageBullet(50, ImgArrow, 5);

// Sets the direction and speed the bullets will be fired in
arrow.setBulletDirection(FlxWeapon.BULLET_LEFT, 200);

if (FlxG.getPlugin(FlxControl) == null)
{
FlxG.addPlugin(new FlxControl);
}

//Control the sprite
FlxControl.create(this, FlxControlHandler.MOVEMENT_ACCELERATES, FlxControlHandler.STOPPING_DECELERATES, 1, true, false);
FlxControl.player1.setFireButton("SPACE", FlxControlHandler.KEYMODE_JUST_DOWN, 0, arrow.fire);
FlxControl.player1.setCursorControl(false, false, true, true);
FlxControl.player1.setJumpButton("UP", FlxControlHandler.KEYMODE_JUST_DOWN, 1000, FlxObject.FLOOR, 250, 200);

// Because we are using the MOVEMENT_ACCELERATES type the first value is the acceleration speed of the sprite
// Think of it as the time it takes to reach maximum velocity. A value of 100 means it would take 1 second. A value of 400 means it would take 0.25 of a second.
FlxControl.player1.setMovementSpeed(800, 0, 100, 200, 800, 0);

// Set a downward gravity of 400px/sec
FlxControl.player1.setGravity(0, 360);

FlxG.state.add(arrow.group);
}


override public function update():void
{

if (touching == FlxObject.FLOOR)
{
if (velocity.x != 0)
{
play(MOVE);
}
else
{
play(IDLE);
}
}
else if (velocity.y < 0)
{
play(JUMP);
}
else if ( velocity.y > 0 )
{
play(FALL);
}

super.update();
}

override public function destroy():void
{
// Important! Clear out the plugin otherwise resources will get messed right up after a while
FlxControl.clear();

super.destroy();
}


}
}
Title: Re: Flixel Power Tools
Post by: photonstorm on Sun, Sep 4, 2011
I'm not seeing anything obvious in that class that could cause this. Do you mind posting the complete project up somewhere?
Title: Re: Flixel Power Tools
Post by: Morgan on Sun, Sep 4, 2011
Ok for want of a better place ill put it here. You can see its pretty basic although the level is created with dame so it seems like a lot of code for not much in that respect. Ive gone over it again and am just about ready to start from scratch.

Here is my main class:
Code: [Select]
package
{
import org.flixel.*;

[SWF(width="640", height="480", backgroundColor="#38B0DE")]
[Frame(factoryClass="Preloader")] //Tells Flixel to use the default preloader

//FlixelGame is the main class which creates the swf and initialises the game
public class Main extends FlxGame
{
public function Main()
{
//Loads the menu and turns debugger on
super(640, 480, MenuState, 1, 60, 60);
forceDebugger = true;
}
}
}

Here is my menu class:
Code: [Select]
package
{
import org.flixel.*;

//MenuState is the titlescreen and menu
public class MenuState extends FlxState
{
[Embed(source="data/KidTitleScreen.png")] public var titleImage:Class;

override public function create():void
{
//Loads the titleScreen.png
var splash:FlxSprite = new FlxSprite(0,0,titleImage);
add(splash);

//Adds the text to the screen
var t:FlxText;
t = new FlxText(0,FlxG.height/2-30,FlxG.width,"K I D  I C A R U S  R E D U X");
t.setFormat(null,32,0xFFFFFFFF,"center", 0xFFFF0000 )
add(t);

t = new FlxText(0,FlxG.width/2-60,FlxG.width,"click to play");
t.setFormat(null, 16, 0x00000000,"center")
add(t);

//Shows the custom flixel cursor
FlxG.mouse.show();

}

override public function update():void
{
super.update();

//Hides the cursor and loads the first level when the user clicks
if(FlxG.mouse.justPressed())
{
//FlxG.mouse.hide();
FlxG.switchState(new PlayState_level1());
}
}
}
}

Here is my playstate class:
Code: [Select]
package
{
import org.flixel.*;
import org.flixel.plugin.photonstorm.*;

//PlayState loads level 1
public class PlayState_level1 extends FlxState
{


protected var level1:BaseLevel;
protected var player:Player;
//private var _arrows:ArrowManager;



override public function create():void
{
//Loads the first level
level1 = new Level_Level1(true, onSpriteAddedCallback);

//Sets the camera to follow the player
FlxG.camera.follow(player, 1);

//Sets up the default camera boundaries
FlxG.camera.setBounds(0, 0, level1.mainLayer.width, level1.mainLayer.height);
FlxG.worldBounds = new FlxRect(level1.mainLayer.width, level1.mainLayer.height);
FlxG.worldBounds.x = 0;
FlxG.worldBounds.y = 0;

//_arrows = new ArrowManager();
}

//Initialises the sprites
protected function onSpriteAddedCallback(sprite:FlxSprite, group:FlxGroup):void
{
if (sprite is Player)
{
player = sprite as Player;
}
}

//Called every frame
override public function update():void
{

super.update();

FlxG.collide(player, level1.mainLayer);

if(player.x > FlxG.width)
player.x = 0;
if(player.x < 0)
player.x = FlxG.width;
}
}
}

Here is my player class again. It has some slight changes seen in the swf in my above post to make the arrow fire in the direction running.
Code: [Select]
package
{
import org.flixel.*;
import org.flixel.plugin.photonstorm.*;

//Player is the class which hold all the player data, sprites and animations
public class Player extends FlxSprite
{
[Embed(source='data/pit1.png')] protected var ImgPlayer:Class;
[Embed(source='data/arrow2.png')] protected var ImgArrow:Class;

public var JUMP:String = "jump"
public var MOVE:String = "move"
public var FALL:String = "fall"
public var IDLE:String = "idle"

private var arrow:FlxWeapon;

public function Player(X:Number,Y:Number):void
{
super(X, Y);
//Loads the character spritesheet
loadGraphic(ImgPlayer, true, true, 48, 48 );

//loadGraphic(ImgArrow, false, true);

width = 20;
height = 48;
offset.x = 11;
offset.y = 0;

addAnimation(JUMP, [5], 3);
addAnimation(MOVE, [3, 2, 1, 0], 15);
addAnimation(FALL, [4], 6);
addAnimation(IDLE, [0], 2);

arrow = new FlxWeapon("arrow", this, "x", "y");

// Tell the weapon to create 50 bullets using the bulletPNG image.
// The 5 value is the x offset, which makes the bullet fire from the tip of the players ship.
arrow.makeImageBullet(50, ImgArrow, 5, 0, true);


// Sets the direction and speed the bullets will be fired in
arrow.setBulletDirection(FlxWeapon.BULLET_RIGHT, 200);

if (FlxG.getPlugin(FlxControl) == null)
{
FlxG.addPlugin(new FlxControl);
}

//Control the sprite
FlxControl.create(this, FlxControlHandler.MOVEMENT_ACCELERATES, FlxControlHandler.STOPPING_DECELERATES, 1, true, false);
FlxControl.player1.setFireButton("SPACE", FlxControlHandler.KEYMODE_JUST_DOWN, 0, arrow.fire);
FlxControl.player1.setCursorControl(false, false, true, true);
FlxControl.player1.setJumpButton("UP", FlxControlHandler.KEYMODE_JUST_DOWN, 1000, FlxObject.FLOOR, 250, 200);

// Because we are using the MOVEMENT_ACCELERATES type the first value is the acceleration speed of the sprite
// Think of it as the time it takes to reach maximum velocity. A value of 100 means it would take 1 second. A value of 400 means it would take 0.25 of a second.
FlxControl.player1.setMovementSpeed(800, 0, 100, 200, 800, 0);

// Set a downward gravity of 400px/sec
FlxControl.player1.setGravity(0, 360);

FlxG.state.add(arrow.group);
}


override public function update():void
{

if (touching == FlxObject.FLOOR)
{
if (velocity.x < 0)
{
arrow.setBulletDirection(FlxWeapon.BULLET_LEFT, 200);
play(MOVE);
}
else if(velocity.x > 0)
{
arrow.setBulletDirection(FlxWeapon.BULLET_RIGHT, 200);
play(MOVE);
}
else
{
play(IDLE);
}
}
else if (velocity.y < 0)
{
play(JUMP);
}
else if ( velocity.y > 0 )
{
play(FALL);
}

super.update();
}

override public function destroy():void
{
// Important! Clear out the plugin otherwise resources will get messed right up after a while
FlxControl.clear();

super.destroy();
}


}
}

Here are the classes created by DAME for the map:
Code: [Select]
//Code generated with DAME. http://www.dambots.com

package
{
import org.flixel.*;
public class BaseLevel
{
public var masterLayer:FlxGroup = new FlxGroup;

public var mainLayer:FlxTilemap;

public var boundsMinX:int;
public var boundsMinY:int;
public var boundsMaxX:int;
public var boundsMaxY:int;

public function BaseLevel() { }

public function addSpriteToLayer(type:Class, group:FlxGroup, x:Number, y:Number, angle:Number, flipped:Boolean, scrollX:Number, scrollY:Number, onAddCallback:Function = null):FlxSprite
{
var obj:FlxSprite = new type(x, y);
obj.x += obj.offset.x;
obj.y += obj.offset.y;
obj.angle = angle;
// Only override the facing value if the class didn't change it from the default.
if( obj.facing == FlxObject.RIGHT )
obj.facing = flipped ? FlxObject.LEFT : FlxObject.RIGHT;
obj.scrollFactor.x = scrollX;
obj.scrollFactor.y = scrollY;
group.add(obj);
if(onAddCallback != null)
onAddCallback(obj, group);
return obj;
}

virtual public function addSpritesForLayerGroup2Layer1(onAddCallback:Function = null):void { }
}
}

and:
Code: [Select]
//Code generated with DAME. http://www.dambots.com

package
{
import org.flixel.*;
public class Level_Level1 extends BaseLevel
{
//Embedded media...
[Embed(source="mapCSV_Group1_Map1.csv", mimeType="application/octet-stream")] public var CSV_Group1Map1:Class;
[Embed(source="data/placeholderTiles.png")] public var Img_Group1Map1:Class;

//Tilemaps
public var layerGroup1Map1:FlxTilemap;

//Sprites
public var Group2Layer1Group:FlxGroup = new FlxGroup;


public function Level_Level1(addToStage:Boolean = true, onAddSpritesCallback:Function = null)
{
// Generate maps.
layerGroup1Map1 = new FlxTilemap;
layerGroup1Map1.loadMap( new CSV_Group1Map1, Img_Group1Map1, 32,32, FlxTilemap.OFF, 0, 1, 1 );
layerGroup1Map1.x = 0.000000;
layerGroup1Map1.y = 0.000000;
layerGroup1Map1.scrollFactor.x = 1.000000;
layerGroup1Map1.scrollFactor.y = 1.000000;

//Add layers to the master group in correct order.
masterLayer.add(layerGroup1Map1);
masterLayer.add(Group2Layer1Group);


if ( addToStage )
{
addSpritesForLayerGroup2Layer1(onAddSpritesCallback);
FlxG.state.add(masterLayer);
}

mainLayer = layerGroup1Map1;

boundsMinX = 0;
boundsMinY = 0;
boundsMaxX = 640;
boundsMaxY = 640;

}

override public function addSpritesForLayerGroup2Layer1(onAddCallback:Function = null):void
{
addSpriteToLayer(Player, Group2Layer1Group , 194.000, 527.000, 0.000, false, 1, 1, onAddCallback );//"pit"
}


}
}

sorry about the long post. and once again thanks for your help.
Title: Re: Flixel Power Tools
Post by: photonstorm on Sun, Sep 4, 2011
Can you zip up the project folder (include the flash develop project) and upload that? Then I can compile it, test it and see. Cheers.
Title: Re: Flixel Power Tools
Post by: Morgan on Sun, Sep 4, 2011
Thank you. i couldnt seem to attach a zip here so i sent it to your gmail address. hope it works.

morgan
Title: Re: Flixel Power Tools
Post by: Morgan on Tue, Sep 6, 2011
so after some playing and reading test84s thread http://forums.flixel.org/index.php/topic,5034.0.html (http://forums.flixel.org/index.php/topic,5034.0.html) i discovered my problem wasnt that my character could only fire while jumping, it was that it couldnt fire while that close to the bottom of the world bounds. if you check this new swf. once you climb up a bit you can fire away no problem.
swf:
http://test.oid.co.nz/design/morgan_oliver/

space = jump
X = fire

so my question now is why is being near the bottom stopping the fire function if FlxWeapon?
Title: Re: Flixel Power Tools
Post by: photonstorm on Tue, Sep 6, 2011
Have you updated the FlxWeapon bounds too? I'm on my iPhone so don't have code to hand, but there is an internal bullet bounds used which may need expanding?
Title: Re: Flixel Power Tools
Post by: Morgan on Tue, Sep 6, 2011
YES! Thanks heaps photon!

once i added a FlxRect as bullet bounds to match the size of my map it all worked fine. Wow ive learnt heaps solving this, thanks. Now i just have to get my bullet rotated the correct way depending on which direction im firing. i also want to kill the bullet if it collides with the main layer of my map. any ideas about this?

the code i added:
Code: [Select]
protected var myBulletBounds:FlxRect;

myBulletBounds = new FlxRect(0, 0, 640, 640);
arrow.setBulletBounds(myBulletBounds);
Title: Re: Flixel Power Tools
Post by: photonstorm on Tue, Sep 6, 2011
For rotation = get the bullet fired from weapon.currentBullet and set the angle on it. Or wait for the 1.9 update :)

For collision it's easy, just do FlxG.collide against the tilemap and weapon.group, then kill the bullet.
Title: Re: Flixel Power Tools
Post by: Kurai on Sat, Oct 8, 2011
Hi there,
I'm using FlxWeapon to get my little sprite fire a machine gun. I tried to include all the code into an FlxGroup, because I'm planning to generate different kinds of player sprites with different weapons later on.
The problem is, I cannot manage to make my sprite fire. Nothing just happens, no matter what I do.
I kinda copied the asteroids demo, because my game is going to have a similar control system.
Here is my Player class:
Code: [Select]
package
{
import org.flixel.*;
import org.flixel.plugin.photonstorm.*;

public class Player extends FlxGroup
{
[Embed(source="img/spad.png")] private var ImgSpad:Class;
public var machineGun: FlxWeapon;
public var playerSprite: FlxSprite;

public function Player()
{
playerSprite = new FlxSprite(680,220,ImgSpad)
//playerSprite.antialiasing=true;

//configure player weapon
machineGun = new FlxWeapon("machineGun", playerSprite, "x", "y");
machineGun.makePixelBullet(40, 2, 2, 0xff00e700, 100, 6);
machineGun.setBulletSpeed(200);

// Enable the plugin - you only need do this once (unless you destroy the plugin)
if (FlxG.getPlugin(FlxControl) == null)
{
FlxG.addPlugin(new FlxControl);
}

//now sets the controls with the awesome plugin!
//We want the motion of the plane to accelerate and decelerate smoothly ...
FlxControl.create(playerSprite, FlxControlHandler.MOVEMENT_ACCELERATES, FlxControlHandler.STOPPING_DECELERATES, 1, false, false);
FlxControl.player1.setRotationType(FlxControlHandler.ROTATION_ACCELERATES, FlxControlHandler.ROTATION_STOPPING_DECELERATES);
//sets the rotation speed
FlxControl.player1.setRotationSpeed(400, 400, 200, 400);
//Set the rotation keys - the default is to use LEFT/RIGHT arrows, so we don't actually need to pass anything here! but they can be whatever you need
FlxControl.player1.setRotationKeys();
// This is what fires the actual bullets (pressing SPACE) at a rate of 1 bullet per 50 ms, hooked to the lazer.fire method
FlxControl.player1.setFireButton("SPACE", FlxControlHandler.KEYMODE_PRESSED, 50, machineGun.fireFromParentAngle);
add(machineGun.group);
add(playerSprite);
}
}
}

What I'm doing wrong?
Title: Re: Flixel Power Tools
Post by: photonstorm on Sat, Oct 8, 2011
Set the bulletBounds on the weapon, on quick glance it appears to be missing and could be causing this.
Title: Re: Flixel Power Tools
Post by: Kurai on Sat, Oct 8, 2011
I did it, by adding the instruction
Code: [Select]
machineGun.setBulletBounds(new FlxRect(0,0,3000,300));(the same as the world bounds) but still, it's not working.
Puzzled.
Title: Re: Flixel Power Tools
Post by: test84 on Sat, Oct 8, 2011
why are you calling machineGun.fireFromParentAngle instead of machineGun.fire() ?
Title: Re: Flixel Power Tools
Post by: Kurai on Sat, Oct 8, 2011
Well, because my player sprite rotates and I need the bullet to be fired at the correct angle.
The example is almost exactly the same you can find in the Flixel Power Tools, it's the Asteroids one.
Except mine isn't working, of course -_-
Title: Re: Flixel Power Tools
Post by: photonstorm on Sat, Oct 8, 2011
I assume that "Player" has been added to the FlxState and is visible and working?
Title: Re: Flixel Power Tools
Post by: Kurai on Sat, Oct 8, 2011
Yeah, exactly. Player is added to the Playstate, is visible and working. Only the bullet aren't. :(

Here is the playstate FYI:

Code: [Select]
package
{
import flash.geom.Rectangle;
import org.flixel.*;
import org.flixel.plugin.photonstorm.*;

public class PlayState extends FlxState
{
private var _player:Player;
[Embed(source="img/sky.png")] private var ImgSky:Class;

override public function create():void
{
//creates the background
FlxG.bgColor=0xFF70BCFF;
FlxG.worldBounds=new FlxRect(0,0,3000,300);


//creates the player
_player = new Player();
add(_player);

FlxG.camera.follow(_player.playerSprite);
//FlxG.camera.deadzone = new FlxRect(0,0,120,120);
//FlxG.camera.antialiasing=true;
FlxG.camera.bounds=FlxG.worldBounds;
}
}
}
Title: Re: Flixel Power Tools
Post by: test84 on Sun, Oct 9, 2011
I've read your code several times already, if you can, upload your project with all needed dependencies and so, and I'll tinker with it.
Title: Re: Flixel Power Tools
Post by: Kurai on Mon, Oct 10, 2011
You can download the entire project here: http://dl.dropbox.com/u/624344/src.zip
Thank you!
Title: Re: Flixel Power Tools
Post by: Kurai on Mon, Oct 10, 2011
Now that's strange. I tried compiling again and now everything works.
Just two questions: obviously when the bullets get off screen they are automatically killed, am I right?
And when I'm going to check collisions I still need to kill the bullet which made the collision, right?
(Sorry if these are stupid questions, I'm still a bit of a newbie ;))
Title: Re: Flixel Power Tools
Post by: photonstorm on Mon, Oct 10, 2011
No bullets don't get killed when off-screen. If you need that I'd set a lifespan on them (or kill them on collision)
Title: Re: Flixel Power Tools
Post by: photonstorm on Mon, Oct 10, 2011
Ok version 1.9 final has been released tonight. It's now live on Github. Lots of changes and updates, mostly bug fixes and tweaks here and there. I'm shattered so I'll do a proper post about it tomorrow :) But if you used FlxBar or FlxWeapon in the past there are several nice updates/patches in there now.
Title: Re: Flixel Power Tools
Post by: photonstorm on Tue, Oct 11, 2011
(http://c251763.r63.cf3.rackcdn.com/wp-content/uploads/2011/10/FlxBarTest5.png)

Iím pleased to announce that version 1.9 of the Flixel Power Tools is now live. This release was never about adding big sweeping new features. Instead I focused on maintenance and making it as solid as possible. Lots of the classes have been expanded and piles of bugs and edge-case oddities stomped.

Updates include: Pixel perfect collision now works 100% even when both sprites are rotating.The new FlxKongregate provides a solid hook into the Kongregate API with all of their advanced features. FlxWeapon gained the ability for pre-fire and post-fire events, sound support, random factors, parent direction firing support, bullet elasticity, bullet counters and bullet lifespans. The control handler had some gravity issues squashed and new isPressedUp/Down/Left/Right methods added. FlxBar had a complete overhaul and is even more flexible now, with 2 new RPG style examples included: A Zelda-like life counter and an RPG Experience bar. Plus there are new tests in the Test Suite including a destructible terrain example.

Release 2.0 will change everything

1.9 is the final release before I start on 2.0. Version 2 will be a significant overhaul to both the structure and classes available. Iím afraid that any code using Flixel Power Tools v1.x will not be forward compatible with 2.0 and will require extensive re-factoring. So if you are mid-game now and using FPT then please remain at version 1.9 until you start a new project.

Why the change? Basically the Power Tools have got too big! It was fine having them all in one place when I started this journey, but as more and more features have been added the structure no longer works. So I intend to split them up into categories such as: input, display, effects, sound, fonts, gui, etc. I wonít be removing any classes, but I may split some up into more manageable chunks Ė especially the more heavy-weight ones such as FlxControl and FlxWeapon.

Development on 2.0 has started and will live under a new í2.0′ branch in github. Do not randomly import this release into a current game! But feel free to check it out, suggest ideas and report bugs. Iím aiming to release 2.0 in the New Year, after which Iíll then make a call if I want to port all of this to html5 or carry on my work on a Stage3D renderer for Flixel.
Title: Re: Flixel Power Tools
Post by: test84 on Tue, Oct 11, 2011
Thanks for all the effort, hope we can do stuff in return.
Title: Re: Flixel Power Tools
Post by: foosety on Fri, Oct 14, 2011
Hey is flxScreenGrab only for local use? I tried grabbing a picture when my swf was online but no luck. Any suggestions?
Title: Re: Flixel Power Tools
Post by: photonstorm on Fri, Oct 14, 2011
Correct. It'd be easy enough to hook to work online - you'd have to ensure that the grab function is the recipient of the KeyboardEvent directly - it can't be passed through another function (that is what fires the sandbox error)
Title: Re: Flixel Power Tools
Post by: foosety on Sat, Oct 15, 2011
Correct. It'd be easy enough to hook to work online - you'd have to ensure that the grab function is the recipient of the KeyboardEvent directly - it can't be passed through another function (that is what fires the sandbox error)

You're right whenever I put it into another function it fires a sandbox error. I attached it to my onClick function from one of my FlxButtonPlus objects which works fine. However now I've run into another dilemma. I'm trying to hide the "take picture" buttons when the user clicks on "take picture". I place picBtn.visible = false; before the screenGrab function in my onClick function, but the screen grab always seems to take the picture before the buttons are hidden. Any ideas for this?
Title: Re: Flixel Power Tools
Post by: photonstorm on Sun, Oct 16, 2011
The problem is the call to visible = false doesn't take effect until the next flixel render, but the screen grab event happens immediately. My suggestion would be to not have the "take picture" buttons as part of flixel at all. Insert them as normal display objects on-top of your game, and then the grab function can hide them before the grab.
Title: Re: Flixel Power Tools
Post by: licebeam on Tue, Oct 18, 2011
I'm having a hard time with bullet collision,

this is my update function, it seems as though using current bullet is out of the question with high rate of fire, because it counts the last bullet fired, so if there is two or more on the screen the don't, kill();

Code: [Select]
override public function update() :void
{
this.immovable = true;

if (FlxG.collide(this, PlayState.lazerbeam.group))
{
healthPoints -= 1;
PlayState.lazerbeam.currentBullet.kill();
play("walk");

}
if (healthPoints == 0)
{
this.kill();
}
}

If there is any way to solve this please let me know, I'm new to this.
Title: Re: Flixel Power Tools
Post by: Alextfish on Wed, Oct 19, 2011
The more normal way to do it is to have your update function call something like

Code: [Select]
FlxG.collide(object1, PlayState.lazerbeam.group, objectHitLaser)
and then have another function

Code: [Select]
public function objectHitLaser(object1:FlxSprite, laserObject:FlxSprite) {
  object1.hurt(1);
  laserObject.kill();
}

Note that FlxSprites have a health variable already, and a hurt(amountOfDamage) function which will take care for you of things like decreasing health and calling kill() when it runs out, so you don't have to do that yourself.
Title: Re: Flixel Power Tools
Post by: test84 on Wed, Oct 19, 2011
I'm having a hard time with bullet collision,

this is my update function, it seems as though using current bullet is out of the question with high rate of fire, because it counts the last bullet fired, so if there is two or more on the screen the don't, kill();

Code: [Select]
override public function update() :void
{
this.immovable = true;

if (FlxG.collide(this, PlayState.lazerbeam.group))
{
healthPoints -= 1;
PlayState.lazerbeam.currentBullet.kill();
play("walk");

}
if (healthPoints == 0)
{
this.kill();
}
}

If there is any way to solve this please let me know, I'm new to this.

umm, don't you have to call super.update() before everything?
Title: Re: Flixel Power Tools
Post by: photonstorm on Wed, Oct 19, 2011
You can call it at the start or end of the update function, doesn't really matter too much (sometimes you need it in a specific place, but it's rare). But it does appear to be missing from the above code entirely.
Title: Re: Flixel Power Tools
Post by: licebeam on Wed, Oct 19, 2011
Thanks guys, it works now and I'm new to this so I forget things like super.update(); =(

I have another question.

Would it be inappropriate to use flxweapon as a particle emitter?
The code seems perfect for what I want to do, is there any reason I wouldn't want to?

An example would be, I have a breakable door and I want the player to have some sort of feedback when it's hit, my first reaction was to try and make it spit back some particles like a spark or pieces breaking off kinda.
Title: Re: Flixel Power Tools
Post by: Morgan on Thu, Oct 20, 2011
FlxEmitter (http://flashgamedojo.com/wiki/index.php?title=Emitter_Creation_(Flixel))
Title: Re: Flixel Power Tools
Post by: photonstorm on Thu, Oct 20, 2011
licebeam - I'd use an FlxEmitter for this really
Title: Re: Flixel Power Tools
Post by: licebeam on Thu, Oct 20, 2011
Ah, thanks again guys, I got an emitter working!

I was fiddling around with using flx weapon to do it before you replied and it just isn't the same haha! =)
Title: Re: Flixel Power Tools
Post by: datorum on Mon, Oct 24, 2011
first of all, thx a lot for this great library.

now my question, am I doing something totally wrong or using the wrong version together?
I am using flixel 2.55 and put Flixel Power Tools 1.9 into the plugin folder. Now I try to use the FlxButtonPlus, which raises a lot of errors due to the fact that FlxGroup is derived from FlxBasic, which doesn't have x,y,width,height, etc. anymore. (FlxButtonPlus is derived from FlxGroup).

Code: [Select]
\src\com\photonstorm\flixel\FlxButtonPlus.as(113): col: 4 Error: Access of undefined property x.
EDIT:
sorry, I had an old version of Flixel Power Tools also in the source directory ;)  ;D
Title: Re: Flixel Power Tools
Post by: photonstorm on Mon, Oct 24, 2011
I was going to say - it shouldn't be in com\photonstorm at all! It should be in org\flixel\plugin\photonstorm :)
Title: Re: Flixel Power Tools
Post by: datorum on Mon, Oct 24, 2011
photon, just found out that FlxExtendedButton doesn't support the color/alpha properties of the sprites used for the button images.
I don't know if it is intentional or not, if not, here you find the "updated" code - was really hard  ;)
http://forums.flixel.org/index.php/topic,5364.0.html
Title: Re: Flixel Power Tools
Post by: datorum on Tue, Oct 25, 2011
maybe a bug report, what exactly does the code "if (_pressed) ..." perform?

Code: [Select]
public function loadGraphic(normal:FlxSprite, highlight:FlxSprite):void
{

buttonNormal.pixels = normal.pixels;
buttonHighlight.pixels = highlight.pixels;


width = buttonNormal.width;
height = buttonNormal.height;

if (_pressed)
{
buttonNormal.visible = false;
}
else
{
buttonHighlight.visible = false;
}
}


I have this function:
Code: [Select]
public function setEarned(Earned:Boolean):void
{
earned = Earned;

if (earned)
{
loadGraphic(spriteEarned, spriteEarnedHigh);
}
else
{
loadGraphic(spriteNotEarned, spriteNotEarnedHigh);
}

}

which called from the constrcutor performs fine, but called in update() results in the highlighted sprite disappearing.
I commented out "if (_pressed)" and now it works.
Title: Re: Flixel Power Tools
Post by: photonstorm on Tue, Oct 25, 2011
_pressed is just an internal var that toggles when the button is held down or not (i.e. pressed) and swaps between two images accordingly. To be honest this class is going in 2.0 to be replaced by a proper UI class.
Title: Re: Flixel Power Tools
Post by: datorum on Mon, Oct 31, 2011
FlxButtonPlus - labels don't have scrollfactor set properly, cause usually you won't need it ;) but I have a scrolling level in the background :)

Code: [Select]
if (Label != null)
{
textNormal = new FlxText(X, Y + 3, Width, Label);
textNormal.setFormat(null, 8, 0xffffffff, "center", 0xff000000);
textNormal.scrollFactor.x = 0; //added
textNormal.scrollFactor.y = 0; //added

textHighlight = new FlxText(X, Y + 3, Width, Label);
textHighlight.setFormat(null, 8, 0xffffffff, "center", 0xff000000);
textHighlight.scrollFactor.x = 0; //added
textHighlight.scrollFactor.y = 0; //added

add(textNormal);
add(textHighlight);
}
Title: Re: Flixel Power Tools
Post by: caladan21ph on Thu, Nov 3, 2011
So I was trying out the code for the sprite rotation in the power tools, and somehow setRotationSpeed and the other setRotation stuff does not appear in my Flash Develop(the little notes that pop up when typing code). This goes the same for starFieldFx.create() . Is this a problem with my flash develop or a version of my powertools? The thing is, the code works if I cut and paste it from the source. Thanks!
Title: Re: Flixel Power Tools
Post by: photonstorm on Thu, Nov 3, 2011
Sounds to me like you don't have your Project set-up correctly in FlashDevelop. It will only auto-complete source code it has direct access to. Have you created a project, put flixel and the tools into your src folder, etc? If you've done all this and SOME stuff auto-completes but not all, then you might just need to rebuild the Intrinsic cache - it's on a drop-down menu in FD somewhere, have a hunt!
Title: Re: Flixel Power Tools
Post by: Alextfish on Thu, Nov 3, 2011
You may also need to make sure every file in your source code includes
Code: [Select]
import org.flixel.plugin.photonstorm.*;
Title: Re: Flixel Power Tools
Post by: caladan21ph on Thu, Nov 3, 2011
Hmm. I did the classpath thing for flixel in one of the beginner tutorials. Ok, I'll try copying the whole flixel folder into the src.
Title: Re: Flixel Power Tools
Post by: Apanda on Fri, Nov 4, 2011
I got a weird issue with FlxScrollZone. After some time it stops scrolling. The time depends on the speed I guess. I first wanted to make scroll speed up with adding this: speed = speed + 0.001; to update. But after 12 seconds scrolling stopped. So I thought it's all about speeding up and changed it to just 15 (private var speed:Number = 15;). But it stops anyway.  That's the code:
FlxScrollZone.add(back, new Rectangle(0, 0, back.width, back.height), -speed, 0, true);
back is the name of my scrolling background sprite.
back = new FlxSprite(0, 0, backImg);
Any ideas why this is happening?
Title: Re: Flixel Power Tools
Post by: antigirl on Thu, Dec 1, 2011
how do i make my player crouch,
looking at the platform example : http://www.photonstorm.com/archives/2247/flash-game-dev-tip-12-building-a-retro-platform-game-in-flixel-part-1

and the controlHandler class, how are left/right associate with the walk movement?
could i technically use firebutton to call any key/action

i.e:   
        addAnimation("duck", [3], 0, false);
   FlxControl.player1.setFireButton("SPACE", FlxControlHandler.KEYMODE_PRESSED, 250, nothing);

        public function nothing():void
    {
     play("duck");
    }



that doesnt work !?
Title: Re: Flixel Power Tools
Post by: test84 on Thu, Dec 1, 2011
how do i make my player crouch,
looking at the platform example : http://www.photonstorm.com/archives/2247/flash-game-dev-tip-12-building-a-retro-platform-game-in-flixel-part-1

and the controlHandler class, how are left/right associate with the walk movement?
could i technically use firebutton to call any key/action

i.e:   
        addAnimation("duck", [3], 0, false);
   FlxControl.player1.setFireButton("SPACE", FlxControlHandler.KEYMODE_PRESSED, 250, nothing);

        public function nothing():void
    {
     play("duck");
    }



that doesnt work !?
If you want  to use FPT's FlxControl, You achieve it via "FlxCont.create", look at this:
Code: [Select]
FlxControl.create(this, FlxControlHandler.MOVEMENT_ACCELERATES, FlxControlHandler.STOPPING_DECELERATES, 1, true, false);
Title: Re: Flixel Power Tools
Post by: Raf on Thu, Dec 22, 2011
I got a weird issue with FlxScrollZone. After some time it stops scrolling. The time depends on the speed I guess. I first wanted to make scroll speed up with adding this: speed = speed + 0.001; to update. But after 12 seconds scrolling stopped. So I thought it's all about speeding up and changed it to just 15 (private var speed:Number = 15;). But it stops anyway.  That's the code:
FlxScrollZone.add(back, new Rectangle(0, 0, back.width, back.height), -speed, 0, true);
back is the name of my scrolling background sprite.
back = new FlxSprite(0, 0, backImg);
Any ideas why this is happening?
Got the same problem. Anybody know why this is happening? I'm really breaking my head over it (not to mention wasting an incredible amount of time and the fun of making games with Flixel)
Title: Re: Flixel Power Tools
Post by: test84 on Thu, Dec 22, 2011
Question about your CoinExplosion demo, why you are setting drag and elasticity at onEmit and why not setting them in constructor? I can understand playing the animation on onEmit, since it may preserve some performance maybe it won't work, but why the other two?

BTW, it's GREAT and works like a charm in my game!

-test84
Title: Re: Flixel Power Tools
Post by: photonstorm on Thu, Dec 22, 2011
I like to keep as little code as possible in a class constructor. There's no reason why it can't go in there though, just personal preference.
Title: Re: Flixel Power Tools
Post by: John Hutchinson (Johntron247) on Tue, Dec 27, 2011
I'm the same way.  I like to put things that will only ever need to be done once in the constructor.  Everything else I put in an overloaded revive() - or maybe create a method called reset() or something, if special parameters and such are needed.  I do that because somewhere down the road I'm probably going to want to recycle or reuse your objects. Having the overloaded revive() method, or a custom reset() function that gets called along with revive(), just makes that easier.  If I left that stuff in the constructor then I'm probably going to have to cut/paste it into the revive() function anyway, so when I create a new object class I try to just put it in that function right from the start.  That also reduces the possibility of forgetting something that needs to be done whenever you do recycle/reuse (not just once when the thing is created), or messing something up when I need to move the code around.
Title: Re: Flixel Power Tools
Post by: test84 on Sat, Dec 31, 2011
I'm the same way.  I like to put things that will only ever need to be done once in the constructor.  Everything else I put in an overloaded revive() - or maybe create a method called reset() or something, if special parameters and such are needed.  I do that because somewhere down the road I'm probably going to want to recycle or reuse your objects. Having the overloaded revive() method, or a custom reset() function that gets called along with revive(), just makes that easier.  If I left that stuff in the constructor then I'm probably going to have to cut/paste it into the revive() function anyway, so when I create a new object class I try to just put it in that function right from the start.  That also reduces the possibility of forgetting something that needs to be done whenever you do recycle/reuse (not just once when the thing is created), or messing something up when I need to move the code around.

Yes I'm with you on it, in other words it makes the class more reusable but since those coins were for that demo and only that, I wondered why he separated them.
Title: Re: Flixel Power Tools
Post by: LoveMeDo on Fri, Feb 17, 2012
Hi Guys,

i recently did the "return fire" tutorial and i totally loved it. Especially the awesome FlxVelocity feature!

So i was trying to use this class for shooting homing missiles at enemies.

Unfortunately i don't know how to do this, because my EnemyManager (which we added in the create() function) is a FlxGroup and not a FlxSprite, which would be needed for FlxVelocity to work properly.

I know, i could skip the EnemyManager, but i really want to keep it for performance reasons.

I'm totally lost and every help is highly appreciated!

Sincerely

LoveMeDo
Title: Re: Flixel Power Tools
Post by: test84 on Sat, Feb 18, 2012
Is it a FlxGroup that has a FlxSprite inside it? If yes, access the FlxSprite with the FlxGroup, i.e. FlxGroup.FlxSprite.

I'm not sure if I understood you right but I sense that EnemyManager should be some kind of class that manages other things around and apparently don't usually have visual representations and thus are not FlxSprites. They usually have some FlxSprites inside them and they control their behavior someway. (Of course I'm trying to talk in context of your game)

So more light on the problem would definitely help.
Title: Re: Flixel Power Tools
Post by: LoveMeDo on Sun, Feb 19, 2012
Hi test84,
thank you for your reply!

As you said, the enemymanager class is a flxgroup class, which handles the recycling of enemies (flxsprite).
The problem is, that im just declaring the enemymanager class in my registry and adding it in my create function. So i don't know how to adress a single enemy in the flxvelocity call.

Adding the Enemy (flxsprite) class to the registry didn't work either.

I was trying this with the "moveToObject" method btw.

I think, that the "moveToPoint" method could also work, if i could figure out how to pass the x,y coordinates of the enemies to the method.
But sadly, i got stuck on this one too  :'(


Best regards

lovemedo
Title: Re: Flixel Power Tools
Post by: Chelnok on Tue, Feb 21, 2012
I'm feeling lazy today, and probably tomorrow :) ..so if anyone have done collecting bullets and / or reload system with Great FlxWeapon, drop some code here or give some tips how it would be smart to do.

Edit:
I found this one:
http://forums.flixel.org/index.php/topic,5552.msg31281.html#msg31281

Looks fine, but another solution is always wellcome.
Title: Re: Flixel Power Tools
Post by: test84 on Tue, Feb 21, 2012
Hi test84,
thank you for your reply!

As you said, the enemymanager class is a flxgroup class, which handles the recycling of enemies (flxsprite).
The problem is, that im just declaring the enemymanager class in my registry and adding it in my create function. So i don't know how to adress a single enemy in the flxvelocity call.

Adding the Enemy (flxsprite) class to the registry didn't work either.

I was trying this with the "moveToObject" method btw.

I think, that the "moveToPoint" method could also work, if i could figure out how to pass the x,y coordinates of the enemies to the method.
But sadly, i got stuck on this one too  :'(


Best regards

lovemedo

So make a function call in your enemy manager class and based on the situation you want, do whatever you want with that enemy. You have to explain more about your problem, why do you want to change velocity of that specific enemy? Is it because he collided with something? Is it because he "saw" the player? whatever it is, you can detect it and call a function on him. i.e. if you collide two objects, the call back function gives you access to those that collided as parameters to the callback function.

(As the problem is no longer Flixel Power Tools related, I suggest we continue this in a separate topic)

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

I'm feeling lazy today, and probably tomorrow :) ..so if anyone have done collecting bullets and / or reload system with Great FlxWeapon, drop some code here or give some tips how it would be smart to do.

Edit:
I found this one:
http://forums.flixel.org/index.php/topic,5552.msg31281.html#msg31281

Looks fine, but another solution is always wellcome.

I'm using the code I put there for a while and haven't noticed anything. Rule of the thumb is, you have to have a pool of bullets and each time you want a new bullet, get it out of that pool with recycle/getFirstAvailabe/getFirstXXX methods, so you won't be "new"-ing bullets on each shoot.

It's performance is not bad because I'm using it in my machine gun with no problem so far.

Code is fairly simple though.
Title: Re: Flixel Power Tools
Post by: LoveMeDo on Thu, Feb 23, 2012
First of all, thank you for taking your time and your patience, test84. Really appreciated.

In a nutshell, what I want is a homing missile (as a weapon power-up) for the playing character.
This is part of my EnemyManager Class (from Phontonstorm's shooter tutorial)

Code: [Select]
package 
{
import org.flixel.*;
import flash.utils.getTimer;
import org.flixel.plugin.photonstorm.*;


public class EnemyManager extends FlxGroup
{
private var lastReleased:int = 1;
private var releaseRate:int;
public var enemy:Enemy;

public function EnemyManager()
{
super();

for (var i:int = 0; i < 40; i++)
{
add(new Enemy);
}
}

public function release():void
{
enemy = Enemy(getFirstAvailable());

if (enemy)
{
enemy.launch();
}
}

override public function update():void
{
super.update();

releaseRate += 1;


if (releaseRate > 120)
{
resetRelease();
release();

}
}

Part of the EnemyClass
Code: [Select]
package 
{
import org.flixel.*;
import org.flixel.plugin.photonstorm.*;

public class Enemy extends FlxSprite
{
[Embed(source = "D:/Game_Dev/FlashDevelop/PSTuT/PSTut/lib/space-baddie.png")] private var enemyPNG:Class;
[Embed(source = "D:/Game_Dev/FlashDevelop/PSTuT/PSTut/lib/space-baddie2.png")] private var enemy2PNG:Class;

private var randomEnemy:int; // Holds the randomly generated integer used to determine which type of enemy spawns
public var randomEnemyTag:String; // Holds the string used to tell PlayState what enemy to spawn
public var scoreValue:uint;

private var fireTime:FlxDelay;
private var willFire:Boolean = false;


public function Enemy()
{
super(0, 0);

exists = false;
}

public function launch():void
{
x = FlxG.width;
y = Math.random() * (FlxG.height - 100) + 50;

randomEnemy = FlxG.random() * 0; // Generates a random integer 0-1

if (randomEnemy == 0)
{
exists = true;
loadGraphic(enemyPNG, false, false, 80, 80);
velocity.x = -150;
randomEnemyTag = "EnemyOne";
scoreValue = 10;

health = 1;
}
else if (randomEnemy == 1)//
{
exists = true;
loadGraphic(enemy2PNG, false, false, 80, 80);
velocity.x = -100;
randomEnemyTag = "EnemyTwo";
scoreValue = 50;

health = 3;
}

Part of the RegistryClass
Code: [Select]
package 
{
public class Registry
{
public static var ship:Ship;
public static var bullets:BulletManager;

public static var enemies:EnemyManager;
public static var enemyBullets:EnemyBulletManager;

public static var bosses:BossManager;
public static var bossBullets:BossBulletManager;

public static var fx:Fx;
public static var hud:HUD;
public static var powerUps:PowerUpManager;

public function Registry()
{
}

public static function init():void
{
ship = new Ship();
bullets = new BulletManager();

enemies = new EnemyManager();
enemyBullets = new EnemyBulletManager();

bosses = new BossManager();
bossBullets = new BossBulletManager();

fx = new Fx();
hud = new HUD();
powerUps = new PowerUpManager();
}

Now implementing the enemy's homing missiles while shooting at the playable character was pretty easy (s. Photonstorm's tutorial)
Code: [Select]
public function enemyFire(bx:int, by:int):void
{
x = bx;
y = by;

FlxVelocity.moveTowardsObject(this, Registry.ship, speed);

exists = true;
}

ship is the playable character.

I just can't use FlxVelocity by swopping the parameters like this:  FlxVelocity.moveTowardsObject (ship, Registry.enemies, speed). because Registry.enemies is not a FlxSprite as presupposed to use FlxVelocity. So, how can my ship have homing missiles without discard the EnemyManager Class?

Hope this helps und have a great day,
lovemedo
Title: Re: Flixel Power Tools
Post by: test84 on Fri, Feb 24, 2012
Assuming that you want to shoot missile at one enemy shop, you have to target one specific ship. How do you select one sheep to shoot at? If it's under mouse click, use mouse, if it's nearest enemy, do a method call and make that ship special from the rest, or any other way that you have for your game logic. Then with that ship in hand, pass it to this function of yours.

If you want to shoot them all, either have a loop and call this function for each member of your enemies group or have a method to do it for you. (or extend that method if that decreases performance).

There are several other ways I can think of, but let's not get ahead of ourselves here.
Title: Re: Flixel Power Tools
Post by: 7heSAMA on Sun, Feb 26, 2012
Hey Photonstorm, if you're reading this, I absolutely love the power tools and the flash dev tips, thanks so much for taking the time to make them. :D

...

...

ok yes this is about more than simple thanks. I was wondering if anyone knew how to apply the GlitchFX to FlxText. Of course I could make image text files, but besides being really memory-intense I would like to be able to dynamically generate the text, eg have the player input the name and then use that in glitched-up radio dialogue. Only idea I had was that it might be possible to generate image files from text in-game but that sounds pretty reasource-heavy, too, and I'm not even sure it's possible (so far it looks like "no"...).

Relevant (http://www.youtube.com/watch?v=jLx0BCjtxx8).
Title: Re: Flixel Power Tools
Post by: photonstorm on Mon, Feb 27, 2012
FlxText just creates an image file anyway, if you look at it you'll see it extends FlxSprite and the "text" is stored in the pixels value. So basically I'm pretty sure Glitch will just work out of the box with it.
Title: Re: Flixel Power Tools
Post by: LoveMeDo on Mon, Feb 27, 2012
test84,

Thank you for your great advice. I'm totally new to coding. I will try it out and let you know how it went.

Cheers,
lovemedo!
Title: Re: Flixel Power Tools
Post by: test84 on Mon, Feb 27, 2012
Glad I could be of any help.
Title: Re: Flixel Power Tools
Post by: 7heSAMA on Tue, Feb 28, 2012
FlxText just creates an image file anyway, if you look at it you'll see it extends FlxSprite and the "text" is stored in the pixels value. So basically I'm pretty sure Glitch will just work out of the box with it.

That's awesome! I didn't even bother to try I admit, assumed it wouldn't work. Thanks a ton, I'll check it out ASAP!

EDIT: It does work! This:

Code: [Select]
var title:FlxSprite;
var glitch:GlitchFX;

override public function create():void
{
if (FlxG.getPlugin(FlxSpecialFX) == null)
{
FlxG.addPlugin(new FlxSpecialFX);
}

var txt = new FlxText(0, (FlxG.height / 4), FlxG.width, "Foxline");
txt.setFormat(null, 24, 0xFFFFFFFF, "center");

glitch = FlxSpecialFX.glitch();

title = glitch.createFromFlxSprite(txt, 2, 2);

glitch.start(1);

this.add(title);
}

gets me some nice, flickering text. No code changes. Cool! Thanks again, photonstorm.
Title: Re: Flixel Power Tools
Post by: frth on Wed, Mar 7, 2012
I would like that my spaceship could fire at sametime two types of weapons - laser and rocket, but problem that I can use only one FireButton. So if I write:
Code: [Select]
FlxControl.player1.setFireButton("CONTROL", FlxControlHandler.KEYMODE_PRESSED, 50, lazer.fireFromParentAngle);
FlxControl.player1.setFireButton("SPACE", FlxControlHandler.KEYMODE_PRESSED, 50, rocket.fireFromParentAngle);
Then player will fire onle rocket. And I don't want to swap weapons, they both must fire at the same time. I looked in FlxContol and FlxControlHandler, but didn't found any function for secondary weapon.

Could anyone help me with this?
Title: Re: Flixel Power Tools
Post by: test84 on Sat, Mar 10, 2012
Just setFireButton to one of them Override your fire method and fire both of those weapons, don't forget to call super.

OR

Have two different fire methods in another wrapper method that calls fireFromParentAngel with different parameters or sets a currentWeapon property and then calls that method.
Title: Re: Flixel Power Tools
Post by: Irtorius on Fri, Mar 16, 2012
Hi, got this problem, im trying to make so that the player can shoot bullets by pressing the spacebar several times, but it just does not work for some reason :-\

This is my current code for setting the control and firerate for the weapon
Code: [Select]
// Set fire button and other settings
FlxControl.player1.setFireButton("SPACE", FlxControlHandler.KEYMODE_PRESSED, 0, Registry.pistol.fire);

// Set fire rate
Registry.pistol.setFireRate(0);

It works but does not perfrom the task i want i to, i just want to shoot one bullet/keypress so i thought if i changed to:
Code: [Select]
// Set fire button and other settings
FlxControl.player1.setFireButton("SPACE", FlxControlHandler.KEYMODE_JUST_DOWN, 0, Registry.pistol.fire);

// Set fire rate
Registry.pistol.setFireRate(0);

I would be able to perform the task, but instead, i can't fire any bullets at all  :-\
Some advice would be greatly appreciated  :)
Title: Re: Flixel Power Tools
Post by: test84 on Sat, Mar 17, 2012
First of all, welcome to flixelville ;)

I never used FlxControl personally but looking at it's code, I would try to change the repeatdelay parameter to a bigger value since 0 apparently means that no delay between shoots/fires and thus meaning all bullets at once.

Also, don't set your fire rate to 0.

And since it's a common mistake, it doesn't hurts to say that if you don't see your bullets, you need to set boundries for your bullets with setBulletBounds, like setBulletBounds(new flxRect(0,0,6000,6000);

Another common mistake that you're better be safe than sorry is that make sure you "add" your bullets group to the scene with "add()" or FlxG.state.add() methods, depending on scope of them.
Title: Re: Flixel Power Tools
Post by: Irtorius on Sun, Mar 18, 2012
Thanks for your reply and I hope I'll enjoy my stay :)
I fixed the holes in the code, but the problem is still there.
The weapon now fires a bullet once in a while when i spam the spacebar.
I want to fire a bullet everytime I press the spacebar. Could this be some bug when using FlxControlHandler.KEYMODE_JUST_DOWN?  :'(
Title: Re: Flixel Power Tools
Post by: test84 on Tue, Mar 20, 2012
try KEYMODE_PRESSED
Title: Re: Flixel Power Tools
Post by: Irtorius on Wed, Mar 21, 2012
Yes, I've tried that and i know it works, but it does not do what I want it to. If I use KEYMODE_PRESSED, the weapon keeps fireing if I hold the button down. I want just want it to fire one bullet, and then the user have to press again.  ;)
How could I do this I asked myself, but it was a little bit overwhelming for me to solve that question.  :-\
Is there any solution for this?
Title: Re: Flixel Power Tools
Post by: test84 on Wed, Mar 21, 2012
That would be the exact purpose of KEYMODE_JUST_DOWN. That doesn't work for you?
Title: Re: Flixel Power Tools
Post by: ben657 on Wed, Mar 21, 2012
Hey, i've just started using these tools, and first of all, theyre excellent! but one thing that eludes me, is how to put in key strings... in the docs it says to use the flixel.system.input.keyboard class to get key strings, but I see no way of using it... is it just me not seeing something or..? :P
Title: Re: Flixel Power Tools
Post by: dncwalk99 on Thu, Mar 22, 2012
Great addition to Flixel.  I've just started using Flixel and the Powertools come in handy.  One question though.  How would I apply a BlurFX to a StarfieldFX?
Title: Re: Flixel Power Tools
Post by: tomii on Tue, Mar 27, 2012
I'm having this problem with FlxScrollZone (I know I'm not the only one), where it just stops working all of a sudden. Anyone know how to fix this?
Title: Re: Flixel Power Tools
Post by: photonstorm on Tue, Mar 27, 2012
Yeah pretty sure the problem is that the translation matrix values just get too big and can't cope any more. Not sure exactly what the limit is though, sorry - might be worth tracing out or something. It's the tx/ty values of the matrix. Could be that it exceeds the value of an integer maybe.

I think the solution would be to look for a "wrap point", i.e. rather than scroll infinitely (until it breaks!) you'd look to see if the translation values matched a seamless loop, and then reset them.
Title: Re: Flixel Power Tools
Post by: tomii on Tue, Mar 27, 2012
Okay, I'll see what I can find.
Title: Re: Flixel Power Tools
Post by: paala on Thu, Mar 29, 2012
I have a problem with FlxBar.
If I set max value different than 100 it doesn't update correctly.
Is this a known issue?
Should I create a separate help topic or is it ok to post here?
Title: Re: Flixel Power Tools
Post by: test84 on Sat, Mar 31, 2012
I have a problem with FlxBar.
If I set max value different than 100 it doesn't update correctly.
Is this a known issue?
Should I create a separate help topic or is it ok to post here?

probably something else is wrong since none of my FlxBars have a max value of 100. Do you update it?
Title: Re: Flixel Power Tools
Post by: photonstorm on Wed, Apr 4, 2012
Hi all,

I'm putting together Flixel Power Tools 2.0 at the moment. So far I've got several fixes across the classes, a bunch of new tile map based stuff and integration of Flod 4.

This will be the last release of FPT that I'm responsible for (someone else is welcome to pick up the mantle and carry on!) so I'm going to ask here now - what are the top (SMALL!) features you would like to see added for version 2? Nothing ridiculous please (don't ask for Stage3D support for example). But if I feel the request is manageable enough, then I'll implement it.

So get your requests in now :)
Title: Re: Flixel Power Tools
Post by: paala on Wed, Apr 4, 2012
Well, I would love box 2d sprites, if is not so hard.
Title: Re: Flixel Power Tools
Post by: xhunterko on Thu, Apr 5, 2012
At the least, a working input box.

It'd be great to have some 3d support though. Like rotateX and its y and whatever people use to get a card flip effect going. Hope neither of those sound too crazy.
Title: Re: Flixel Power Tools
Post by: test84 on Thu, Apr 5, 2012
I wish we could edit the bullet properties after we create a weapon. As of now, you should do all Setxxx before you make it and any Setxxx you do on your weapon is useless because bullets are already created with those properties you set at constructing it.

I also wrote a reload method and posted here for flxweapon, maybe it would help some people.
Title: Re: Flixel Power Tools
Post by: test84 on Wed, Apr 11, 2012
What's the best way to hide and disable a FlxButtonPlus? I can't "kill" it because it's a flxgroup and has two extendedsprites inside it so "kill"ing it just makes it invisible but actually works if you click it.
Title: Re: Flixel Power Tools
Post by: photonstorm on Thu, Apr 12, 2012
Over-ride its kill method and just kill the children as well. Or create a "disabled" method that tells the children to ignore mouse clicks. Or add it to the github wishlist and I'll add it into the final version of FPT :)
Title: Re: Flixel Power Tools
Post by: test84 on Thu, Apr 12, 2012
Something strange happens when I did a similar thing, when I press the credits button for the 2nd time, it calls another registered click function, like you pressed another button as well.

For example when I press the Credits button, it hides the main menu group and shows the credits group but 2nd time, when I press the credits, it calls the hide menu group and then calls the show menu as well (which was registered to Back button in credits menu) !

I didn't do what you said exactly earlier but I overrided kill and revive and put alive and exists to false and true accordingly (since in the click code, I see you check those variables)
Title: Re: Flixel Power Tools
Post by: test84 on Thu, Apr 12, 2012
Over-ride its kill method and just kill the children as well

And what I should do in the revive one?

Or create a "disabled" method that tells the children to ignore mouse clicks.
Assume I have that function, how I can make them invisible then?

And I believe we don't need such because you already check that with exists, visible and active flags:
Code: [Select]
protected function onMouseUp(event:MouseEvent):void
{
if (exists && visible && active && (_status == PRESSED) && (_onClick != null) && (pauseProof || !FlxG.paused))
{
_onClick.apply(null, onClickParams);
}
}
Title: Re: Flixel Power Tools
Post by: test84 on Sun, Apr 15, 2012
Over-ride its kill method and just kill the children as well.

I believe it does it already, because FlxButtonPlus is a FlxGroup and FlxGroup's kill calls kill on each member.

Maybe I didn't get what you meant.
Title: Re: Flixel Power Tools
Post by: test84 on Sun, Apr 15, 2012
I think it's not possible, or atleast I don't know how, to over-ride kill method of FlxButtonPlus properly, because of this line in FlxGroup's kill:
if(Recurse && (basic is FlxGroup))
and since FlxButtonPlus is a FlxGroup, it will will run this:
(basic as FlxGroup).callAll(FunctionName,Recurse);
which causes to ignore FlxButtonPlus's own over-ridden kill() and call FlxGroup's kill().

EDIT 4:

I wanted to resort to that disable method you mentioned but that can't be done for the same reason I just said because of that thing in callAll thing.
Title: Re: Flixel Power Tools
Post by: LegacyCrono on Wed, May 2, 2012
Hi, got this problem, im trying to make so that the player can shoot bullets by pressing the spacebar several times, but it just does not work for some reason :-\

This is my current code for setting the control and firerate for the weapon
Code: [Select]
// Set fire button and other settings
FlxControl.player1.setFireButton("SPACE", FlxControlHandler.KEYMODE_PRESSED, 0, Registry.pistol.fire);

// Set fire rate
Registry.pistol.setFireRate(0);

It works but does not perfrom the task i want i to, i just want to shoot one bullet/keypress so i thought if i changed to:
Code: [Select]
// Set fire button and other settings
FlxControl.player1.setFireButton("SPACE", FlxControlHandler.KEYMODE_JUST_DOWN, 0, Registry.pistol.fire);

// Set fire rate
Registry.pistol.setFireRate(0);

I would be able to perform the task, but instead, i can't fire any bullets at all  :-\
Some advice would be greatly appreciated  :)

I had the same issue, and managed to fix this by doing the following:
- Open org.flixel.plugin.photonstorm.FlxControl and find line 159:
Code: [Select]
override public function draw():void - And change it for:
Code: [Select]
override public function update():void

The problem happens because org.flixel.system.Input is updating before FlxControl has the opportunity to see the JUST_DOWN state of the key. When FlxControl runs on "draw()" the key state has already changed to "pressed", so the Fire button isn't triggered.
FlxControl currently updates on draw(), I have no idea why. Changing it to update() fixes this problem, but I don't know if it changes the behavior of something else on the Power Tools, so do this at your own discretion.
I hope photonstorm verify this and fix this problem soon.
Title: Re: Flixel Power Tools
Post by: Jeff on Tue, May 22, 2012
Just introduced myself to the power tools. Lots of great stuff there. I like the FX particularly.

Although I don't think I currently have much need for such a feature, I think one nice improvement for the extendedSprite would be to simplify creating entities that consist of multiple parts - in other words "sprites" that basically consist of multiple sprites.
Title: Re: Flixel Power Tools
Post by: squidbot on Wed, May 23, 2012
I have a question about overlapping sprites and the "clickable" property. I have four sprites on top of each other, only one visible at a time to show different states (the context is a grid of sprites you can mouse over and it will highlight current, and differently highlight nearby sprites you can move to next.)

My assumption was that if I set clickable to false on all the sprites but one, it would always get the clicks (I'll call this the control sprite.) The problem is that sprites that are marked not clickable are still added to the control stack in checkForClick. This meant that depending on how my control sprite was sorted, it would sometimes get clicks, sometimes not.

Rather than sorting, I solved the problem by changing the update in FlxExtendedSprite from

Code: [Select]
isPressed == false && FlxG.mouse.justPressed()
to

Code: [Select]
if ((clickable == true) && (isPressed == false && FlxG.mouse.justPressed()))

Now, I could have sorted the control sprite to the top, but that seems a little unintuitive and would have required extra code to support. So my question is, am I thinking about the problem incorrectly? Should non-clickable sprites still be added in to the control stack on a click? I hate changing the library as it causes issues when I need to update (I have to merge it in rather than just replace it.) And for that matter, is there a way to do this besides sorting that I am completely missing?

Thanks!

(BTW, I'm very happy with the library, don't want to come off as negative!)

Title: Re: Flixel Power Tools
Post by: paala on Thu, Jun 7, 2012
Another useful thing would be  animated sprites with baked rotations...
Title: Re: Flixel Power Tools
Post by: natdempk on Thu, Jun 14, 2012
I have a question about using FlxMouseControl? I am getting an error saying:
Code: [Select]
Item.as(36): col: 66 Error: Access of possibly undefined property clickTarget through a reference with static type org.flixel.plugin.photonstorm:FlxMouseControl.
I also get the same error when I use isDragging and dragTarget in the code below.

I create a FlxMouseControl in Registry.as by doing:
Code: [Select]
public static var mouseCon:FlxMouseControl = new FlxMouseControl();
Then in Item.as I reference it in the update function as follows:
Code: [Select]
// equip an item by pressing equip key + clicking
if (FlxG.keys.pressed(Registry.equipkey) && Registry.mouseCon.clickTarget == this) {
Registry.player.equip(this);
}

// drag an inventory item to another slot
if (Registry.mouseCon.clickTarget == this && Registry.mouseCon.isDragging) {
// snap to mouse until released
while (!FlxG.mouse.justReleased())
{
Registry.mouseCon.dragTarget.x = FlxG.mouse.x;
Registry.mouseCon.dragTarget.y = FlxG.mouse.y;
super.update();
}
// when released
// find item released over - UNSURE
var tempItem:Item = Registry.mouseCon.clickTarget;
var oldSlot:int = this.invSlot;
// swap item positions + set new slots
Registry.player.inventory[tempItem.invSlot] = this;
this.invSlot = tempItem.invSlot;
Registry.player.inventory[oldSlot] = tempItem;
tempItem.invSlot = oldSlot;
}

It seems to be saying that property is possibly undefined, but I am not sure why? Am I even doing this the right way? Should I create one FlxMouseControl for my whole game to contol some GUI stuff or would I be better off making a separate FlxMouseControl for each item in my inventory?
Title: Re: Flixel Power Tools
Post by: Jeff on Sat, Jul 21, 2012
Is there a plan of adding tilemap support for the pixel perfect collision?  I put a sprite for collision in this case, but for some the pixelperfect check is functioning like the normal collision check: with enough rotation, it collides too early. Any idea, what the problem could be?
Title: Re: Flixel Power Tools
Post by: ezknight on Tue, Nov 13, 2012
Never mind. I improved my Googl-fu tonight and found the solution to my problem here: http://forums.flixel.org/index.php?topic=4855.0
My dragon class's update function wasn't calling super.update();

I am having an issue with the mouseReleasedCallback and mousePressedCallback parts of FlxExtendedSprite. I have been following the code in the balls mini game and it appears that I have done everything correctly, however the callback function never fires when I click the object it is attached to. I have added the FlxMouseControl plugin and have set the object as clickable via enableMouseClicks(true,true) but nothing happens.

I am extending the FlxExtendedClass with my own class. Could that be the problem?

This is my play state:

Code: [Select]
package
{
import org.flixel.*;
import org.flixel.plugin.photonstorm.*;
 
public class DRPlayState extends FlxState
{
[Embed(source="images/mountains.png")] private var mountains:Class;

private var sprite:FlxSprite;
private var dragonSp:DragonSprite;
private var cameraWall:FlxGroup;
private var xdir:int;
private var ydir:int;
private var speed:int;

private var clickCounter:FlxText;
private var missCounter:FlxText;

public function DRPlayState()
{
}

override public function create():void
{
if (FlxG.getPlugin(FlxMouseControl) == null)
{
FlxG.addPlugin(new FlxMouseControl);
}

sprite = new FlxSprite(0,68,mountains);
add(sprite);
sprite = new FlxSprite(32,68,mountains);
add(sprite);
sprite = new FlxSprite(96,68,mountains);
add(sprite);
sprite = new FlxSprite(192,68,mountains);
add(sprite);

speed = 2;

clickCounter = new FlxText(10, 0, 100, "Hits: ");
clickCounter.size = 20;
add(clickCounter);
missCounter = new FlxText(500, 0, 100, "Misses: ");
missCounter.size = 20;
add(missCounter);

dragonSp = new DragonSprite();
//dragonSp.enableMouseClicks(false,true);
//dragonSp.mousePressedCallback = spriteClicked;

add(dragonSp);

cameraWall = FlxCollision.createCameraWall(FlxG.camera, FlxCollision.CAMERA_WALL_OUTSIDE, 8, false);
add(cameraWall);
}

/*private function spriteClicked(obj:DragonSprite, x:int, y:int):void
{
dragonSp.switchDragon();
dragonSp.hitCount++;
if(dragonSp.hitCount >= 10)
{
dragonSp.speed -= 5;
dragonSp.hitCount = 0;
}
}*/

override public function update():void
{
super.update();

if(dragonSp.missed >=5)
{
goToGameOver();
}
clickCounter.text = "Hits: " + dragonSp.clicks.toString();
missCounter.text = "Misses: " + dragonSp.missed.toString();
FlxG.collide(dragonSp,cameraWall);
}

private function goToGameOver():void
{
FlxG.switchState(new DROverState());
}

override public function destroy():void
{
FlxMouseControl.clear();

super.destroy();
}
}
}

Here is my Dragon Class:

Code: [Select]
package
{
import org.flixel.*;
import org.flixel.plugin.photonstorm.*;

public class DragonSprite extends FlxExtendedSprite
{
[Embed(source = "images/bio_dragon.png")]
private var bio_dragon:Class;
[Embed(source = "images/bone_dragon.png")]
private var bone_dragon:Class;
[Embed(source = "images/dragon.png")]
private var dragon:Class;
[Embed(source = "images/fire_dragon.png")]
private var fire_dragon:Class;
[Embed(source = "images/gold_dragon.png")]
private var gold_dragon:Class;
[Embed(source = "images/ice_dragon.png")]
private var ice_dragon:Class;
[Embed(source = "images/mud_dragon.png")]
private var mud_dragon:Class;
[Embed(source = "images/wind_dragon.png")]
private var wind_dragon:Class;
[Embed(source = "images/ghost_dragon.png")]
private var ghost_dragon:Class;
[Embed(source = "images/shadow_dragon.png")]
private var shadow_dragon:Class;

private var ImgDragon:Class;
private var dragonCount:int;
public var missed:int;
public var speed:int;
public var hitCount:int;

public function DragonSprite()
{
super(64, 64);

if (FlxG.getPlugin(FlxMouseControl) == null)
{
FlxG.addPlugin(new FlxMouseControl);
}

switchDragon();

missed = 0;
speed = 300;
hitCount = 0;

enableMouseClicks(true, true);
mousePressedCallback = spriteClicked;
}

public function switchDragon():void
{
var randDragon:int = randomRange(1,100);

elasticity = 1;

if (randDragon > 0 && randDragon <= 30)
{
velocity.x = randomRange(25, 50, true);
velocity.y = randomRange(25, 50, true);
loadGraphic(dragon);
} else if (randDragon > 30 && randDragon <= 40)
{
velocity.x = randomRange(25, 75, true);
velocity.y = randomRange(25, 75, true);
loadGraphic(fire_dragon);
} else if (randDragon > 40 && randDragon <= 50)
{
velocity.x = randomRange(25, 75, true);
velocity.y = randomRange(25, 75, true);
loadGraphic(ice_dragon);
} else if (randDragon > 50 && randDragon <= 60)
{
velocity.x = randomRange(25, 75, true);
velocity.y = randomRange(25, 75, true);
loadGraphic(wind_dragon);
} else if (randDragon > 60 && randDragon <= 70)
{
velocity.x = randomRange(25, 75, true);
velocity.y = randomRange(25, 75, true);
loadGraphic(mud_dragon);
} else if (randDragon > 70 && randDragon <= 80)
{
velocity.x = randomRange(30, 80, true);
velocity.y = randomRange(30, 80, true);
loadGraphic(bio_dragon);
} else if (randDragon > 80 && randDragon <= 85)
{
velocity.x = randomRange(35, 85, true);
velocity.y = randomRange(35, 85, true);
loadGraphic(bone_dragon);
} else if (randDragon > 85 && randDragon <= 90)
{
velocity.x = randomRange(40, 90, true);
velocity.y = randomRange(40, 90, true);
loadGraphic(ghost_dragon);
} else if (randDragon > 90 && randDragon <= 95)
{
velocity.x = randomRange(45, 95, true);
velocity.y = randomRange(45, 95, true);
loadGraphic(shadow_dragon);
} else if (randDragon > 95 && randDragon <= 100)
{
velocity.x = randomRange(50, 100, true);
velocity.y = randomRange(50, 100, true);
loadGraphic(gold_dragon);
}
y = randomRange(1,85);
x = randomRange(1,535);
dragonCount = 0;
}

override public function update():void
{
dragonCount++;
if (dragonCount > speed)
{
missed++;
switchDragon();
}

}

private function spriteClicked(obj:DragonSprite, x:int, y:int):void
{
//obj.kill();
switchDragon();
hitCount++;
if (hitCount >= 10)
{
speed -= 5;
hitCount = 0;
}
}

private function randomRange(minNum:Number, maxNum:Number, flip:Boolean = false):Number
{
var randNum:int = (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);

if (flip == true && randomRange(1,2) == 2)
{
randNum = randNum * - 1;
}
return randNum;
}
}
}

I have tried putting the spriteClicked function in both the dragon class and the play state. I have tried every combination of true/false in the first parameter of the enableMouseClicks function and mousePressedCallback/mouseReleasedCallback. I have used my dragon class as the type declaration of the first parameter of the callback function as well as FlxExtendedSprite. Nothing works.
Title: Re: Flixel Power Tools
Post by: Silvio Carrťra on Mon, Feb 4, 2013
Code: [Select]
bow = new FlxWeapon("bow", actor, "x", "y");
bow.makeAnimatedBullet(50, AssetsRegistry.SPRITE_ARROW_18x25, 18, 25, [1, 2, 3], 3, true, 5, 5);
bow.setBulletDirection(FlxWeapon.BULLET_NORTH_EAST, 200);
bow.setFireRate(100);

add(bow.group);

It's shooting alright with:
Code: [Select]
bow.fireAtMouse();

Problem is, my arrows don't turn on the direction I'm shooting. So they are always poiting up. Is there a way to do this?
Title: Re: Flixel Power Tools
Post by: SuperDaimyo on Sun, Feb 24, 2013
Quote
I'm having this problem with FlxScrollZone (I know I'm not the only one), where it just stops working all of a sudden. Anyone know how to fix this?

Yeah pretty sure the problem is that the translation matrix values just get too big and can't cope any more. Not sure exactly what the limit is though, sorry - might be worth tracing out or something. It's the tx/ty values of the matrix. Could be that it exceeds the value of an integer maybe.

I think the solution would be to look for a "wrap point", i.e. rather than scroll infinitely (until it breaks!) you'd look to see if the translation values matched a seamless loop, and then reset them.

I have been experiencing this problem as well and have been staring at it for an hour. So far I have figured out that it is on the 103rd shift of the zone every time no matter what (even at 1 pixel a frame).  I will continue to fiddle and see if this can be solved as it messes up an otherwise really cool plugin.

Well, for a wrap point for horizontal scrolling only, I am using a line of code that would prevent tx/distanceX from approaching that 103 to closely and must wrap the value exactly when its a seamless loop but still working on the kinks. will post when i get it but i is teh bad at math, and have to consider possibility that tx/distanceX may reach 103 before a seamless wrap point :<.

Anyway, this is an ugly hack I still dont know the problem but maybe this might help those who just want to get it to work without stopping.

FlxScrollZone.as, line 235.

Code: [Select]
if (Math.abs(zone.scrollMatrix.tx) % Math.abs( (zone.distanceX*2))==0 &&  Math.abs(zone.scrollMatrix.tx) > zone.region.width )zone.scrollMatrix.tx=0;             

Settled on this, i use the abs because i read as3 didnt like modulus operations with negative numbers. In any case huge values of tx like if you set the distanceX with 100000 will break the function still. The condition tests if your x was translated at least once across its width and that it is in a "square" position then it just resets the tx.
Title: Re: Flixel Power Tools
Post by: Liberty Bell Studios on Tue, Mar 19, 2013
Hi, I love your tools, they are great!

However, I have a problem with the alpha mask.

Specifically, I made a class to create custom UIs, and I need to apply two masks in sequence.

What happens is that after I apply the second mask, the results of the cuts from the first mask appear as black, instead of transparent. Basically, applying the second mask makes me lose the alpha from the first cut.

How can I fix this? Thanks!
Title: Re: Flixel Power Tools
Post by: John56465 on Wed, Apr 24, 2013
I'm having an issue with the scrollFactor attribute inherited from native FlxSprite. I'm setting it to 0 on some FLxExtendedSprites for UI, and it works for the graphic (they always show up at the same place), but when I check their mouseOver the area isn't fixed, and it moves along the FlxG.camera (when it's moved using its scroll attribute). It's like FlxExtendedSprite.mouseOver doesn't work with the default Flixel camera.
Anyone have had the same issue?

Edit :
Well, I found a solution. Instead of checking sprite.mouseOver, I have to do
Code: [Select]
if (FlxMath.pointInFlxRect(mousePos.x, mousePos.y, sprite.rect))
{ ... }
which is almost the same thing as what mouseOver did in the first place. Pretty annoying. I tried centerOffsets, both with a 'true" and a "false" argument, but that didn't work. Posting the solution of course so people can see it.
Title: Flixel Power
Post by: DavydBezuglyi on Thu, Nov 12, 2015
Поступили новые книги из Amazon

Joinery Gary ROROWSKI, Classic Joints with Power tools

Сам я оцифровку не потяну. Если есть желающие почитать т.е. отсканировать - Welcom
Title: Flixel Power Tools
Post by: nesterdron on Sun, Mar 26, 2017
Yes I am using uxtheme to do the theming. For the most part it is just using SetWindowTheme and conveniently the tools do the theming for you.
Though I suspect I will have to manually call uxtheme painting api and get values for some things.

Edit:
I really should have cropped that photo. Its stretching the forum window.