请求高手帮忙详细解释以下两段flash代码!一个鼠标跟随的
package{importflash.display.Sprite;publicclassShipextendsSprite{publicfunctionShip(){...
package
{
import flash.display.Sprite;
public class Ship extends Sprite
{
public function Ship()
{
draw(false);
}
public function draw(showFlame:Boolean):void
{
graphics.clear();
graphics.lineStyle(1, 0x912BD5);
graphics.moveTo(10, 0);
graphics.lineTo(-10, 10);
graphics.lineTo(-5, 0);
graphics.lineTo(-10, -10);
graphics.lineTo(10, 0);
if(showFlame)
{
graphics.moveTo(-7.5, -5)
graphics.lineTo(-15, 0);
graphics.lineTo(-7.5, 5);
}
}
}
} 展开
{
import flash.display.Sprite;
public class Ship extends Sprite
{
public function Ship()
{
draw(false);
}
public function draw(showFlame:Boolean):void
{
graphics.clear();
graphics.lineStyle(1, 0x912BD5);
graphics.moveTo(10, 0);
graphics.lineTo(-10, 10);
graphics.lineTo(-5, 0);
graphics.lineTo(-10, -10);
graphics.lineTo(10, 0);
if(showFlame)
{
graphics.moveTo(-7.5, -5)
graphics.lineTo(-15, 0);
graphics.lineTo(-7.5, 5);
}
}
}
} 展开
2个回答
2010-06-18
展开全部
package
{
import flash.display.Sprite;
// Ship类继承自Sprite类,言下之意 这是一个元件绑定类
public class Ship extends Sprite
{
public function Ship()
{
//构造函数中执行内部函数draw 传入参数为false
draw(false);
}
//内部函数draw
public function draw(showFlame:Boolean):void
{
//这里是绘制一个飞船的图形罢了 graphics是displayObject对象内部的绘制对象
//lineStyle是定义线样式的 moveTo是移动绘制点 lineTo是在绘制点和目标点间连上直线
graphics.clear();
graphics.lineStyle(1, 0x912BD5);
graphics.moveTo(10, 0);
graphics.lineTo(-10, 10);
graphics.lineTo(-5, 0);
graphics.lineTo(-10, -10);
graphics.lineTo(10, 0);
//如果传入的参数是true 就在船尾加上火焰
if(showFlame)
{
graphics.moveTo(-7.5, -5)
graphics.lineTo(-15, 0);
graphics.lineTo(-7.5, 5);
}
}
}
}
==================================
具体效果你可以复制下面这段代码到一个新的as3.0 flash工程中时间轴代码上 运行一下就知道了
import flash.display.Sprite;
var m:Sprite = new Sprite();
addChild(m)
m.x = stage.stageWidth/2
m.y = stage.stageHeight/2
m.graphics.lineStyle(1, 0x912BD5);
m.graphics.moveTo(10, 0);
m.graphics.lineTo(-10, 10);
m.graphics.lineTo(-5, 0);
m.graphics.lineTo(-10, -10);
m.graphics.lineTo(10, 0);
m.graphics.moveTo(-7.5, -5)
m.graphics.lineTo(-15, 0);
m.graphics.lineTo(-7.5, 5);
{
import flash.display.Sprite;
// Ship类继承自Sprite类,言下之意 这是一个元件绑定类
public class Ship extends Sprite
{
public function Ship()
{
//构造函数中执行内部函数draw 传入参数为false
draw(false);
}
//内部函数draw
public function draw(showFlame:Boolean):void
{
//这里是绘制一个飞船的图形罢了 graphics是displayObject对象内部的绘制对象
//lineStyle是定义线样式的 moveTo是移动绘制点 lineTo是在绘制点和目标点间连上直线
graphics.clear();
graphics.lineStyle(1, 0x912BD5);
graphics.moveTo(10, 0);
graphics.lineTo(-10, 10);
graphics.lineTo(-5, 0);
graphics.lineTo(-10, -10);
graphics.lineTo(10, 0);
//如果传入的参数是true 就在船尾加上火焰
if(showFlame)
{
graphics.moveTo(-7.5, -5)
graphics.lineTo(-15, 0);
graphics.lineTo(-7.5, 5);
}
}
}
}
==================================
具体效果你可以复制下面这段代码到一个新的as3.0 flash工程中时间轴代码上 运行一下就知道了
import flash.display.Sprite;
var m:Sprite = new Sprite();
addChild(m)
m.x = stage.stageWidth/2
m.y = stage.stageHeight/2
m.graphics.lineStyle(1, 0x912BD5);
m.graphics.moveTo(10, 0);
m.graphics.lineTo(-10, 10);
m.graphics.lineTo(-5, 0);
m.graphics.lineTo(-10, -10);
m.graphics.lineTo(10, 0);
m.graphics.moveTo(-7.5, -5)
m.graphics.lineTo(-15, 0);
m.graphics.lineTo(-7.5, 5);
展开全部
这样都是标准写法
package //包
{
import flash.display.Sprite; 导入Sprite这个类
public class Ship extends Sprite //用剪辑基本都得继承这个
{
public function Ship() //构造函数 记得都这么写就行了
{
draw(false); 使用 draw这个方法
}
这段是用来画图形的,画的是一个箭头
public function draw(showFlame:Boolean):void
{
graphics.clear();
graphics.lineStyle(1, 0x912BD5); //直线的类型1像素,颜色
graphics.moveTo(10, 0);
graphics.lineTo(-10, 10); //画线
graphics.lineTo(-5, 0);
graphics.lineTo(-10, -10);
graphics.lineTo(10, 0);
if(showFlame) //如果draw(ture)如果调用时这么写就继续执行下面的函数
{
graphics.moveTo(-7.5, -5)
graphics.lineTo(-15, 0);
graphics.lineTo(-7.5, 5);
}
}
}
package //包
{
import flash.display.Sprite; 导入Sprite这个类
public class Ship extends Sprite //用剪辑基本都得继承这个
{
public function Ship() //构造函数 记得都这么写就行了
{
draw(false); 使用 draw这个方法
}
这段是用来画图形的,画的是一个箭头
public function draw(showFlame:Boolean):void
{
graphics.clear();
graphics.lineStyle(1, 0x912BD5); //直线的类型1像素,颜色
graphics.moveTo(10, 0);
graphics.lineTo(-10, 10); //画线
graphics.lineTo(-5, 0);
graphics.lineTo(-10, -10);
graphics.lineTo(10, 0);
if(showFlame) //如果draw(ture)如果调用时这么写就继续执行下面的函数
{
graphics.moveTo(-7.5, -5)
graphics.lineTo(-15, 0);
graphics.lineTo(-7.5, 5);
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询