当前位置

网站首页> 程序设计 > 开源项目 > 程序开发 > 浏览文章

【easeljs】显示对象基础 DisplayObject 类 - 黒之染

作者:小梦 来源: 网络 时间: 2024-02-26 阅读:

类介绍

继承自 EventDispatcher

DisplayObject is an abstract class that should not be constructed directly. Instead construct subclasses such as Container, Bitmap, and Shape. DisplayObject is the base class for all display classes in the EaselJS library. It defines the core properties and methods that are shared between all display objects, such as transformation properties (x, y, scaleX, scaleY, etc), caching, and mouse handlers.

函数方法

cache ( x y width height [scale=1] )

Defined in cache:749
把此显示对象写进一个新的隐藏的canvas,然后用于接下来的绘制。此显示对象可能有多个child,也可能有多个滤镜,stage每次update需要绘制这个对象的时候都会重新绘制所有child和滤镜,因此可以用这个缓存起来,下次直接把它放上画布速度就快了。缓存好的这个显示对象,可以自由地移动、旋转、渐消(faded)。然而,如果它的内容发生变化,你必须手动调用updateCache() 或者重新使用 cache()。你必须通过x, y, w, 和 h参数,指定缓存的区域,这里指定的矩形区域会被渲染和缓存,且使用的是这个对象的坐标系。

例如如果你定义了一个形状,而且在形状里0,0位置画一个半径25的圆形:

 var shape = new createjs.Shape(); shape.graphics.beginFill("#ff0000").drawCircle(0, 0, 25); myShape.cache(-25, -25, 50, 50); 

注意:滤镜要在缓存之前指定。一些滤镜(例如 BlurFilter)和scale一起使用是不会产生效果的。
通常,缓存canvas的面积是widthscale乘以heightscale,然而一些滤镜(例如 BlurFilter)会给canvas的面积添加padding。
Parameters:

x Number
The x coordinate origin for the cache region.
y Number
The y coordinate origin for the cache region.
width Number
The width of the cache region.
height Number
The height of the cache region.
[scale=1] Number optional
The scale at which the cache will be created. For example, if you cache a vector shape using myShape.cache(0,0,100,100,2) then the resulting cacheCanvas will be 200x200 px. This lets you scale and rotate cached elements with greater fidelity. Default is 1.

网友最爱