Show:

annie.Stage Class

Extends annie.Sprite
Defined in: libs/Stage.js:19
Module: annie

Available since 1.0.0

Stage 表示显示 canvas 内容的整个区域,所有显示对象的顶级显示容器

Methods

_updateSplitBounds

() private

更新boundsList矩阵

addChild

(
  • child
)
Void public

Inherited from annie.Sprite: libs/Sprite.js:87

Available since 1.0.0

添加一个显示对象到Sprite

Parameters:

Returns:

Void:

addChildAt

(
  • child
  • index
)
Void public

Inherited from annie.Sprite: libs/Sprite.js:177

Available since 1.0.0

添加一个child到Sprite中并指定添加到哪个层级

Parameters:

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:

addUpdateObj

(
  • target
)
Void public static

Defined in libs/Stage.js:911

添加一个刷新对象,这个对象里一定要有一个 flush 函数。 因为一但添加,这个对象的 flush 函数会以stage的fps间隔调用 如,你的stage是30fps 那么你这个对象的 flush 函数1秒会调用30次。

Parameters:

  • target Object

    要循化调用 flush 函数的对象

Returns:

Void:

allUpdateObjList

() static

Defined in libs/Stage.js:981

Available since 1.0.0

要循环调用 flush 函数对象列表

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

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

getChildAt

(
  • index
)
annie.DisplayObject public

Inherited from annie.Sprite: libs/Sprite.js:226

Available since 1.0.0

获取Sprite中指定层级一个child

Parameters:

getChildByName

(
  • name
  • isOnlyOne
  • isRecursive
)
String | Array public

Inherited from annie.Sprite: libs/Sprite.js:141

Available since 1.0.0

通过给displayObject设置的名字来获取一个child,可以使用正则匹配查找

Parameters:

  • name String

    对象的具体名字或是一个正则表达式

  • isOnlyOne Boolean

    默认为true,如果为true,只返回最先找到的对象,如果为false则会找到所有匹配的对象数组

  • isRecursive Boolean

    false,如果为true,则会递归查找下去,而不只是查找当前对象中的child,child里的child也会找,依此类推

Returns:

String | Array:

返回一个对象,或者一个对象数组,没有找到则返回空

getChildIndex

(
  • child
)
Number public

Inherited from annie.Sprite: libs/Sprite.js:242

Available since 1.0.2

获取Sprite中一个child所在的层级索引,找到则返回索引数,未找到则返回-1

Parameters:

Returns:

getDrawRect

() annie.Rectangle public

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

Available since 1.0.0

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

Returns:

getFrameRate

() Number public

Defined in libs/Stage.js:454

Available since 1.0.0

引擎的刷新率,就是一秒中执行多少次刷新

Returns:

getRootDivWH

(
  • div
)
Object public

Defined in libs/Stage.js:464

Available since 1.0.0

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

获取引擎所在的div宽高

Parameters:

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是本地坐标

localToGlobal

(
  • point
)
annie.Point public

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

Available since 1.0.0

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

Parameters:

Returns:

removeAllChildren

() Void public

Inherited from annie.Sprite: libs/Sprite.js:334

Available since 1.0.0

移除Sprite上的所有child

Returns:

Void:

removeAllEventListener

() Void public

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

Available since 1.0.0

移除对象中所有的侦听

Returns:

Void:

removeChild

(
  • child
)
Void public

Inherited from annie.Sprite: libs/Sprite.js:98

Available since 1.0.0

从Sprite中移除一个child

Parameters:

Returns:

Void:

removeChildAt

(
  • index
)
Void public

Inherited from annie.Sprite: libs/Sprite.js:295

Available since 1.0.0

移除指定层级上的孩子

Parameters:

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:

removeUpdateObj

(
  • target
)
Void public static

Defined in libs/Stage.js:935

Available since 1.0.0

移除掉已经添加的循环刷新对象

Parameters:

Returns:

Void:

resize

() Void public

Defined in libs/Stage.js:242

Available since 1.0.0

当舞台尺寸发生改变时,如果stage autoResize 为 true,则此方法会自己调用; 如果设置stage autoResize 为 false 你需要手动调用此方法以更新界面. 不管autoResize 的状态是什么,你只要侦听 了stage 的 annie.Event.RESIZE 事件 都可以接收到舞台变化的通知。

Returns:

Void:

setFrameRate

(
  • fps
)
Void public

Defined in libs/Stage.js:439

Available since 1.0.0

引擎的刷新率,就是一秒中执行多少次刷新

Parameters:

  • fps Number

    最好是60的倍数如 1 2 3 6 10 12 15 20 30 60

Returns:

Void:

Sprite

() public

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

Available since 1.0.0

构造函数

Stage

(
  • rootDivId
  • desW
  • desH
  • fps
  • scaleMode
  • renderType
)
public

Defined in libs/Stage.js:28

Available since 1.0.0

显示对象入口函数

Parameters:

  • rootDivId String
  • desW Number

    舞台宽

  • desH Number

    舞台高

  • fps Number

    刷新率

  • scaleMode String

    缩放模式 StageScaleMode

  • renderType Number

    渲染模式0:canvas 1:webGl 2:dom

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

()

停止鼠标跟随

swapChild

(
  • child1
  • child2
)
Boolean

Inherited from annie.Sprite: libs/Sprite.js:260

Available since 2.0.0

交换两个显示对象的层级

Parameters:

  • child1 Object

    显示对象,或者显示对象的索引

  • child2 Object

    显示对象,或者显示对象的索引

Returns:

updateCache

() Void

Inherited from annie.Sprite: libs/Sprite.js:325

Available since 3.2.0

如果对容器缓存为位图过,则会更新缓存,没事别乱调用

Returns:

Void:

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

autoResize

Boolean public

Defined in libs/Stage.js:147

Available since 1.0.0

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

当设备尺寸更新,或者旋转后是否自动更新舞台尺寸 默认不开启

Default: false

autoSteering

Boolean public

Defined in libs/Stage.js:136

Available since 1.0.0

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

当设备尺寸更新,或者旋转后是否自动更新舞台方向 默认不开启

Default: false

bgColor

String #FFFFFF" 或 RGB(255,255,255) 或 RGBA(255,255,255,255) public

Defined in libs/Stage.js:198

Available since 1.0.0

舞台的背景色 默认为""就是透明背景 可能设置一个颜色值改变舞台背景

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

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

children

Array public

Inherited from annie.Sprite: libs/Sprite.js:60

Available since 1.0.0

显示对象的child列表

Default: []

desHeight

Number public

Defined in libs/Stage.js:168

Available since 1.0.0

舞台的尺寸高,也就是我们常说的设计尺寸

Default: 240

desWidth

Number public

Defined in libs/Stage.js:158

Available since 1.0.0

舞台的尺寸宽,也就是我们常说的设计尺寸

Default: 320

divHeight

Number public

Defined in libs/Stage.js:178

Available since 1.0.0

舞台在当前设备中的真实高

Default: 320

divWidth

Number public

Defined in libs/Stage.js:188

Available since 1.0.0

舞台在当前设备中的真实宽

Default: 240

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类都有一个实例类型字符串,通过这个字符串,你能知道这个实例是从哪个类实例而来

iosTouchendPreventDefault

Boolean public

Defined in libs/Stage.js:69

Available since 1.0.4

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

是否阻止ios端双击后页面会往上弹的效果,因为如果阻止了,可能有些html元素出现全选框后无法取消 所以需要自己灵活设置,默认阻止.

Default: true

isCache

Boolean

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

Available since 3.2.0

是否被缓存了

isMultiMouse

Boolean

Defined in libs/Stage.js:129

Available since 1.1.3

开启或关闭多个手指的鼠标事件

isMultiTouch

Boolean

Defined in libs/Stage.js:122

Available since 1.0.3

开启或关闭多点手势事件 目前仅支持两点 旋转 缩放

isPreventDefaultEvent

Boolean

Defined in libs/Stage.js:80

Available since 1.0.9

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

是否禁止引擎所在的DIV的鼠标事件或触摸事件的默认行为,默认为true是禁止的。

Default: true

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

mcSpeed

Number public

Inherited from annie.Sprite: libs/Sprite.js:39

Available since 3.1.5

容器类所有动画的播放速度,默认是1.如果有嵌套的话,速度相乘;

Default: 1

mouseChildren

Boolean public

Inherited from annie.Sprite: libs/Sprite.js:50

Available since 1.0.0

是否可以让children接收鼠标事件 鼠标事件将不会往下冒泡

Default: true

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

pause

Boolean public static

Defined in libs/Stage.js:326

Available since 1.0.0

是否暂停

Default: false

renderObj

IRender public

Defined in libs/Stage.js:100

Available since 1.0.0

当前stage所使用的渲染器 渲染器有两种,一种是canvas 一种是webGl

Default: null

renderType

Number public

Defined in libs/Stage.js:110

Available since 1.0.0

渲染模式值 只读 CANVAS:0, webGl: 1

Default: 0

rootDiv

Html Div public

Defined in libs/Stage.js:89

Available since 1.0.0

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

整个引擎的最上层的div元素, 承载canvas的那个div html元素

Default: null

rotation

Number public

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

Available since 1.0.0

显示对象旋转角度

Default: 0

scaleMode

String public

Defined in libs/Stage.js:358

Available since 1.0.0

舞台的缩放模式 默认为空就是无缩放的真实大小 "noBorder" 无边框模式 ”showAll" 显示所有内容 “fixedWidth" 固定宽 ”fixedHeight" 固定高

Default: "onScale"

Example:

 //动态更改stage的对齐方式示例
 //以下代码放到一个舞台的显示对象的构造函数中
 let s=this;
 s.addEventListener(annie.Event.ADD_TO_STAGE,function(e){
     let i=0;
     s.stage.addEventListener(annie.MouseEvent.CLICK,function(e){
         let aList=[annie.StageScaleMode.EXACT_FIT,annie.StageScaleMode.NO_BORDER,annie.StageScaleMode.NO_SCALE,annie.StageScaleMode.SHOW_ALL,annie.StageScaleMode.FIXED_WIDTH,annie.StageScaleMode.FIXED_HEIGHT]
         let state=e.currentTarget;
         state.scaleMode=aList[i];
         if(i>5){i=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;

viewRect

annie.Rectangle public

Defined in libs/Stage.js:883

Available since 1.0.0

舞台在设备里截取后的可见区域,有些时候知道可见区域是非常重要的,因为这样你就可以根据舞台的可见区域做自适应了。

Default: {x:0,y:0,width:0,height:0}

Example:

 //始终让一个对象顶对齐,或者

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显示对象加入到舞台事件

annie.Event.ON_INIT_STAGE

Defined in libs/Stage.js:48

Available since 1.0.0

annie.Stage舞台初始化完成后会触发的事件

annie.Event.ON_RUN_CHANGED

Defined in libs/Stage.js:59

Available since 1.0.0

annie引擎暂停或者恢复暂停时触发,这个事件只能在annie.globalDispatcher中监听

annie.Event.RESIZE

Defined in libs/Stage.js:53

Available since 1.0.0

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

annie.Stage舞台尺寸发生变化时触发

annie.TouchEvent.ON_MULTI_TOUCH

String

Defined in libs/Stage.js:64

annie.Stage 的多点触碰事件。这个事件只能在annie.Stage对象上侦听

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显示对象从舞台移出事件