Getting Start with Flash based Virtual World
Developing Virtual World is a huge task, but if we break the task list, here is first step.
In this example I have integrated SmartFox with OpenSpace.
Software Check List
1. SmartFox Server (http://www.smartfoxserver.com/products/)
2. Open Space Engine (http://www.openspace-engine.com/evaluate.php)
3.IIS or any local server i.e. WAMP (http://www.wampserver.com/en/download.php)
- Install SmartFox (You can install any version of SmarFox Lit, Basic or Pro)
- Start SmartFox Server. Programs-SmartFox Server-Start SmartFox Server
- Start Admin Tool. Programs-SmartFox Server-Admin-Admin Tool
- Login Using Default Setting Server IP 127.0.0.1, Port 9339, User Name sfs_admin, Password sfs_pass
- Click Config.xml Tab
- Under Zones Tag Add the Following
<Zone name="openspace" uCountUpdate="true" maxUsers="200" customLogin="false">
<Rooms>
<Room name="Ranch (inside)" maxUsers="50" isPrivate="false" isTemp="false" uCountUpdate="true" />
<Room name="Ranch (outside)" maxUsers="50" isPrivate="false" isTemp="false" uCountUpdate="true" />
<Room name="Slopes area" maxUsers="50" isPrivate="false" isTemp="false" uCountUpdate="true" />
</Rooms>
</Zone>
- Extract the “OpenSpace_trial.zip” and go to the following folder “\OpenSpace_trial\OpenSpace_trial\Examples”
- Copy “FarWest_Ranch” and “Slopes” to loacalhost root. (C:\Inetpub\wwwroot)
- Open Your browser and type “http://localhost/FarWest_Ranch/OpenSpace_tester.html” or http://localhost/Slopes/OpenSpace_tester.html” and see your character moving into virtual world.
You can edit the world using Editor Which is Located at “\OpenSpace_trial\Editor\OpenSpaceEditor_trial.air” (You need to install it)
You can edit avatar by editing following file “\OpenSpace_trial\OpenSpace_trial\Examples\FarWest_Ranch\libraries\AvatarsLibraryExample.fla”
Shuffling Array in Flash
We often need to shuffle array in flash but flash is not having any in-built function to shuffle the array.
Here is code to shuffle the array in a simple manner.
Please convert smart quotes to normal quote before pasting the following code to flash
// Initinal Value of the Array
var aData:Array = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
trace(‘Before Shuffling : aData = {‘+aData+’}');// Before Shuffling : aData = {1,2,3,4,5,6,7,8,9,10}
for (i=0; i<aData.length; i++) {
//This will fetch the value at random index and save it in nData
var nData:Array = aData.splice(randRange(0, aData.length-1), 1);
//This will store the nData value to end of the same array
aData.push(nData[0]);
}
trace(‘After Shuffling : aData = {‘+aData+’}');// After Shuffling : aData = {5,6,1,3,7,10,2,9,8,4}
function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.floor(Math.random()*(max-min+1))+min;
return randomNum;
}
Fake Gravity Algo
Hi,
This is the fake Gravity algo. I have copied this from book “Flash MX 2004 Game Design”.
//————– Copy from here ——————-
// Object require on Stage
// ball:MovieClip – Idally with a circle or whatever you want.
var ymov:Number = 0;
//
var gravity:Number = 2;
ball.onEnterFrame = function() {
ymov += gravity;
ball._y += ymov;
if (ball._y>(Stage.height – ball._height)) {
ball._y = Stage.height – ball._height;
ymov *= -1;
}
};
//————– Stop Copying ——————-
Tween Class
Tween class is preety smilple and very very useful. I have not used it till last month and after using it I always think that If I had spend 1hr on this class before 2 years, Icould make many application more interesting. (Specially some Drag & Drops)
Here is one example of Tween Class.
You need to put one movieClip named “mcObject” on Stage and paste the code in Action Layer.
//————– Copy from here ——————-
import mx.transitions.Tween;
import mx.transitions.easing.*;
//
var mcObject:MovieClip;
//
mcObject.onPress = pressHandler;
mcObject.onRelease = mcObject.onReleaseOutside=releaseHandler;
//
function pressHandler() {
//trace(“pressHandler called with ["+arguments+"]“);
this.oldX = this._x;
this.oldY = this._y;
this.startDrag();
}
//
function releaseHandler() {
//trace(“releaseHandler called with ["+arguments+"]“);
this.stopDrag();
var xTween:Tween = new Tween(this, “_x”, Bounce.easeOut, this._x, this.oldX, 5, true);
var yTween:Tween = new Tween(this, “_y”, Bounce.easeOut, this._y, this.oldY, 5, true);
}
//————– Stop Copying ——————-
You can take offical help on Tween class from here
Jump Algo in Flash
Hi,
I could not fullfill promise that I’ll post daily but I am trying…..
This post is for Flash Developers who are doing game programming.
Open new Flash File, Create one MovieClip and Paste this code on MovieClip (Bad Practice, but focus on what it’s doing)
//————– Copy from here ——————-
//This is settign the initial values onLoad
onClipEvent (load) {
//Speed of the Object
//More Speed will make object go higher in sky....
//This can be mass of the object
startspeed = 10;
//Amount of Gravity, 9.8 is standard Gravity
//Use 0 as gravity and your object will be lost in space
//Will never come down...
//Can be used for animated background, with some random wind algo.
gravity = 9.8;
//Current Status
jumping = false;
//Initial position
startpos = 0;
}
onClipEvent (enterFrame) {
//If user press up key and object is not jumping
//This will make object jump
if ((Key.isDown(87) or Key.isDown(Key.UP)) and jumping == false) {
jumping = true;
starttime = getTimer()/1000;
startpos = this._y;
}else if(Key.isDown(Key.LEFT)){
_x -=5;
}else if(Key.isDown(Key.RIGHT)){
_x +=5;
}
if (jumping) {
time = getTimer()/1000-starttime;
_y -= (startspeed-gravity*time);
if (_y>startpos) {
_y = startpos;
jumping = false;
}
}
}
//————– Stop Copying ——————-
This code is taken from http://www.video-animation.com/flash_06.shtml