-
Notifications
You must be signed in to change notification settings - Fork 433
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
Added a global CachedGraphics persistence variable. #1241
Conversation
If specified, CachedGraphics will use the persist value supplied by the constructor. Otherwise, it defaults to the value of persistentCachedGraphics in FlxG.bitmap (BitmapFrontEnd). This allows globally setting what the persist value of CachedGraphics should default to, making it easier to keep desired graphics persistent between state changes.
{ | ||
key = Key; | ||
bitmap = Bitmap; | ||
persist = Persist; | ||
persist = Persist != null ? Persist : FlxG.bitmap.persistentCachedGraphics; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of assigning this at construction time, why not leave value to null by default, and do this check during destruction time (when it's actually used)? As it stands, if you create some sprites, and then set FlxG.bitmap.persistentCachedGraphics to true after, it won't do anything since the value has been already set in each sprite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue with that is you're essentially making the persist state all or nothing. The value in assigning it at creation time is you can designate specific graphics to be persistent.
For instance, I would want a reoccurring menu to be persistent, if it's a menu that is accessible from both my main menu and my game (options screens, help screens, etc.).
Yet I don't need all the objects in my game to persist within my main menu, and so on.
The advantage of having a value be used globally at construction time is this - you can switch the default persist state to what you desire, before you create your menus. Then once they're created, you can switch it back off.
It makes things a little easier if you can have things default to what you want beforehand - that way you don't have to manually make sure each and every element of your persistent menu has persist set to true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plus, I'm not entirely sure what the value would be in having absolutely everything persistent or not. Not on the global scale of things, anyway.
Maybe a renaming of the variable would make it more clear on what it does? Something like defaultPersitence
? defaultCachedGraphicsPersistence
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would definitely prefer a static CachedGraphics.defaultPersist
, because that follows the pattern we already have for FlxCamera.defaultZoom
and FlxCamera.defaultCameras
.
Added a global CachedGraphics persistence variable.
Summary
If specified,
CachedGraphics
will use thePersist:Null<Bool>
value supplied by theconstructor. Otherwise, it defaults to the value of
defaultPersist
inCachedGraphics
.This allows globally setting what the persist value of
CachedGraphics
should default to, making it easier to keep desired graphics persistent between state
changes.
Changes
CachedGraphics
's constructor becomes aNull<Bool>
variable, so that ifPersist
is null,persist
in theCachedGraphics
is set to the default value (the value ofCachedGraphics.defaultPersist
).CachedGraphics
gets a simpledefaultPersist:Bool
so that persistence with all createdCachedGraphics
can be globally toggled.Reasoning
FlxSprite
,FlxText
and so on), they have to manually adjust thecachedGraphics.persist
variable for each object. This can be made easier with a global variable.CachedGraphics.defaultPersist = true
, create the objects that you wish to be persistent, and thenCachedGraphics.defaultPersist = false
.Menu
andPlay
states of a game. My own project has a Leaderboard menu that generates quite a bit of names and entries. Only having to create these objects once is a significant advantage, since this menu is accessible from most areas of the game. Having an easy way to control the persistence of objects as a whole is extremely handy for this.Update
Thanks to the feedback from gamedevsam and Gama11, I believe this static variable is clearer with its naming convention and position within CachedGraphics. Thanks guys.