Blogger had some issues last night so this is 11/05's Work Completed.
The goal was to complete the Switch Tile Client Editor. Although I put in a full day's work, I didn't get around to working towards the goal. Instead, all my time went toward fixing the GUI issues that I had talked about.
I think what I ended up doing works pretty well. I had said that I'd develop a system where GUI sections or panels would fade as the mouse pointer got closer to it. I wrote a new class or two and was able to make this work but later realized that some GUI panels have buttons which of course need the mouse pointer to interact with.
So I developed a 'hide/show info' option. The user can simply toggle the visibility of anything in the way of the puzzle elements by pressing 'H' on the keyboard. I also added a class that takes the dimensions of a rectangle and adds a black panel object behind a group of GUI objects.
With FlashPunk, you can simply change an Entity's Boolean 'visible' property to false so achieving this toggle feature seemed simple enough. However, several of these panels are made up of several Entity objects and then several of those may be made up of several entities. That meant keeping track of a lot of entities which can get quite confusing.
Since most objects are based off of FlashPunk's Entity class, I base all my Entity objects off of a class I wrote called EnityPlus. This simply extends Entity and adds a few things I find helpful.
One big thing I added is a group of functions and an array which are related to adding and removing entities from the world. The array is called 'allWorldObjectsInThis' and a few of the functions are; epAdd(), epRemove(), epAddList()... and so on. The functions simply add and remove entities to and from the world like you normally would ( world.add(e) ), except they also add and remove entities from the 'allWorldObjectsInThis' array.
This allows versatility and automation. For example; FlashPunk calls a removed() function in any Entity when it's removed from the world. In EntityPlus, I over-rid this function and added a loop to remove everything in my 'allWorldObjectsInThis' array from the world. So anytime I remove an entity from the world, any entities that entity has added to the world with epAdd or epAddList get automatically removed from the world.
Now, for turning off the visibility for a group of objects. In EntityPlus I wrote a function called visibility(_visible:Boolean) which sets that entity's visible property to the value passed and then calls the same function for each EntityPlus in the 'allWorldObjectsInThis' array. So if I have an EntityPlus class 'SwitchTileEditor_SubMenu' that has added to the world everything that makes up the GUI panels, I can simply call it's visibility() function when the user presses 'H'.
if (Input.pressed(Key.H))
{
if (visible) visibility(false);
else visibility(true);
}
No comments:
Post a Comment