主要是利用Flash Actionscript一步一步学习Flash高射炮简单游戏的制作过程,最终效果只是一个简单的演示,如果你有兴趣可以继续深入学习!
第一步:首先简单的制作一个鼠标动画,绘制一个鼠标的图,自己定。然后选择第一帧输入下面代码:
Mouse.hide(); attachMovie("crosshair", "crosshair", 1); crosshair.onEnterFrame = function() { this._x = _xmouse; this._y = _ymouse; };
效果如下:
第二步:绘制一个坦克,分成两部分,如下面:
把下面的命名实例名为tank
代码如下:
Mouse.hide(); attachMovie("crosshair", "crosshair", 1); attachMovie("tank", "tank", 2, {_x:230, _y:350}); crosshair.onEnterFrame = function() { this._x = _xmouse; this._y = _ymouse; }; tank.onEnterFrame = function() { mousex = _xmouse-this._x; mousey = (_ymouse-this._y)*-1; angle = Math.atan(mousey/mousex)/(Math.PI/180); if (mousex<0) { angle += 180; } if (mousex>=0 && mousey<0) { angle += 360; } this.cannon._rotation = angle*-1; };
效果(无角度限制):
第三步:我这里设置转动的一定的角度。
Mouse.hide(); attachMovie("crosshair", "crosshair", 1); attachMovie("tank", "tank", 2, {_x:230, _y:350}); crosshair.onEnterFrame = function() { this._x = _xmouse; this._y = _ymouse; }; tank.onEnterFrame = function() { mousex = _xmouse-this._x; mousey = (_ymouse-this._y)*-1; angle = Math.atan(mousey/mousex)/(Math.PI/180); if (mousex<0) { angle += 180; } if (mousex>=0 && mousey<0) { angle += 360; } if (angle>160) { angle = 160; } if (angle<20) { angle = 20; } this.cannon._rotation = angle*-1; };
效果如下:
没有相关教程
|