Book Image

Flash Multiplayer Virtual Worlds

Book Image

Flash Multiplayer Virtual Worlds

Overview of this book

Flash virtual worlds are some of the most exciting—and profitable—online business being built today. Using Flash, developers can build interactive environments where users can interact with the virtual world and one another, compete, and have fun. Creating a playful environment on an electronic network presents unique challenges as you combine a fun, upbeat frontend with some serious and complex server logic. This handy book assists you in building amazing virtual worlds in no time by implementing ActionScripts in a Flash IDE. With this book in hand, you will build virtual worlds that have avatars walking around and interacting with non playing characters, completing challenging quests, and allowing users to link with real-world friends. The fun begins with first exploring existing virtual world games such as Club Penguin, Mole, Dofus, and World of Warcraft. We will then design our virtual environment. Then we will create avatars and move the avatars in the virtual world. We will add some triggers to add amusement and life to the virtual world. We will allow the avatars to interact with other players and create a buddy list for each user. Then we will integrate buildings and other environment to the virtual world. We will also let the players interact with non-player characters to complete some tasks. Finally, we move on to add interesting quests to the virtual world, which need to be accomplished by the player to gear up to the next level of the game. This example-rich, hands-on guide sequentially develops a multiplayer virtual world—the platform, the environment, quests, avatars, non-playing characters, and interaction between them.
Table of Contents (18 chapters)
Flash Multiplayer Virtual Worlds
Credits
About the Author
About the Reviewers
Preface

Scrolling the world


When the world is becoming bigger, we need to either scroll the world or divide it into smaller parts. We will focus on scrolling the world in this chapter and discuss about dividing the world in next chapter.

We will add a function in World class now. The lookAtAvatar function offset the world position to have the avatar locate at the center of the screen.

public function lookAtAvatar(avatar:Avatar):void {
/* the center of the screen */
var targetScreenPoint:Point = new Point(stage.stageWidth/2,stage. stageHeight/2);
var localTargetPoint:Point = this.globalToLocal( targetScreenPoint);
this.x += localTargetPoint.x - avatar.x;
this.y += localTargetPoint.y - avatar.y;
}

In the walking function in WalkingAvatar class, we can keep putting the controlling avatar in the center of the screen.

if (this == world.myAvatar){
world.lookAtAvatar(this);
}

Another common scrolling method is to scroll the world when the avatar is walking into the edge of the screen. We change the preceding...