n
LogMsg — This function prints a specified debug string to the
Console window.
function OnKill() //run as entity is removed from memory
RemoveActivePlayerIfNeeded(this);
end
n
RemoveActivePlayerIfNeeded — This function flags to
Novashell that the specified entity may be safely deleted from
memory since it is no longer required for the game.
8.11.3 Visual Profiles
Any single entity on the map, such as the player entity, may be in one
among many different states (such as walking, running, jumping) at
any one time. The player entity may, for example, be in a standing-still
state or in a walking or running state, depending on which keys the
player presses. Consequently, the visual appearance of an entity will
probably change depending on its state, requiring a different graphic
or animation to represent the entity in each state. Novashell uses its
Visual Profiles feature to solve this problem. A visual profile in
Novashell is an XML file assigned to an entity that lists each entity
state by name (“walk,” “run,” “jump,” etc.), and associates a visual
style (an appearance) to each state. Once the developer has associated
a complete XML profile to an entity and listed every state that entity
may assume, he then programs (in Lua) the entity’s currently active
state at run time from among the list of states available in the profile.
This is a bit like a dial or switch on a washing machine for choosing
which mode to work in. An example visual profile is featured below.
<resources>
<profile name="main_character">
<anim state="idle_left" spritename="idle_left" mirrorx="no" />
<anim state="idle_right" spritename="idle_left"
mirrorx="yes" />
<anim state="walk_right" spritename="walk_right"
mirrorx="yes" />
<anim state="walk_up" spritename="idle_down" mirrorx="no" />
</profile>
<sprite name="idle_left">
<image fileseq="idle/idle_left_.png" leading_zeroes="3" />
256 Chapter 8 / Novashell and 2D Games
<translation origin="center" />
<animation pingpong="no" loop="yes" speed="150" />
</sprite>
<sprite name="idle_right">
<image fileseq="idle/idle_right_.png" leading_zeroes="3" />
<translation origin="center" />
<animation pingpong="no" loop="yes" speed="150" />
</sprite>
<sprite name="walk_right">
<image fileseq="idle/walk_right_.png" leading_zeroes="3" />
<translation origin="center" />
<animation pingpong="no" loop="yes" speed="150" />
</sprite>
<sprite name="walk_up">
<image fileseq="idle/walk_up_.png" leading_zeroes="3" />
<translation origin="center" />
<animation pingpong="no" loop="yes" speed="150" />
</sprite>
</resources>
The above visual profile is for a sample player character and defines
four different states, though typically such a file would define many
others. These states are: idle_left, idle_right, walk_right, and walk_up.
The first two states are “idle” states in which the player is standing
still. The two walk states are for walking right and for walking up (for a
game with a top-down view). Let’s take a closer look at the profile
states and sprite entities of the visual profile XML file.
<anim state="idle_left" spritename="idle_left" mirrorx="no" />
n
Anim state nodes define a single entity state. Each anim states
features a name tag to specify the name of the state; a sprite name
that corresponds to a sprite node specified further down in the
XML file, which is a reference to the image resource to use for the
entity when in this state; and a mirror tag, which can be either
“yes” or “no” and determines whether the associated visual style
(as specified by sprite name) will be flipped or reversed. This last
property is useful for directional states such as walk_left and
walk_right, where the same image can be flipped to face the appro-
priate direction for each state.
Chapter 8 / Novashell and 2D Games 257
Chapter 8

Get Cross Platform Game Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.