change the pic of instance
- August 13, 2009
- 1 reply
- 769 views
hi ![]()
i make this code that move instance in 8 direction
but i used rotation to change the direction of instance
but now i went to change the pic like this pic in attach
or
http://img43.imageshack.us/img43/5909/alexchar.png
and the code
var up:Boolean = false;
var down:Boolean = false;
var left:Boolean = false;
var right:Boolean = false;
//create the function main.
function Main(event:Event){
check_move();
change_opg();
}
function prease_key (e:KeyboardEvent)
{
if(e.keyCode==37)
{
left = true;
}
if(e.keyCode==39)
{
right = true;
}
if(e.keyCode==38)
{
up = true;
}
if(e.keyCode==40)
{
down = true;
}
}
function resave_key (e:KeyboardEvent)
{
if(e.keyCode==37)
{
left = false;
}
if(e.keyCode==39)
{
right = false;
}
if(e.keyCode==38)
{
up = false;
}
if(e.keyCode==40)
{
down = false;
}
}
function check_move()
{
if(left)
{
m1.x -=5;
}
if(right)
{
m1.x +=5;
}
if(up)
{
m1.y -=5;
}
if(down)
{
m1.y +=5;
}
}
function change_opg()
{
if(left)
{
if(up)
{
m1.rotation =315;
}
else if(down)
{
m1.rotation =225;
}
else
{
m1.rotation =270;
}
}
if(right)
{
if(up)
{
m1.rotation =45;
}
else if(down)
{
m1.rotation =135;
}
else
{
m1.rotation =90;
}
}
if(up&&!left&&!right)
{
m1.rotation =0;
}
if(down&&!left&&!right)
{
m1.rotation =180;
}
}
//Lets the function main play every frame.
addEventListener(Event.ENTER_FRAME,Main);
stage.addEventListener(KeyboardEvent.KEY_DOWN, prease_key);
stage.addEventListener(KeyboardEvent.KEY_UP, resave_key);