更好一种小球组合键移动

const KEY_A:uint=65;
const KEY_D:uint=68;
const KEY_S:uint=83;
const KEY_W:uint=87;
/*
      *author : SinSoul 
      *blogs: http://www.cnblogs.com/sinsoul
		 
*/
var key:Object=new Object();
var speed:Number=10;
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDown);
stage.addEventListener(KeyboardEvent.KEY_UP,keyUp);
addEventListener(Event.ENTER_FRAME,test);
function keyDown(e:KeyboardEvent):void {
	key[e.keyCode]=true;
}
function keyUp(e:KeyboardEvent):void {
	key[e.keyCode]=false;
}

function test(e:Event):void {
	if (key[KEY_A]) {
		mc.x-=speed;
	}
	if (key[KEY_D]) {
		mc.x+=speed;
	}
	if (key[KEY_W]) {
		mc.y-=speed;
	}
	if (key[KEY_S]) {
		mc.y+=speed;
	}
}

 

使用 A,W,D,S来移动小球

posted @ 2010-11-05 14:45  sinsoul  阅读(220)  评论(0编辑  收藏  举报