-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent setting a FlxSprite to an invalid frame #174
Prevent setting a FlxSprite to an invalid frame #174
Conversation
Fixes FlixelCommunity#13 Prevents an "out of range" frame number from being set either by an animation, or by manually setting the `frame` property. Adds new getter/setter `numFrames` where user can manually specify how many frames an animation has (in case some frame are empty). To go hand in hand with this is the read-only property `maxFrames` which calculates how many frames can fit on that sprite sheet. NOTE: it rounds up, so sprites may "hang off the edge" if the sheet is the wrong dimensions. This may be fixed in the future depending on how other applications handle "overhanging frames".
The code compiles just fine. I haven't tested it, but I uploaded the SWC to the sandbox if anyone has some code to test it on (it's in the |
Odd, I didn't notice that property (and if I'm not mistaken, it's not even used anywhere in the code, which is probably why I missed it.) The code used to calculate it is only correct if the tiles fit perfectly on the sprite sheet, but will be bugged if there are any pixels "hanging over the edge". Using But you are right, there is no need to re-calculate
Actually, that's due to a typo of mine. Originally I was defaulting return (_numFrames == -1) ? maxFrames : _numFrames; |
It wasn't being used anywhere, and I'm assuming since it is public, that it was meant to be read-only.
No need to re-calculate it every time you call the property! It only needs to be updated whenever you change the bitmap associated with the sprite sheet.
Originally I was defaulting _numFrames to -1 until I realized it was an unsigned integer. Rather than change it to a signed one, I realized that you could never have zero frames, and let 0 be the default value. However, I forgot to change this in the actual `numFrames` getter.
I finally found where this property was being used! No wonder it was public.
There we go, all solved! I tested it in the sandbox and it works properly, but take a look and make sure I didn't miss anything. There is one warning thrown, but the good news is, it is supposed to throw that warning, since that is the "bugged" sprite which we have been talking about. Thanks for adding the sprite sheet Fernando, for some reason I thought it was going to require more work than that, and figured it would be easier finding a demo project that uses sprite sheets anyway. Also, I finally found where that |
The only problem now is that the code doesn't actually say which class throws the warning, so you pretty much have to guess and debug using a bunch of |
Everything seems to be working now, great job! I'm just nitpicking now, but shouldn't we keep the property Since the current release should not break anything, I think it's prudent to keep |
I assumed that public variable was only used internally by Flixel (especially since it is technically read-only, setting it does nothing), I didn't think of the fact that developers might use it. I'm also not a fan of that variable naming since the What if I create a public getter named |
I totally agree with you.
That's perfect! We can add a |
Do you know of any guides or at least an example and recommended use of the tag? The only thing I'm finding on it after some lazy (ie, only looking on the first page of results) Google searching is the following, which only describes how to use the Flex Metadata tags, not the comment tags: Deprecated metadata tag Should both be used, or is that unnecessary? Does Flash Professional still have difficulties compiling Flex Metadata unless you download and specify the Flex SDK (which most beginners won't have done, and I know has caused confusion for a few)? I seem to remember that in CS3 it couldn't compile with the metadata at all, or at least not the |
I never used a Flex deprecated metadata tag, so I don't know if Flash Professional still have problems with it. I think we can keep it simple and just add a comment tag, such as:
|
For backwards compatability, add depreciated getter `frames`. Also fix tiny typo in description of `numFrames` (no use creating a new commit just for that tiny thing).
That simple? Excellent! The commit has been added to this pull request. |
Simplicity is key! :D Your change is perfect. The code is good and working, we can merge it. |
Prevent setting a FlxSprite to an invalid frame
Fixes #13
Prevents an "out of range" frame number from being set either by an
animation, or by manually setting the
frame
property.Adds new getter/setter
numFrames
where user can manually specify howmany frames an animation has (in case some frame are empty).
To go hand in hand with this is the read-only property
maxFrames
whichcalculates how many frames can fit on that sprite sheet. NOTE: it rounds
up, so sprites may "hang off the edge" if the sheet is the wrong
dimensions. This may be fixed in the future depending on how other
applications handle "overhanging frames".