美堂佳苗个人资料:actionscript超简单

来源:百度文库 编辑:高校问答 时间:2024/03/29 20:25:49
actionscript编一个简单的用键盘方向键控制一个小球能上下左右运动。
简单一点的,我不要带角度的旋转,只要求上下左右就可以了

写在主场景第一帧。
//小球叫ball_mc

onEnterFrame = function()
{
if(Key.isDown(Key.LEFT))
{
ball_mc._x -= 5;
}
if(Key.isDown(Key.RIGHT))
{
ball_mc._x += 5;
}
if(Key.isDown(Key.UP))
{
ball_mc._y -= 5;
}
if(Key.isDown(Key.DOWN))
{
ball_mc._y += 5;
}
}

//按一下动一下。

步骤:1、画一个小球。取名为ball.并把它放在主场景中。
2、在ball上右击,在action中写上如下的语句:
onClipEvent (load) {
var up=1;
var left=0;
var right=0;
var down=0;
pos = _root.ball._rotation;
// :get the initialize position
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
var up=0;
var left=0;
var right=1;
var down=0;
_root.ball._rotation = pos+90;
_root.ball._x = _root.ball._x+5;
if (_root.ball._x>=350-_root.ball._height) {
_root.ball._x = 350-_root.ball._height;
}
}
if (Key.isDown(Key.LEFT)) {
var up=0;
var left=1;
var right=0;
var down=0;
_root.ball._rotation = pos-90;
_root.ball._x = _root.ball._x-5;
if (_root.ball._x<=50+_root.ball._height) {
_root.ball._x = 50+_root.ball._height;
}
}
if (Key.isDown(Key.UP)) {
var up=1;
var left=0;
var right=0;
var down=0;
_root.ball._rotation = pos;
_root.ball._y = _root.ball._y-5;
if (_root.ball._y<=50+_root.ball._width) {
_root.ball._y = 50+_root.ball._width;
}
}
if (Key.isDown(Key.DOWN)) {
var up=0;
var left=0;
var right=0;
var down=1;
_root.ball._rotation = pos+180;
_root.ball._y = _root.ball._y+5;
if (_root.ball._y>=350-_root.ball._width) {
_root.ball._y = 350-_root.ball._width;
}
}
if (Key.isDown(Key.DOWN) and Key.isDown(Key.LEFT)) {
_root.ball._rotation = pos+225;
_root.ball._x = _root.ball._x-2;
_root.ball._y = _root.ball._y+2;
if (_root.ball._y>=380-_root.ball._width) {
_root.ball._y = 380-_root.ball._width;
}
if (_root.ball._x<=20+_root.ball._height) {
_root.ball._x = 20+_root.ball._height;
}
}
if (Key.isDown(Key.DOWN) and Key.isDown(Key.RIGHT)) {
_root.ball._rotation = pos+135;
_root.ball._x = _root.ball._x+2;
_root.ball._y = _root.ball._y+2;
if (_root.ball._y>=380-_root.ball._width) {
_root.ball._y = 380-_root.ball._width;
}
if (_root.ball._x>=380-_root.ball._height) {
_root.ball._x = 380-_root.ball._height;
}
}
if (Key.isDown(Key.UP) and Key.isDown(Key.LEFT)) {
_root.ball._rotation = pos-45;
_root.ball._x = _root.ball._x-2;
_root.ball._y = _root.ball._y-2;
if (_root.ball._y<=20+_root.ball._width) {
_root.ball._y = 20+_root.ball._width;
}
if (_root.ball._x<=20+_root.ball._height) {
_root.ball._x = 20+_root.ball._height;
}
}
if (Key.isDown(Key.UP) and Key.isDown(Key.RIGHT)) {
_root.ball._rotation = pos+45;
_root.ball._x = _root.ball._x+2;
_root.ball._y = _root.ball._y-2;
if (_root.ball._y<=20+_root.ball._width) {
_root.ball._y = 20+_root.ball._width;
}
if (_root.ball._x>=380+_root.ball._height) {
_root.ball._x = 380+_root.ball._height;
}
}
if (Key.isDown(Key.SPACE)) {
i += 1;
_root.attachMovie("zidan", "zidan"+i, i);
_root["zidan"+i]._x = _root.ball._x;
_root["zidan"+i]._y = _root.ball._y;
}
}

步骤:1、画一个小球。取名为ball.并把它放在主场景中。
2、在ball上右击,在action中写上如下的语句:
onClipEvent (load) {
var up=1;
var left=0;
var right=0;
var down=0;
pos = _root.ball._rotation;
// :get the initialize position
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
var up=0;
var left=0;
var right=1;
var down=0;
_root.ball._rotation = pos+90;
_root.ball._x = _root.ball._x+5;
if (_root.ball._x>=350-_root.ball._height) {
_root.ball._x = 350-_root.ball._height;
}
}
if (Key.isDown(Key.LEFT)) {
var up=0;
var left=1;
var right=0;
var down=0;
_root.ball._rotation = pos-90;
_root.ball._x = _root.ball._x-5;
if (_root.ball._x<=50+_root.ball._height) {
_root.ball._x = 50+_root.ball._height;
}
}
if (Key.isDown(Key.UP)) {
var up=1;
var left=0;
var right=0;
var down=0;
_root.ball._rotation = pos;
_root.ball._y = _root.ball._y-5;
if (_root.ball._y<=50+_root.ball._width) {
_root.ball._y = 50+_root.ball._width;
}
}
if (Key.isDown(Key.DOWN)) {
var up=0;
var left=0;
var right=0;
var down=1;
_root.ball._rotation = pos+180;
_root.ball._y = _root.ball._y+5;
if (_root.ball._y>=350-_root.ball._width) {
_root.ball._y = 350-_root.ball._width;
}
}
if (Key.isDown(Key.DOWN) and Key.isDown(Key.LEFT)) {
_root.ball._rotation = pos+225;
_root.ball._x = _root.ball._x-2;
_root.ball._y = _root.ball._y+2;
if (_root.ball._y>=380-_root.ball._width) {
_root.ball._y = 380-_root.ball._width;
}
if (_root.ball._x<=20+_root.ball._height) {
_root.ball._x = 20+_root.ball._height;
}
}
if (Key.isDown(Key.DOWN) and Key.isDown(Key.RIGHT)) {
_root.ball._rotation = pos+135;
_root.ball._x = _root.ball._x+2;
_root.ball._y = _root.ball._y+2;
if (_root.ball._y>=380-_root.ball._width) {
_root.ball._y = 380-_root.ball._width;
}
if (_root.ball._x>=380-_root.ball._height) {
_root.ball._x = 380-_root.ball._height;
}
}
if (Key.isDown(Key.UP) and Key.isDown(Key.LEFT)) {
_root.ball._rotation = pos-45;
_root.ball._x = _root.ball._x-2;
_root.ball._y = _root.ball._y-2;
if (_root.ball._y<=20+_root.ball._width) {
_root.ball._y = 20+_root.ball._width;
}
if (_root.ball._x<=20+_root.ball._height) {
_root.ball._x = 20+_root.ball._height;
}
}
if (Key.isDown(Key.UP) and Key.isDown(Key.RIGHT)) {
_root.ball._rotation = pos+45;
_root.ball._x = _root.ball._x+2;
_root.ball._y = _root.ball._y-2;
if (_root.ball._y<=20+_root.ball._width) {
_root.ball._y = 20+_root.ball._width;
}
if (_root.ball._x>=380+_root.ball._height) {
_root.ball._x = 380+_root.ball._height;
}
}
if (Key.isDown(Key.SPACE)) {
i += 1;
_root.attachMovie("zidan", "zidan"+i, i);
_root["zidan"+i]._x = _root.ball._x;
_root["zidan"+i]._y = _root.ball._y;
}
}