new Ycc.Layer(yccInstance, option)
图层类。
每新建一个图层,都会新建一个canvas元素。
每个图层都跟这个canvas元素绑定。
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
yccInstance |
Ycc | ycc实例 | ||||||
option |
object |
配置项
|
Extends
Members
-
ctxCanvasRenderingContext2D
-
当前图层的绘图环境
-
ctxCache
-
图层的缓存绘图环境
-
ctxCacheRectYcc.Math.Rect
-
缓存时drawImage所绘制的最小区域
-
disableTypeObject
-
被禁用的事件类型。key为type,val为boolean
-
enableEventManagerboolean
-
是否监听舞台的事件。用于控制舞台事件是否广播至图层。默认关闭
-
enableFrameEventboolean
-
是否接收每帧更新的通知。默认为false
-
ghostboolean
-
图层是否幽灵,幽灵状态的图层,getUIFromPointer 会直接跳过整个图层
-
heightnumber
-
图层高
-
id
-
图层id
-
listenersObject
-
所有的监听器。key为type,val为listener数组。
-
namestring
-
图层名称
-
onclickfunction
-
点击 的监听。默认为null
-
ondragendfunction
-
拖拽结束 的监听。默认为null
-
ondraggingfunction
-
拖拽 的监听。默认为null
-
ondragstartfunction
-
拖拽开始 的监听。默认为null
-
onmousedownfunction
-
鼠标按下 的监听。默认为null
-
onmousemovefunction
-
鼠标移动 的监听。默认为null
-
onmouseoutfunction
-
鼠标移出 的监听。默认为null
-
onmouseoverfunction
-
鼠标移入 的监听。默认为null
-
onmouseupfunction
-
鼠标抬起 的监听。默认为null
-
ontapfunction
-
点击事件 的监听。默认为null
-
ontouchendfunction
-
触摸结束 的监听。默认为null
-
ontouchmovefunction
-
触摸移动 的监听。默认为null
-
ontouchstartfunction
-
触摸开始 的监听。默认为null
-
renderCacheRectboolean
-
是否以红色方框框选缓存的最小区域,调试时可使用
-
show
-
图层是否显示
-
stopAllEventboolean
-
只会阻止当前UI事件的触发,不会阻止其下面子元素事件的触发
-
stopTypeObject
-
被阻止的事件类型。key为type,val为boolean
-
textValuestring
-
图层中的文字。仅当图层type为text时有值。
-
type
-
图层类型。 `ui`表示用于绘图的图层。`tool`表示辅助的工具图层。`text`表示文字图层。 默认为`ui`。
-
uiCountRecursionnumber
-
该图层ui的总数(只在渲染之后赋值)
-
uiCountRenderednumber
-
该图层渲染的ui总数(只在渲染之后赋值)
-
uiListArray.<Ycc.UI>
-
存储图层中的所有UI。UI的顺序,即为图层中的渲染顺序。
-
useCacheboolean
-
是否使用独立的缓存canvas
-
widthnumber
-
图层宽
-
xnumber
-
图层位置的x坐标。默认与舞台左上角重合
-
ynumber
-
图层位置的Y坐标。默认与舞台左上角重合
-
yccClass
-
类型
-
yccInstance
-
ycc实例的引用
Methods
-
staticYcc.Layer.release(layer)
-
释放layer的内存,等待GC 将所有引用属性置为null
Name Type Description layer -
inherited addListener(type, listener)
-
添加某个类型的监听器
Name Type Description typestring listenerfunction -
addUI(ui, beforeUI)
-
添加一个UI图形至图层,如果设置了beforUI,该UI会被添加至该UI之前
Name Type Description uiYcc.UI UI图形 beforeUIYcc.UI | null UI图形 -
clear()
-
清除图层
-
clearCache()
-
清空缓存画布、缓存区域
-
inherited disableEvent(type)
-
禁止某个事件触发
Name Type Description type -
getUIFromPointer(dot, uiIsShow){UI}
-
获取图层中某个点所对应的最上层UI,最上层UI根据层级向下遍历,取层级最深的可见UI。
Name Type Description dotYcc.Math.Dot 点坐标,为舞台的绝对坐标 uiIsShowBoolean 是否只获取显示在舞台上的UI,默认为true Returns:
Type Description UI -
getUIListFromPointer(dot){Array.<Ycc.UI>}
-
获取图层中某个点所对应的所有UI,无论显示不显示,无论是否是幽灵,都会获取。
Name Type Description dotYcc.Math.Dot 点坐标,为舞台的绝对坐标 Returns:
Type Description Array.<Ycc.UI> -
init(){null}
-
初始化
Returns:
Type Description null -
onFrameComing()
-
若接收通知,此函数为接收通知的回调函数。当且仅当enableFrameEvent为true时生效
-
removeAllUI()
-
清空图层内的所有UI
-
inherited removeListener(type, listener)
-
移除某个类型的监听器
Name Type Description typelistener -
removeSelf()
-
删除自身
-
removeUI(ui)
-
删除图层内的某个UI图形,及其子UI
Name Type Description ui -
render(forceUpdate)
-
渲染Layer中的所有UI,
直接将UI的离屏canvas绘制至上屏canvas。Name Type Description forceUpdateboolean 是否强制更新 若强制更新,所有图层会强制更新缓存 若非强制更新,对于使用缓存的图层,只会绘制缓存至舞台 -
renderAllToCtx(ctx)
-
绘制所有UI至某个绘图环境
Name Type Description ctx -
renderCacheToStage(forceUpdate)
-
绘制缓存区域至上屏canvas
Name Type Description forceUpdateboolean 是否强制更新,若为true,绘制之前先重新绘制缓存 -
renderToStage()
-
渲染图层至舞台
- Deprecated
- Yes
-
reRender(forceUpdate)
-
重绘图层。
直接将UI的离屏canvas绘制至上屏canvas。Name Type Description forceUpdateboolean 是否强制更新 若强制更新,所有图层会强制更新缓存 若非强制更新,对于使用缓存的图层,只会绘制缓存至舞台 -
inherited resumeEvent(type)
-
恢复某个事件的触发
Name Type Description type -
inherited stop(type)
-
阻止某个事件类型继续传递
Name Type Description type -
transformToAbsolute(dotOrArr){Ycc.Math.Dot|Array.<Ycc.Math.Dot>}
-
根据图层坐标,将图层内某个点的相对坐标(相对于图层),转换为舞台的绝对坐标
Name Type Description dotOrArrYcc.Math.Dot | Array.<Ycc.Math.Dot> Returns:
Type Description Ycc.Math.Dot | Array.<Ycc.Math.Dot> -
transformToLocal(dotOrArr){Ycc.Math.Dot|Array.<Ycc.Math.Dot>}
-
根据图层坐标,将某个点的绝对坐标,转换为图层内的相对坐标
Name Type Description dotOrArrYcc.Math.Dot | Array.<Ycc.Math.Dot> Returns:
Type Description Ycc.Math.Dot | Array.<Ycc.Math.Dot> -
inherited triggerListener(type, data)
-
触发某一类型的监听器
Name Type Description typedata -
updateCache()
-
更新图层的缓存绘图环境