1.Game Object Architecture
After learning about all the object editor, now it is time to move onto coding your objects.
Game Objects are edited by making use of it's dynamic button-bar seen on the left-side of the workspace:
There are five categories of code for all game objects. Each as unique and important as the other.
So Let's Begin with the.....
2.Basic Object Functions
Looking at the picture above you can see there is quite the list of functions to edit. These functions are called automatically by the Game Pencil Engine each frame(Exception being the "Constructor, Descructor and Sprite Done" functions).
So piece by piece, let's discuss their use:
The constructor of an object is where variables are declared for an object. This function is called as soon as the object is created and is the chief building block for game objects.
The destructor of an object is the last function and object performs before it dies. Depending on the game and it's design it is where many dynamic variables are put to rest or where the player is rewarded points/coins, etc, etc.
The Start frame function is what is called at the start of each game frame within the game loop. It is crucial for many game AI and is used often to reset variables, states, etc.
The main logic function is the bread and butter of most game engines and is called after start-frame. Here is where the game ai usually takes place.
The sprite done function is called after an object's sprite animation is completed and is about to be reset. This is useful for games in which you need to have an action happen once a sprite animation is completed.
The end frame function is also called every frame and is called right before the engine enters into it's render state. This is usually used as a finalization step before presenting to the user what happened in the main-logic step.
The pre-render function is the first of the three render functions in which users typically call rendering-functions to be later drawn over such as shadows, effects, etc.
The render function for game objects is where you typically will draw the game object as you will like the player to be presented. If this function is left blank, than it will just default to drawing the sprite animation of the object at it's (x,y) position in the case that it does not inherit from another object.
This render function will possibly be the least used by most objects. This function is the last to be rendered before the next game frame. It is limited to game screen and where you will place gui elements and things on the HUD to relate information to users.
Custom functions are just that, custom functions created by you for objects to call on themselves or by other objects.
There are cases in which you may want to create custom functions in order to reduce the amount of times you re-use your code. Custom functions are passed down to child members of functions and as such the scope must remain known.
Examples of custom functions:
- etc, etc
Many games can be made without ever using this tab and is intended for advanced use of the engine. These functions unlike the others are not called automatically by the game pencil engine.
Special Functions are very similar to the Basic Object functions in which they are called automatically, but is called quite rarely.
This function occurs after at the opening of each scene.
This function occurs at the ending of each scene.
This function occurs at the start of the game.
This function occurs at the end of the game.
This function occurs when the player dies.
This function occurs when the player runs out of lives.
Game Objects are dynamic and essentially control the entire game engine.
So whether if you're making a small platformer game, episodic adventure, rts, rpg please become comfortable with the easy to use features as well as advanced features of game objects.