Game Development Reference
In-Depth Information
}
private function moveSprite():void {
// Check the bounds for x
if ( m_sprite.x < 0 || m_sprite.x > WIDTH )
m_dx *= -1;
// Check the bounds for y
if ( m_sprite.y < 0 || m_sprite.y > HEIGHT )
m_dy *= -1;
// affect the change to the sprite
m_sprite.x += m_dx;
m_sprite.y += m_dy;
}
}
}
Mouse events
Every game user interface needs to handle mouse events. The mouse is an
integral part of any application, especially a game. You must have a very good
understanding of Flash mouse events that you can trap and take action for.
What do we need to handle mouse
events for?
In a multiplayer game, mouse handling starts at the login panel. For example,
clicking on an OK button, the user expects the interface to log into the server;
alternatively, clicking on a Cancel button, the user expects to quit the game.
Although Flash does a lot of mouse handling for you, there are numerous places that
you need something done specific when the user operates the mouse within your
game. Flash, for example, does all the work when the user clicks inside a text field to
show the cursor indicating the user that it is ready to accept the keyboard input.
Handling mouse clicks is one thing. Often in your game you may need to track the
mouse position; you may also need to handle events when the mouse enters
or leaves a specific area on the screen.
 
Search WWH ::




Custom Search