Show:

annie.Shape Class

Extends annie.Bitmap
Defined in: libs/Shape.js:19
Module: annie

Available since 1.0.0

矢量对象

Methods

_updateSplitBounds

() private

更新boundsList矩阵

addDraw

(
  • commandName
  • params
)
Void public

Defined in libs/Shape.js:142

Available since 1.0.0

添加一条绘画指令,具体可以查阅Html Canvas画图方法

Parameters:

  • commandName String

    ctx指令的方法名 如moveTo lineTo arcTo等

  • params Array

Returns:

Void:

addEventListener

(
  • type
  • listener
  • useCapture
)
Void public

Inherited from annie.EventDispatcher: libs/EventDispatcher.js:109

Available since 1.0.0

给对象添加一个侦听

Parameters:

  • type String

    侦听类型

  • listener Function

    侦听后的回调方法,如果这个方法是类实例的方法,为了this引用的正确性,请在方法参数后加上.bind(this);

  • useCapture Boolean

    true 捕获阶段 false 冒泡阶段 默认 true

Returns:

Void:

Example:

 this.addEventListener(annie.Event.ADD_TO_STAGE,function(e){console.log(this);}.bind(this));

addSound

(
  • sound
)
Void public

Inherited from annie.DisplayObject: libs/DisplayObject.js:952

Available since 2.0.0

返回一个id,这个id你要留着作为删除他时使用。 这个声音会根据这个显示对象添加到舞台时播放,移出舞台而关闭

Parameters:

Returns:

Void:

arcTo

(
  • x
  • y
)
Void public

Defined in libs/Shape.js:236

Available since 1.0.0

从上一点画弧到某一点,如果没有设置上一点,则上一点默认为(0,0)

Parameters:

Returns:

Void:

beginBitmapFill

(
  • image
  • matrix
)
Void public

Defined in libs/Shape.js:408

Available since 1.0.0

位图填充 一般给Annie2x用

Parameters:

  • image Image
  • matrix Array

Returns:

Void:

beginBitmapStroke

(
  • image
  • matrix
  • lineWidth
  • cap
  • join
  • miter
)
Void public

Defined in libs/Shape.js:469

Available since 1.0.0

线条位图填充 一般给Annie2x用

Parameters:

  • image Image
  • matrix Array
  • lineWidth Number
  • cap String

    线头的形状 butt round square 默认 butt

  • join String

    线与线之间的交接处形状 bevel round miter 默认miter

  • miter Number

    正数,规定最大斜接长度,如果斜接长度超过 miterLimit 的值,边角会以 lineJoin 的 "bevel" 类型来显示 默认10

Returns:

Void:

beginFill

(
  • color
)
Void public

Defined in libs/Shape.js:379

Available since 1.0.0

开始绘画填充,如果想画的东西有颜色填充,一定要从此方法开始

Parameters:

  • color String

    颜色值 单色和RGBA格式

Returns:

Void:

beginLinearGradientFill

(
  • points
  • colors
)
Void public

Defined in libs/Shape.js:390

Available since 1.0.0

线性渐变填充 一般给Annie2x用

Parameters:

  • points Array

    一组点

  • colors Array

    一组颜色值

Returns:

Void:

Example:

 var shape=new annie.Shape();
 shape.beginLinearGradientFill([0,0,200,0],[[0,"#ff0000",1],[0.164706,"#ffff00",1],[0.364706,"#00ff00",1],[0.498039,"#00ffff",1],[0.666667,"#0000ff",1],[0.831373,"#ff00ff",1],[1,"#ff0000",1]]);
 shape.drawRect(0,0,200,200);
 shape.endFill();
 s.addChild(shape);

beginLinearGradientStroke

(
  • points
  • colors
  • lineWidth
  • cap
  • join
  • miter
)
Void public

Defined in libs/Shape.js:449

Available since 1.0.0

画线性渐变的线条 一般给Annie2x用

Parameters:

  • points Array

    一组点

  • colors Array

    一组颜色值

  • lineWidth Number
  • cap Number

    线头的形状 0 butt 1 round 2 square 默认 butt

  • join Number

    线与线之间的交接处形状 0 miter 1 bevel 2 round 默认miter

  • miter Number

    正数,规定最大斜接长度,如果斜接长度超过 miterLimit 的值,边角会以 lineJoin 的 "bevel" 类型来显示 默认10

Returns:

Void:

beginRadialGradientFill

(
  • points
  • colors
  • matrixDate
)
Void public

Defined in libs/Shape.js:32

Available since 1.0.0

径向渐变填充 一般给Annie2x用

Parameters:

  • points Array

    一组点

  • colors Array

    一组颜色值

  • matrixDate Object

    如果渐变填充有矩阵变形信息

Returns:

Void:

Example:

 var shape=new annie.Shape();
 shape.beginRadialGradientFill([100,100,100,100,100],[[0,"#00ff00",1],[1,"#000000",1]]);
 shape.drawRect(0,0,200,200);
 shape.endFill();
 s.addChild(shape);

beginRadialGradientStroke

(
  • points
  • colors
  • lineWidth
  • cap
  • join
  • miter
)
Void public

Defined in libs/Shape.js:51

Available since 1.0.0

画径向渐变的线条 一般给Annie2x用

Parameters:

  • points Array

    一组点

  • colors Array

    一组颜色值

  • lineWidth Number
  • cap String

    线头的形状 butt round square 默认 butt

  • join String

    线与线之间的交接处形状 bevel round miter 默认miter

  • miter Number

    正数,规定最大斜接长度,如果斜接长度超过 miterLimit 的值,边角会以 lineJoin 的 "bevel" 类型来显示 默认10

Returns:

Void:

beginStroke

(
  • color
  • lineWidth
  • cap
  • join
  • miter
)
Void public

Defined in libs/Shape.js:430

Available since 1.0.0

给线条着色

Parameters:

  • color String

    颜色值

  • lineWidth Number

    宽度

  • cap Number

    线头的形状 0 butt 1 round 2 square 默认 butt

  • join Number

    线与线之间的交接处形状 0 miter 1 bevel 2 round 默认miter

  • miter Number

    正数,规定最大斜接长度,如果斜接长度超过 miterLimit 的值,边角会以 lineJoin 的 "bevel" 类型来显示 默认10

Returns:

Void:

bezierCurveTo

(
  • cp1X
  • cp1Y
  • cp2X
  • cp2Y
  • x
  • y
)
Void public

Defined in libs/Shape.js:263

Available since 1.0.0

三次贝赛尔曲线 从上一点画二次贝赛尔曲线到某一点,如果没有设置上一点,则上一占默认为(0,0)

Parameters:

Returns:

Void:

Bitmap

(
  • bitmapData
  • rect
)
public

Inherited from annie.Bitmap: libs/bitmap.js:29

Available since 1.0.0

构造函数

Parameters:

  • bitmapData Image | Video | Canvas
    一个HTMl Image的实例,小程序或者小游戏里则只能是一个图片的地址
  • rect annie.Rectangle
    设置显示Image的区域,不设置值则全部显示Image的内容,小程序或者小游戏里没有这个参数

Example:

 //html5
 var imgEle=new Image();
 imgEle.onload=function (e) {
     var bitmap = new annie.Bitmap(imgEle)
     //居中对齐
     bitmap.x = (s.stage.desWidth - bitmap.width) / 2;
     bitmap.y = (s.stage.desHeight - bitmap.height) / 2;
     s.addChild(bitmap);
     //截取图片的某一部分显示
     var rect = new annie.Rectangle(0, 0, 200, 200),
     rectBitmap = new annie.Bitmap(imgEle, rect);
     rectBitmap.x = (s.stage.desWidth - bitmap.width) / 2;
     rectBitmap.y = 100;
     s.addChild(rectBitmap);
 }
 imgEle.src='http://test.annie2x.com/test.jpg';
 //小程序或者小游戏
 var imgEle="http://test.annie2x.com/test.jpg";
 var bitmap=new annie.Bitmap(imgEle);
 s.addChild(bitmap);

测试链接

changeColor

(
  • infoObj
)
Void public

Defined in libs/Shape.js:782

Available since 1.0.2

如果有的话,改变矢量对象的边框或者填充的颜色.

Parameters:

  • infoObj Object
    • fillColor String | Any

      填充颜色值,如"#fff" 或者 "rgba(255,255,255,1)"或者是annie.Shape.getGradientColor()方法返回的渐变对象;

    • strokeColor String

      线条颜色值,如"#fff" 或者 "rgba(255,255,255,1)";

    • lineWidth Number

      线条的粗细,如"1,2,3...";

Returns:

Void:

clear

() Void public

Defined in libs/Shape.js:363

Available since 1.0.0

清除掉之前所有绘画的东西

Returns:

Void:

clearCustomTransform

(
  • transId
)
public

Inherited from annie.DisplayObject: libs/DisplayObject.js:1083

Available since 3.1.0

如果你在mc更改了对象的x y scale rotation alpha,最后想还原,不再需要自我控制,可以调用这方法

Parameters:

  • transId Number

    //0->x,1->y,2->scaleX,3->scaleY,4->rotation,5->alpha,-1->all

closePath

() Void public

Defined in libs/Shape.js:280

Available since 1.0.0

闭合一个绘画路径

Returns:

Void:

decodePath

(
  • data
)
Void public

Defined in libs/Shape.js:556

Available since 1.0.0

解析一段路径 一般给Annie2x用

Parameters:

Returns:

Void:

destroy

() Void public

Inherited from annie.AObject: libs/EventDispatcher.js:63

Available since 2.0.0

销毁一个对象 销毁之前一定要做完其他善后工作,否则有可能会出错 特别注意不能在对象自身方法或事件里调用此方法。 比如,不要在显示对象自身的 annie.Event.ON_REMOVE_TO_STAGE 或者其他类似事件调用,一定会报错

Returns:

Void:

dispatchEvent

(
  • event
  • data
  • useCapture
)
Boolean public

Inherited from annie.EventDispatcher: libs/EventDispatcher.js:156

Available since 1.0.0

广播侦听

Parameters:

  • event annie.Event | String

    广播所带的事件对象,如果传的是字符串则自动生成一个annie.Event对象,事件类型就是传入进来的字符串的值

  • data Object

    广播后跟着事件一起传过去的其他任信息,默认值为null

  • useCapture Boolean

    true 捕获阶段 false 冒泡阶段 默认 true

Returns:

Boolean:

如果有收听者则返回true

Example:

 var mySprite=new annie.Sprite(),
 yourEvent=new annie.Event("yourCustomerEvent");
 yourEvent.data={a:1,b:2,c:"hello",d:{aa:1,bb:2}};
 mySprite.addEventListener("yourCustomerEvent",function(e){
     console.log(e.data);
 })
 mySprite.dispatchEvent(yourEvent);

DisplayObject

() public

Inherited from annie.DisplayObject: libs/DisplayObject.js:78

Available since 1.0.0

drawArc

(
  • x
  • y
  • radius
  • start
  • end
)
Void public

Defined in libs/Shape.js:309

Available since 1.0.0

画一个弧形

Parameters:

Returns:

Void:

drawCircle

(
  • x
  • y
  • radius
)
Void public

Defined in libs/Shape.js:324

Available since 1.0.0

画一个圆

Parameters:

Returns:

Void:

drawEllipse

(
  • x
  • y
  • w
  • h
)
Void public

Defined in libs/Shape.js:337

Available since 1.0.0

画一个椭圆

Parameters:

Returns:

Void:

drawRect

(
  • x
  • y
  • w
  • h
)
Void public

Defined in libs/Shape.js:290

Available since 1.0.0

画一个矩形

Parameters:

Returns:

Void:

drawRoundRect

(
  • x
  • y
  • w
  • h
  • rTL
  • rTR
  • rBL
  • rBR
)
Void public

Defined in libs/Shape.js:155

Available since 1.0.0

画一个带圆角的矩形

Parameters:

Returns:

Void:

endFill

() Void public

Defined in libs/Shape.js:502

Available since 1.0.0

结束填充

Returns:

Void:

endStroke

() Void public

Defined in libs/Shape.js:535

Available since 1.0.0

结束画线

Returns:

Void:

getBitmapStyle

(
  • image
)
CanvasPattern public static

Defined in libs/Shape.js:104

Available since 1.0.0

设置位图填充时需要使用的方法,一般给用户使用较少,Annie2x工具自动使用

Parameters:

  • image Image

    HTML Image元素

Returns:

getDrawRect

() annie.Rectangle public

Inherited from annie.DisplayObject: libs/DisplayObject.js:682

Available since 1.0.0

获取对象形变后外切矩形 可以从这个方法中读取到此显示对象变形后x方向上的宽和y方向上的高

Returns:

getGradientColor

(
  • points
  • colors
)
Any public static

Defined in libs/Shape.js:79

Available since 1.0.0

通过一系统参数获取生成颜色或渐变所需要的对象 一般给用户使用较少,Annie2x工具自动使用

Parameters:

Returns:

Any:

getRGBA

(
  • color
  • alpha
)
String public static

Defined in libs/Shape.js:117

Available since 1.0.0

通过24位颜色值和一个透明度值生成RGBA值

Parameters:

  • color String

    字符串的颜色值,如:#33ffee

  • alpha Number

    0-1区间的一个数据 0完全透明 1完全不透明

Returns:

getSound

(
  • id
)
Array

Inherited from annie.DisplayObject: libs/DisplayObject.js:927

Available since 2.0.0

Parameters:

Returns:

Array:

这个对象里所有叫这个名字的声音引用数组

getWH

() W: number; h: number

Inherited from annie.DisplayObject: libs/DisplayObject.js:812

Available since 1.1.0

获取宽高

Returns:

W: number; h: number:

}

globalToLocal

(
  • point
)
annie.Point public

Inherited from annie.DisplayObject: libs/DisplayObject.js:579

Available since 1.0.0

将全局坐标转换到本地坐标值

Parameters:

Returns:

hasEventListener

(
  • type
  • useCapture
)
Boolean public

Inherited from annie.EventDispatcher: libs/EventDispatcher.js:215

Available since 1.0.0

是否有添加过此类型的侦听

Parameters:

  • type String

    侦听类型

  • useCapture Boolean

    true 捕获阶段 false 冒泡阶段 默认 true

Returns:

Boolean:

如果有则返回true

hitTestPoint

(
  • hitPoint
  • isGlobalPoint
)
annie.DisplayObject public

Inherited from annie.DisplayObject: libs/DisplayObject.js:620

Available since 1.0.0

点击碰撞测试,就是舞台上的一个point是否在显示对象内,在则返回该对象,不在则返回null

Parameters:

  • hitPoint annie.Point

    要检测碰撞的点

  • isGlobalPoint Boolean

    是不是全局坐标的点,默认false是本地坐标

lineTo

(
  • x
  • y
)
Void public

Defined in libs/Shape.js:224

Available since 1.0.0

从上一点画到某一点,如果没有设置上一点,则上一点默认为(0,0)

Parameters:

Returns:

Void:

localToGlobal

(
  • point
)
annie.Point public

Inherited from annie.DisplayObject: libs/DisplayObject.js:591

Available since 1.0.0

将本地坐标转换到全局坐标值

Parameters:

Returns:

moveTo

(
  • x
  • y
)
Void public

Defined in libs/Shape.js:212

Available since 1.0.0

绘画时移动到某一点

Parameters:

Returns:

Void:

quadraticCurveTo

(
  • cpX
  • cpX
  • x
  • y
)
Void public

Defined in libs/Shape.js:248

Available since 1.0.0

二次贝赛尔曲线 从上一点画二次贝赛尔曲线到某一点,如果没有设置上一点,则上一占默认为(0,0)

Parameters:

Returns:

Void:

removeAllEventListener

() Void public

Inherited from annie.EventDispatcher: libs/EventDispatcher.js:268

Available since 1.0.0

移除对象中所有的侦听

Returns:

Void:

removeEventListener

(
  • type
  • listener
  • useCapture
)
Void public

Inherited from annie.EventDispatcher: libs/EventDispatcher.js:239

Available since 1.0.0

移除对应类型的侦听

Parameters:

  • type String

    要移除的侦听类型

  • listener Function

    侦听时绑定的回调方法

  • useCapture Boolean

    true 捕获阶段 false 冒泡阶段 默认 true

Returns:

Void:

removeSound

(
  • id
)
Void public

Inherited from annie.DisplayObject: libs/DisplayObject.js:968

Available since 2.0.0

删除一个已经添加进来的声音

Parameters:

Returns:

Void:

setLineDash

(
  • data
)
Void

Defined in libs/Shape.js:522

Available since 2.0.2

设置虚线参数

Parameters:

  • data Array

    一个长度为2的数组,第1个是虚线长度,第2个是虚线间隔,如果此参数为[]的空数组,则是清除虚线。 如[5,20]是画虚线,[]则是请除虚线,变为实线

Returns:

Void:

startDrag

(
  • isCenter
  • bounds
)
Void public

Inherited from annie.DisplayObject: libs/DisplayObject.js:1046

Available since 1.1.2

启动鼠标或者触摸拖动

Parameters:

  • isCenter Boolean

    指定将可拖动的对象锁定到指针位置中心 (true),还是锁定到用户第一次单击该对象的位置 (false) 默认false

  • bounds annie.Rectangle

    相对于显示对象父级的坐标的值,用于指定 Sprite 约束矩形

Returns:

Void:

stopAllSounds

() Void public

Inherited from annie.DisplayObject: libs/DisplayObject.js:853

Available since 2.0.0

停止这个显示对象上的所有声音

Returns:

Void:

stopDrag

()

停止鼠标跟随

Properties

alpha

Number public

Inherited from annie.DisplayObject: libs/DisplayObject.js:339

Available since 1.0.0

显示对象透明度

Default: 1

anchorX

Number public

Inherited from annie.DisplayObject: libs/DisplayObject.js:410

Available since 1.0.0

显示对象上x方向的缩放或旋转点

Default: 0

anchorY

Number public

Inherited from annie.DisplayObject: libs/DisplayObject.js:432

Available since 1.0.0

显示对象上y方向的缩放或旋转点

Default: 0

bitmapData

Any public

Inherited from annie.Bitmap: libs/bitmap.js:70

Available since 1.0.0

小游戏不支持 小程序不支持

HTML的一个Image对象或者是canvas对象或者是video对象

Default: null

blendMode

Number public

Inherited from annie.DisplayObject: libs/DisplayObject.js:476

Available since 1.0.0

显示对象的混合模式 支持的混合模式大概有23种,具体查看annie.BlendMode

Default: 0

cacheAsBitmap

Unknown

Inherited from annie.DisplayObject: libs/DisplayObject.js:201

Available since 3.2.0

是否将这个对象缓存为位图了

filters

Array public

Inherited from annie.DisplayObject: libs/DisplayObject.js:545

Available since 1.0.0

小游戏不支持 小程序不支持

显示对象的滤镜数组

Default: null

height

Unknown public

Inherited from annie.DisplayObject: libs/DisplayObject.js:824

Available since 1.0.3

获取或者设置显示对象在父级里的y方向的高,不到必要不要用此属性获取高 如果你要同时获取宽高,建议使用getWH()方法获取宽和高

hitArea

Unknown

Inherited from annie.DisplayObject: libs/DisplayObject.js:607

Available since 3.0.1

annie.Sprite显示容器的接受鼠标点击的区域。一但设置,容器里所有子级将不会触发任何鼠标相关的事件。 相当于 mouseChildren=false,但在有大量子级显示对象的情况下,此方法的性能搞出mouseChildren几个数量级,建议使用。

Sub-properties:

hitTestWithPixel

Boolean

Inherited from annie.DisplayObject: libs/DisplayObject.js:157

Available since 1.1.0

小游戏不支持 小程序不支持

是否对图片对象使用像素碰撞检测透明度,默认关闭

Default: false

instanceId

Number public

Inherited from annie.AObject: libs/EventDispatcher.js:31

Available since 1.0.0

每一个annie引擎对象都会有一个唯一的id码。

Example:

 //获取 annie引擎类对象唯一码
 console.log(this.instanceId);

instanceType

String public

Inherited from annie.AObject: libs/EventDispatcher.js:49

Available since 1.0.3

每一个annie类都有一个实例类型字符串,通过这个字符串,你能知道这个实例是从哪个类实例而来

isCache

Boolean

Inherited from annie.DisplayObject: libs/DisplayObject.js:188

Available since 3.2.0

是否被缓存了

mask

annie.DisplayObject public

Inherited from annie.DisplayObject: libs/DisplayObject.js:516

Available since 1.0.0

显示对象的遮罩, 是一个Shape显示对象或是一个只包含shape显示对象的MovieClip

Default: null

matrix

annie.Matrix public

Inherited from annie.DisplayObject: libs/DisplayObject.js:500

Available since 1.0.0

显示对象的变形矩阵

Default: null

mouseEnable

Boolean public

Inherited from annie.DisplayObject: libs/DisplayObject.js:116

Available since 1.0.0

是否可以接受点击事件,如果设置为false,此显示对象将无法接收到点击事件

Default: false

name

String public

Inherited from annie.DisplayObject: libs/DisplayObject.js:127

Available since 1.0.0

每一个显示对象都可以给他命一个名字,这样我们在查找子级的时候就可以直接用this.getChildrndByName("name")获取到这个对象的引用

Default: ""

parent

annie.Sprite public

Inherited from annie.DisplayObject: libs/DisplayObject.js:101

Available since 1.0.0

显示对象的父级

Default: null

rotation

Number public

Inherited from annie.DisplayObject: libs/DisplayObject.js:314

Available since 1.0.0

显示对象旋转角度

Default: 0

scaleX

Number public

Inherited from annie.DisplayObject: libs/DisplayObject.js:268

Available since 1.0.0

显示对象x方向的缩放值

Default: 1

scaleY

Number public

Inherited from annie.DisplayObject: libs/DisplayObject.js:291

Available since 1.0.0

显示对象y方向的缩放值

Default: 1

skewX

Number public

Inherited from annie.DisplayObject: libs/DisplayObject.js:362

Available since 1.0.0

显示对象x方向的斜切值

Default: 0

skewY

Number public

Inherited from annie.DisplayObject: libs/DisplayObject.js:386

Available since 1.0.0

显示对象y方向的斜切值

Default: 0

soundList

Array public

Inherited from annie.DisplayObject: libs/DisplayObject.js:170

Available since 2.0.0

当前对象包含的声音列表

Default: []

stage

Stage public

Inherited from annie.DisplayObject: libs/DisplayObject.js:91

Available since 1.0.0

此显示对象所在的舞台对象,如果此对象没有被添加到显示对象列表中,此对象为空。

Default: null;

visible

Boolean public

Inherited from annie.DisplayObject: libs/DisplayObject.js:454

Available since 1.0.0

显未对象是否可见

Default: 0

width

Unknown public

Inherited from annie.DisplayObject: libs/DisplayObject.js:783

Available since 1.0.3

获取或者设置显示对象在父级里的x方向的宽,不到必要不要用此属性获取高 如果你要同时获取宽高,建议使用 getWH()方法获取宽和高

x

Number public

Inherited from annie.DisplayObject: libs/DisplayObject.js:222

Available since 1.0.0

显示对象位置x

Default: 0

y

Number public

Inherited from annie.DisplayObject: libs/DisplayObject.js:245

Available since 1.0.0

显示对象位置y

Default: 0

Events

ADD_TO_STAGE

Inherited from annie.DisplayObject: libs/DisplayObject.js:31

Available since 1.0.0

annie.DisplayObject显示对象加入到舞台事件

CLICK

String

annie.DisplayObject鼠标或者手指单击

ENTER_FRAME

Inherited from annie.DisplayObject: libs/DisplayObject.js:41

Available since 1.0.0

annie.DisplayObject显示对象 循环帧事件

MOUSE_DOWN

Inherited from annie.DisplayObject: libs/DisplayObject.js:47

Available since 1.0.0

annie.DisplayObject鼠标或者手指按下事件

MOUSE_MOVE

Inherited from annie.DisplayObject: libs/DisplayObject.js:62

Available since 1.0.0

annie.DisplayObject鼠标或者手指移动事件

MOUSE_OUT

Inherited from annie.DisplayObject: libs/DisplayObject.js:72

Available since 1.0.0

annie.DisplayObject鼠标或者手指移出显示对象边界触发的事件

MOUSE_OVER

Inherited from annie.DisplayObject: libs/DisplayObject.js:67

Available since 1.0.0

annie.DisplayObject鼠标或者手指移入到显示对象上里触发的事件

MOUSE_UP

Inherited from annie.DisplayObject: libs/DisplayObject.js:52

Available since 1.0.0

annie.DisplayObject鼠标或者手指抬起事件

REMOVE_TO_STAGE

Inherited from annie.DisplayObject: libs/DisplayObject.js:36

Available since 1.0.0

annie.DisplayObject显示对象从舞台移出事件