2004/12/04 | [我闪日记09]-GGDI和GPen的测试类
类别(我闪我闪) | 评论(3) | 阅读(355) | 发表于 23:00

这些只是一些自己的补课而已,不过真是学了很多东西,代码也逐渐规范了。经过两天的学习,发现云开老师的确是和善可亲,虽然我很笨,但还是很耐心的指点,呵呵。今天的作业先发上来,画矩形的方法分已经放入GGDI类,大家先PP~

/*
@class gx.graphics.GGDI
@package gx.graphics
@author 高翔
@tooltip GGDI类,目前仅有绘制矩形方法
*/

import gx.graphics.GPen;
//GGDI类
class gx.graphics.GGDI extends MovieClip {
private static var _target:MovieClip;
public static function set target(target:MovieClip):Void {
_target = target;
}
//绘制矩形方法-静态(画笔、顶点的x坐标、y坐标、长、宽)
public static function DrawRect(pen:GPen, x:Number, y:Number, h:Number, w:Number):Void {
_target.lineStyle(pen.width, pen.color, pen.alpha);
_target.moveTo(x, y);
_target.lineTo(x+w, y);
_target.lineTo(x+w, y+h);
_target.lineTo(x, y+h);
_target.lineTo(x, y);
}
}

这是昨天的测试GPen类,又让老师说了,color的类型已更正。:)

/*
@class gx.graphics.GPen
@package gx.graphics
@author 高翔
@tooltip 测试笔刷GPen类
*/

class gx.graphics.GPen {
private var _width:Number;
private var _color:Number;
private var _alpha:Number;
//构造器(宽度、颜色、透明度)
public function GPen(width:Number, color:Number, alpha:Number) {
_width = width;
_color = color;
_alpha = alpha;
}
//获取属性
public function get width():Number {
return _width;
}
public function get color():Number {
return _color;
}
public function get alpha():Number {
return _alpha;
}
//设置属性
public function set width(width:Number):Void {
this._width = width;
}
public function set color(color:Number):Void {
this._color = color;
}
public function set alpha(alpha:Number):Void {
this._alpha = alpha;
}
}

使用方法:

import gx.graphics.GGDI;
import gx.graphics.GPen;
var pen:GPen = new GPen(2, 0x0000ff, 100);
GGDI.target = _root;
GGDI.DrawRect(pen, 1, 1, 50, 75);

晚上去写GColor类,现在有点上瘾了,呵呵~

 

0

评论Comments