I’m just learning right now so I’m creating some fairly simple applications that’ll help me to learn.
Right now I just created an isometric moving character. It pretty well, there’s just one problem. This is eventually meant to work on a tile-based engine, and my current method is in intervals of 5pixels. The tile centers are about 48px away from each other (If I remember correctly) So just jaggedly moving the character the length of his walk in 1 instance won’t work. How can I move the character smoothly? Or do I have to rewrite the whole thing?
Live demo: http://rakuhana.org/vs/vs.php
I know that this is written kinda bad (It’s all in the document class, ideally, and eventually it’ll be in a separate character class, but I’m just learning now).
Source:
package
{
import KeyObject;
import flash.display.*;
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;
public class VelunaStory extends MovieClip
{
private var myParent:Sprite;
private var baseSheet:BitmapData;
public static var STAGE:Stage;
private var frame:Bitmap;
private var character:hero;
private var dir:int;
public function VelunaStory()
{
STAGE = this.stage;
character = new hero;
character.x = character.y = 50;
STAGE.addChild(character);
dir = 0;
character.gotoAndStop('front_stand');
startMain();
}
private function startMain()
{
//character.centerBitmap();
var Key:KeyObject = new KeyObject(STAGE);
STAGE.addEventListener(Event.ENTER_FRAME, onenter);
function onenter(e:Event):void
{
if(Key.isDown(Key.RIGHT))
{
character.gotoAndStop('front_walking');
character.x += 5;
character.y += 5;
character.scaleX = -1;
dir = 1;
}
else if(Key.isDown(Key.LEFT))
{
character.gotoAndStop('back_walking');
character.x -= 5;
character.y -= 5;
character.scaleX = -1;
dir = 3;
}
else if(Key.isDown(Key.UP))
{
character.gotoAndStop('back_walking');
character.x += 5;
character.y -= 5;
character.scaleX = 1;
dir = 2;
}
else if(Key.isDown(Key.DOWN))
{
character.gotoAndStop('front_walking');
character.x -= 5;
character.y += 5;
character.scaleX = 1;
dir = 0;
}
else
{
switch(dir)
{
case 0:
character.scaleX = 1;
character.gotoAndStop('front_stand');
break;
case 1:
character.scaleX = -1;
character.gotoAndStop('front_stand');
break;
case 2:
character.scaleX = 1;
character.gotoAndStop('back_stand');
break;
case 3:
character.scaleX = -1;
character.gotoAndStop('back_stand');
break;
}
}
}
}
}
}
Any insight or links on how can I achieve this is greatly appreciated.