File Index
24 | 25 |{+new Link().toSrc(item.alias).withText(item.name)+}
28 |-
30 |
- Author: 32 |
- {+item.author+} 33 |
- Version: 36 |
- {+item.version+} 37 |
- Location: 41 |
- {+location+} 43 |
48 |
├── docs ├── images │ ├── logo.jpg │ ├── logo.png │ ├── quark.jpg │ ├── mine_260.jpg │ ├── dolphin_260.jpg │ ├── fishjoy_260.jpg │ ├── runner_260.jpg │ ├── displayobject.jpg │ ├── dolphin_main_s.jpg │ ├── infrastructure.jpg │ ├── dolphin_startup_s.jpg │ └── displayobject_lifecircle.jpg ├── img │ ├── glyphicons-halflings.png │ └── glyphicons-halflings-white.png ├── api_template │ ├── allclasses.tmpl │ ├── static │ │ ├── index.html │ │ ├── header.html │ │ └── default.css │ ├── symbol.tmpl │ ├── allfiles.tmpl │ ├── index.tmpl │ └── publish.js ├── css │ ├── prettify.css │ └── bootstrap-responsive.min.css ├── index.html ├── demo.html ├── tutorial_context.html ├── tutorial_event.html ├── tutorial_infrastructure.html ├── tutorial_displayobject.html ├── tutorial.html ├── api │ ├── index.html │ └── symbols │ │ └── Drawable.html └── tutorial_squirrel.html ├── examples ├── images │ ├── bg.jpg │ ├── boy.png │ ├── btns.png │ ├── girl.png │ ├── mask.png │ └── turn.png ├── squirrel │ ├── images │ │ ├── body_walk.png │ │ └── head_idle.png │ ├── Squirrel.js │ └── squirrel.html ├── imageloader.html ├── tween1.html ├── tween2.html ├── button.html ├── text.html ├── mask.html ├── graphics.html ├── hittest.html └── simple1.html ├── src └── base │ ├── utils │ ├── UIDUtil.js │ ├── Audio.js │ ├── Timer.js │ ├── ImageLoader.js │ └── Utils.js │ ├── context │ ├── Context.js │ ├── CanvasContext.js │ └── DOMContext.js │ ├── display │ ├── Bitmap.js │ ├── Drawable.js │ ├── Stage.js │ ├── MovieClip.js │ ├── Button.js │ ├── Text.js │ ├── Graphics.js │ ├── DisplayObjectContainer.js │ └── DisplayObject.js │ ├── event │ ├── EventConst.js │ ├── EventDispatcher.js │ └── EventManager.js │ └── geom │ ├── Rectangle.js │ └── Matrix.js ├── LICENSE ├── CHANGES └── README.md /docs/images/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quark-dev-team/quarkjs/HEAD/docs/images/logo.jpg -------------------------------------------------------------------------------- /docs/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quark-dev-team/quarkjs/HEAD/docs/images/logo.png -------------------------------------------------------------------------------- /docs/images/quark.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quark-dev-team/quarkjs/HEAD/docs/images/quark.jpg -------------------------------------------------------------------------------- /examples/images/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quark-dev-team/quarkjs/HEAD/examples/images/bg.jpg -------------------------------------------------------------------------------- /docs/images/mine_260.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quark-dev-team/quarkjs/HEAD/docs/images/mine_260.jpg -------------------------------------------------------------------------------- /examples/images/boy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quark-dev-team/quarkjs/HEAD/examples/images/boy.png -------------------------------------------------------------------------------- /examples/images/btns.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quark-dev-team/quarkjs/HEAD/examples/images/btns.png -------------------------------------------------------------------------------- /examples/images/girl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quark-dev-team/quarkjs/HEAD/examples/images/girl.png -------------------------------------------------------------------------------- /examples/images/mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quark-dev-team/quarkjs/HEAD/examples/images/mask.png -------------------------------------------------------------------------------- /examples/images/turn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quark-dev-team/quarkjs/HEAD/examples/images/turn.png -------------------------------------------------------------------------------- /docs/images/dolphin_260.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quark-dev-team/quarkjs/HEAD/docs/images/dolphin_260.jpg -------------------------------------------------------------------------------- /docs/images/fishjoy_260.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quark-dev-team/quarkjs/HEAD/docs/images/fishjoy_260.jpg -------------------------------------------------------------------------------- /docs/images/runner_260.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quark-dev-team/quarkjs/HEAD/docs/images/runner_260.jpg -------------------------------------------------------------------------------- /docs/images/displayobject.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quark-dev-team/quarkjs/HEAD/docs/images/displayobject.jpg -------------------------------------------------------------------------------- /docs/images/dolphin_main_s.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quark-dev-team/quarkjs/HEAD/docs/images/dolphin_main_s.jpg -------------------------------------------------------------------------------- /docs/images/infrastructure.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quark-dev-team/quarkjs/HEAD/docs/images/infrastructure.jpg -------------------------------------------------------------------------------- /docs/images/dolphin_startup_s.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quark-dev-team/quarkjs/HEAD/docs/images/dolphin_startup_s.jpg -------------------------------------------------------------------------------- /docs/img/glyphicons-halflings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quark-dev-team/quarkjs/HEAD/docs/img/glyphicons-halflings.png -------------------------------------------------------------------------------- /docs/images/displayobject_lifecircle.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quark-dev-team/quarkjs/HEAD/docs/images/displayobject_lifecircle.jpg -------------------------------------------------------------------------------- /docs/img/glyphicons-halflings-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quark-dev-team/quarkjs/HEAD/docs/img/glyphicons-halflings-white.png -------------------------------------------------------------------------------- /examples/squirrel/images/body_walk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quark-dev-team/quarkjs/HEAD/examples/squirrel/images/body_walk.png -------------------------------------------------------------------------------- /examples/squirrel/images/head_idle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quark-dev-team/quarkjs/HEAD/examples/squirrel/images/head_idle.png -------------------------------------------------------------------------------- /docs/api_template/allclasses.tmpl: -------------------------------------------------------------------------------- 1 |
-------------------------------------------------------------------------------- /docs/api_template/static/index.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 |canvas - 渲染上下文所对应的画布。
10 | */ 11 | var Context = Quark.Context = function(props) 12 | { 13 | if(props.canvas == null) throw "Quark.Context Error: canvas is required."; 14 | 15 | this.canvas = null; 16 | Quark.merge(this, props); 17 | }; 18 | 19 | /** 20 | * 为开始绘制显示对象做准备,需要子类来实现。 21 | */ 22 | Context.prototype.startDraw = function(){ }; 23 | 24 | /** 25 | * 绘制显示对象,需要子类来实现。 26 | */ 27 | Context.prototype.draw = function(){ }; 28 | 29 | /** 30 | * 完成绘制显示对象后的处理方法,需要子类来实现。 31 | */ 32 | Context.prototype.endDraw = function(){ }; 33 | 34 | /** 35 | * 对显示对象进行变换,需要子类来实现。 36 | */ 37 | Context.prototype.transform = function(){ }; 38 | 39 | /** 40 | * 从画布中删除显示对象,需要子类来实现。 41 | * @param {DisplayObject} target 要删除的显示对象。 42 | */ 43 | Context.prototype.remove = function(target){ }; 44 | 45 | })(); -------------------------------------------------------------------------------- /examples/imageloader.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |image - Image对象。
11 | *rect - Image对象的矩形区域。格式为:[0,0,100,100]
12 | */ 13 | var Bitmap = Quark.Bitmap = function(props) 14 | { 15 | this.image = null; 16 | this.rectX = 0; //ready-only 17 | this.rectY = 0; //ready-only 18 | this.rectWidth = 0; //ready-only 19 | this.rectHeight = 0; //ready-only 20 | 21 | props = props || {}; 22 | Bitmap.superClass.constructor.call(this, props); 23 | this.id = props.id || Quark.UIDUtil.createUID("Bitmap"); 24 | 25 | this.setRect(props.rect || [0, 0, this.image.width, this.image.height]); 26 | this.setDrawable(this.image); 27 | this._stateList.push("rectX", "rectY", "rectWidth", "rectHeight"); 28 | }; 29 | Quark.inherit(Bitmap, Quark.DisplayObject); 30 | 31 | /** 32 | * 设置Bitmap对象的image的显示区域。 33 | * @param {Array} rect 要设置的显示区域数组。格式为:[rectX, rectY, rectWidth, rectHeight]。 34 | */ 35 | Bitmap.prototype.setRect = function(rect) 36 | { 37 | this.rectX = rect[0]; 38 | this.rectY = rect[1]; 39 | this.rectWidth = this.width = rect[2]; 40 | this.rectHeight = this.height = rect[3]; 41 | }; 42 | 43 | /** 44 | * 覆盖父类的渲染方法。渲染image指定的显示区域。 45 | * @param {Context} context 渲染上下文。 46 | */ 47 | Bitmap.prototype.render = function(context) 48 | { 49 | context.draw(this, this.rectX, this.rectY, this.rectWidth, this.rectHeight, 0, 0, this.width, this.height); 50 | }; 51 | 52 | })(); -------------------------------------------------------------------------------- /src/base/display/Drawable.js: -------------------------------------------------------------------------------- 1 | 2 | (function(){ 3 | 4 | /** 5 | * 构造函数. 6 | * @name Drawable 7 | * @class Drawable是可绘制图像或DOM的包装。当封装的是HTMLImageElement、HTMLCanvasElement或HTMLVideoElement对象时,可同时支持canvas和dom两种渲染方式,而如果封装的是dom时,则不支持canvas方式。 8 | * @param drawable 一个可绘制对象。 9 | * @param {Boolean} isDOM 指定参数drawable是否为一个DOM对象。默认为false。 10 | */ 11 | var Drawable = Quark.Drawable = function(drawable, isDOM) 12 | { 13 | this.rawDrawable = null; 14 | this.domDrawable = null; 15 | this.set(drawable, isDOM); 16 | }; 17 | 18 | /** 19 | * 根据context上下文获取不同的Drawable包装的对象。 20 | * @param {DisplayObject} obj 指定的显示对象。 21 | * @param {Context} context 指定的渲染上下文。 22 | * @return 返回包装的可绘制对象。 23 | */ 24 | Drawable.prototype.get = function(obj, context) 25 | { 26 | if(context == null || context.canvas.getContext != null) 27 | { 28 | return this.rawDrawable; 29 | }else 30 | { 31 | if(this.domDrawable == null) 32 | { 33 | this.domDrawable = Quark.createDOMDrawable(obj, {image:this.rawDrawable}); 34 | } 35 | return this.domDrawable; 36 | } 37 | }; 38 | 39 | /** 40 | * 设置Drawable对象。 41 | * @param drawable 一个可绘制对象。 42 | * @param {Boolean} isDOM 指定参数drawable是否为一个DOM对象。默认为false。 43 | */ 44 | Drawable.prototype.set = function(drawable, isDOM) 45 | { 46 | if(isDrawable(drawable)) this.rawDrawable = drawable; 47 | if(isDOM === true) 48 | { 49 | this.domDrawable = drawable; 50 | }else if(this.domDrawable) 51 | { 52 | this.domDrawable.style.backgroundImage = "url(" + this.rawDrawable.src + ")"; 53 | } 54 | }; 55 | 56 | function isDrawable(elem) 57 | { 58 | if(elem == null) return false; 59 | return (elem instanceof HTMLImageElement) || 60 | (elem instanceof HTMLCanvasElement) || 61 | (elem instanceof HTMLVideoElement); 62 | }; 63 | 64 | })(); -------------------------------------------------------------------------------- /src/base/event/EventConst.js: -------------------------------------------------------------------------------- 1 | 2 | (function(){ 3 | 4 | /** 5 | * 按钮Key的code映射表。 6 | */ 7 | Quark.KEY = { 8 | 9 | MOUSE_LEFT : 1, 10 | MOUSE_MID : 2, 11 | MOUSE_RIGHT : 3, 12 | 13 | BACKSPACE : 8, 14 | TAB : 9, 15 | NUM_CENTER : 12, 16 | ENTER : 13, 17 | RETURN : 13, 18 | SHIFT : 16, 19 | CTRL : 17, 20 | ALT : 18, 21 | PAUSE : 19, 22 | CAPS_LOCK : 20, 23 | ESC : 27, 24 | ESCAPE : 27, 25 | SPACE : 32, 26 | PAGE_UP : 33, 27 | PAGE_DOWN : 34, 28 | END : 35, 29 | HOME : 36, 30 | LEFT : 37, 31 | UP : 38, 32 | RIGHT : 39, 33 | DOWN : 40, 34 | PRINT_SCREEN : 44, 35 | INSERT : 45, 36 | DELETE : 46, 37 | 38 | ZERO : 48, 39 | ONE : 49, 40 | TWO : 50, 41 | THREE : 51, 42 | FOUR : 52, 43 | FIVE : 53, 44 | SIX : 54, 45 | SEVEN : 55, 46 | EIGHT : 56, 47 | NINE : 57, 48 | 49 | A : 65, 50 | B : 66, 51 | C : 67, 52 | D : 68, 53 | E : 69, 54 | F : 70, 55 | G : 71, 56 | H : 72, 57 | I : 73, 58 | J : 74, 59 | K : 75, 60 | L : 76, 61 | M : 77, 62 | N : 78, 63 | O : 79, 64 | P : 80, 65 | Q : 81, 66 | R : 82, 67 | S : 83, 68 | T : 84, 69 | U : 85, 70 | V : 86, 71 | W : 87, 72 | X : 88, 73 | Y : 89, 74 | Z : 90, 75 | 76 | CONTEXT_MENU : 93, 77 | NUM_ZERO : 96, 78 | NUM_ONE : 97, 79 | NUM_TWO : 98, 80 | NUM_THREE : 99, 81 | NUM_FOUR : 100, 82 | NUM_FIVE : 101, 83 | NUM_SIX : 102, 84 | NUM_SEVEN : 103, 85 | NUM_EIGHT : 104, 86 | NUM_NINE : 105, 87 | NUM_MULTIPLY : 106, 88 | NUM_PLUS : 107, 89 | NUM_MINUS : 109, 90 | NUM_PERIOD : 110, 91 | NUM_DIVISION : 111, 92 | F1 : 112, 93 | F2 : 113, 94 | F3 : 114, 95 | F4 : 115, 96 | F5 : 116, 97 | F6 : 117, 98 | F7 : 118, 99 | F8 : 119, 100 | F9 : 120, 101 | F10 : 121, 102 | F11 : 122, 103 | F12 : 123 104 | }; 105 | 106 | })(); -------------------------------------------------------------------------------- /examples/squirrel/Squirrel.js: -------------------------------------------------------------------------------- 1 | 2 | var Squirrel = function(props) 3 | { 4 | Squirrel.superClass.constructor.call(this, props); 5 | this.init(); 6 | }; 7 | Q.inherit(Squirrel, Q.DisplayObjectContainer); 8 | 9 | Squirrel.prototype.init = function() 10 | { 11 | //松鼠的头部,是一个MovieClip类型。 12 | this.head = new Q.MovieClip({id:"head", image:Q.getDOM("headIdle"), useFrames:true, interval:2, x:5, y:0}); 13 | this.head.addFrame([ 14 | {rect:[0,0,66,56]}, 15 | {rect:[69,0,66,56]}, 16 | {rect:[138,0,66,56]}, 17 | {rect:[207,0,66,56]} 18 | ]); 19 | 20 | //松鼠的身体,也是一个MovieClip类型。 21 | this.body = new Q.MovieClip({id:"body", image:Q.getDOM('bodyWalk'), useFrames:true, interval:2, x:0, y:25}); 22 | this.body.addFrame([ 23 | {rect:[0,0,108,66]}, 24 | {rect:[109,0,108,66]}, 25 | {rect:[218,0,108,66]}, 26 | {rect:[327,0,108,66]}, 27 | {rect:[436,0,108,66]}, 28 | {rect:[545,0,108,66]}, 29 | {rect:[0,70,108,66]}, 30 | {rect:[109,70,108,66]}, 31 | {rect:[218,70,108,66]}, 32 | {rect:[327,70,108,66]}, 33 | {rect:[436,70,108,66]} 34 | ]); 35 | 36 | //由头部和身体组成了一只松鼠。 37 | this.addChild(this.body, this.head); 38 | 39 | //初始化数据。 40 | this.eventChildren = false; 41 | this.jumping = false; 42 | this.speedY = this.currentSpeedY = 8; 43 | this.originY = this.y; 44 | }; 45 | 46 | //控制松鼠的跳跃 47 | Squirrel.prototype.jump = function(e) 48 | { 49 | if(!this.jumping) 50 | { 51 | this.jumping = true; 52 | this.currentSpeedY = this.speedY; 53 | } 54 | }; 55 | 56 | //松鼠的更新函数,此方法会不断的被quark系统调用而产生跳跃动画。 57 | Squirrel.prototype.update = function() 58 | { 59 | if(this.jumping) 60 | { 61 | this.currentSpeedY -= 0.3; 62 | this.y -= this.currentSpeedY; 63 | if(this.originY <= this.y) 64 | { 65 | this.y = this.originY; 66 | this.jumping = false; 67 | } 68 | } 69 | }; -------------------------------------------------------------------------------- /src/base/geom/Rectangle.js: -------------------------------------------------------------------------------- 1 | 2 | (function(){ 3 | 4 | var Rectangle = Quark.Rectangle = function(x, y, width, height) 5 | { 6 | this.x = x; 7 | this.y = y; 8 | this.width = width; 9 | this.height = height; 10 | }; 11 | 12 | Rectangle.prototype.intersects = function(rect) 13 | { 14 | return (this.x <= rect.x + rect.width && rect.x <= this.x + this.width && 15 | this.y <= rect.y + rect.height && rect.y <= this.y + this.height); 16 | }; 17 | 18 | Rectangle.prototype.intersection = function(rect) 19 | { 20 | var x0 = Math.max(this.x, rect.x); 21 | var x1 = Math.min(this.x + this.width, rect.x + rect.width); 22 | 23 | if(x0 <= x1) 24 | { 25 | var y0 = Math.max(this.y, rect.y); 26 | var y1 = Math.min(this.y + this.height, rect.y + rect.height); 27 | 28 | if(y0 <= y1) 29 | { 30 | return new Rectangle(x0, y0, x1 - x0, y1 - y0); 31 | } 32 | } 33 | return null; 34 | }; 35 | 36 | Rectangle.prototype.union = function(rect, returnNew) 37 | { 38 | var right = Math.max(this.x + this.width, rect.x + rect.width); 39 | var bottom = Math.max(this.y + this.height, rect.y + rect.height); 40 | 41 | var x = Math.min(this.x, rect.x); 42 | var y = Math.min(this.y, rect.y); 43 | var width = right - x; 44 | var height = bottom - y; 45 | if(returnNew) 46 | { 47 | return new Rectangle(x, y, width, height); 48 | }else 49 | { 50 | this.x = x; 51 | this.y = y; 52 | this.width = width; 53 | this.height = height; 54 | } 55 | }; 56 | 57 | Rectangle.prototype.containsPoint = function(x, y) 58 | { 59 | return (this.x <= x && x <= this.x + this.width && this.y <= y && y <= this.y + this.height); 60 | }; 61 | 62 | Rectangle.prototype.clone = function() 63 | { 64 | return new Rectangle(this.x, this.y, this.width, this.height); 65 | }; 66 | 67 | Rectangle.prototype.toString = function() 68 | { 69 | return "(x=" + this.x + ", y=" + this.y + ", width=" + this.width + ", height=" + this.height + ")"; 70 | }; 71 | 72 | })(); -------------------------------------------------------------------------------- /docs/api_template/allfiles.tmpl: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | {! Link.base = ""; /* all generated links will be relative to this */ !} 7 |类 |
47 | 说明 |
48 |
|---|---|
"; 57 | output += new Link().toSymbol(thisClass.alias); 58 | output += " | "; 59 | output += resolveLinks(summarize(thisClass.classDesc)); 60 | output += " |
21 |
22 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/src/base/utils/ImageLoader.js:
--------------------------------------------------------------------------------
1 |
2 | (function(){
3 |
4 | /**
5 | * 构造函数.
6 | * @name ImageLoader
7 | * @augments EventDispatcher
8 | * @class ImageLoader类是一个图片加载器,用于动态加载图片资源。
9 | * @param source 要加载的图片资源,可以是一个单独资源或多个资源的数组。图片资源格式为:{src:$url, id:$id, size:$size}。
10 | */
11 | var ImageLoader = Quark.ImageLoader = function(source)
12 | {
13 | ImageLoader.superClass.constructor.call(this);
14 |
15 | this.loading = false; //ready-only
16 |
17 | this._index = -1;
18 | this._loaded = 0;
19 | this._images = {};
20 | this._totalSize = 0;
21 | this._loadHandler = Quark.delegate(this._loadHandler, this);
22 |
23 | this._addSource(source);
24 | };
25 | Quark.inherit(ImageLoader, Quark.EventDispatcher);
26 |
27 | /**
28 | * 开始顺序加载图片资源。
29 | * @param source 要加载的图片资源,可以是一个单独资源或多个资源的数组。
30 | */
31 | ImageLoader.prototype.load = function(source)
32 | {
33 | this._addSource(source);
34 | if(!this.loading) this._loadNext();
35 | };
36 |
37 | /**
38 | * 添加图片资源。
39 | * @private
40 | */
41 | ImageLoader.prototype._addSource = function(source)
42 | {
43 | if(!source) return;
44 | source = (source instanceof Array) ? source : [source];
45 | for(var i = 0; i < source.length; i++)
46 | {
47 | this._totalSize+= source[i].size || 0;
48 | }
49 | if(!this._source) this._source = source;
50 | else this._source = this._source.concat(source);
51 | };
52 |
53 | /**
54 | * 加载下一个图片资源。
55 | * @private
56 | */
57 | ImageLoader.prototype._loadNext = function()
58 | {
59 | this._index++;
60 | if(this._index >= this._source.length)
61 | {
62 | this.dispatchEvent({type:"complete", target:this, images:this._images});
63 | this._source = [];
64 | this.loading = false;
65 | this._index = -1;
66 | return;
67 | }
68 |
69 | var img = new Image();
70 | img.onload = this._loadHandler;
71 | img.src = this._source[this._index].src;
72 | this.loading = true;
73 | };
74 |
75 | /**
76 | * 图片加载处理器。
77 | * @private
78 | */
79 | ImageLoader.prototype._loadHandler = function(e)
80 | {
81 | this._loaded++;
82 | var image = this._source[this._index];
83 | image.image = e.target;
84 | var id = image.id || image.src;
85 | this._images[id] = image;
86 | this.dispatchEvent({type:"loaded", target:this, image:image});
87 | this._loadNext();
88 | };
89 |
90 | /**
91 | * 返回已加载图片资源的数目。
92 | */
93 | ImageLoader.prototype.getLoaded = function()
94 | {
95 | return this._loaded;
96 | };
97 |
98 | /**
99 | * 返回所有图片资源的总数。
100 | */
101 | ImageLoader.prototype.getTotal = function()
102 | {
103 | return this._source.length;
104 | };
105 |
106 | /**
107 | * 返回已加载的图片资源的大小之和(在图片资源的大小size已指定的情况下)。
108 | */
109 | ImageLoader.prototype.getLoadedSize = function()
110 | {
111 | var size = 0;
112 | for(var id in this._images)
113 | {
114 | var item = this._images[id];
115 | size += item.size || 0;
116 | }
117 | return size;
118 | };
119 |
120 | /**
121 | * 返回所有图片资源的大小之和(在图片资源的大小size已指定的情况下)。
122 | */
123 | ImageLoader.prototype.getTotalSize = function()
124 | {
125 | return this._totalSize;
126 | };
127 |
128 | })();
--------------------------------------------------------------------------------
/examples/squirrel/squirrel.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
22 |
23 |
24 |
118 |
119 |
120 |
--------------------------------------------------------------------------------
/examples/graphics.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | QuarkJS是一个HTML5游戏框架,它的目标是提供一套简单高效的方法创建HTML5游戏。
82 |它具有以下特性:
83 |91 | 查看项目(GitHub)
92 | 93 |
62 |
63 |
69 |
70 |
76 |
77 |
83 |
84 | 说明:带*的作品由QuarkJS的老版本CasualJS开发。
90 |canvas - 渲染上下文所对应的canvas,HTMLCanvasElement对象。
11 | */ 12 | var CanvasContext = Quark.CanvasContext = function(props) 13 | { 14 | CanvasContext.superClass.constructor.call(this, props); 15 | this.context = this.canvas.getContext("2d"); 16 | }; 17 | Quark.inherit(CanvasContext, Quark.Context); 18 | 19 | /** 20 | * 准备绘制,保存当前上下文。 21 | */ 22 | CanvasContext.prototype.startDraw = function() 23 | { 24 | this.context.save(); 25 | }; 26 | 27 | /** 28 | * 绘制指定的显示对象到Canvas上。 29 | * @param {DisplayObject} target 要绘制的显示对象。 30 | */ 31 | CanvasContext.prototype.draw = function(target) 32 | { 33 | //ignore children drawing if the parent has a mask. 34 | if(target.parent != null && target.parent.mask != null) return; 35 | 36 | if(target.mask != null) 37 | { 38 | //we implements the mask function by using 'source-in' composite operation. 39 | //so can't draw objects with masks into this canvas directly. 40 | var w = target.width, h = target.height; 41 | var context = Q._helpContext, canvas = context.canvas, ctx = context.context; 42 | canvas.width = 0; 43 | canvas.width = w; 44 | canvas.height = h; 45 | context.startDraw(); 46 | target.mask._render(context); 47 | ctx.globalCompositeOperation = 'source-in'; 48 | 49 | //this is a trick for ignoring mask drawing during object drawing. 50 | var mask = target.mask; 51 | target.mask = null; 52 | if(target instanceof Quark.DisplayObjectContainer) 53 | { 54 | //container's children should draw at once in 'source-in' mode. 55 | var cache = target._cache || Quark.cacheObject(target); 56 | ctx.drawImage(cache, 0, 0, w, h, 0, 0, w, h); 57 | }else 58 | { 59 | target.render(context); 60 | } 61 | context.endDraw(); 62 | target.mask = mask; 63 | 64 | arguments[0] = canvas; 65 | this.context.drawImage.apply(this.context, arguments); 66 | }else if(target._cache != null) 67 | { 68 | //draw cache if exist 69 | this.context.drawImage(target._cache, 0, 0); 70 | }else if(target instanceof Quark.Graphics || target instanceof Quark.Text) 71 | { 72 | //special drawing 73 | target._draw(this.context); 74 | }else 75 | { 76 | //normal draw 77 | var img = target.getDrawable(this); 78 | if(img != null) 79 | { 80 | arguments[0] = img; 81 | this.context.drawImage.apply(this.context, arguments); 82 | } 83 | } 84 | }; 85 | 86 | /** 87 | * 绘制完毕,恢复上下文。 88 | */ 89 | CanvasContext.prototype.endDraw = function() 90 | { 91 | this.context.restore(); 92 | }; 93 | 94 | /** 95 | * 对指定的显示对象进行context属性设置或变换。 96 | * @param {DisplayObject} target 要进行属性设置或变换的显示对象。 97 | */ 98 | CanvasContext.prototype.transform = function(target) 99 | { 100 | var ctx = this.context; 101 | 102 | if(target instanceof Q.Stage) 103 | { 104 | //Use style for stage scaling 105 | if(target._scaleX != target.scaleX) 106 | { 107 | target._scaleX = target.scaleX; 108 | this.canvas.style.width = target._scaleX * target.width + "px"; 109 | } 110 | if(target._scaleY != target.scaleY) 111 | { 112 | target._scaleY = target.scaleY; 113 | this.canvas.style.height = target._scaleY * target.height + "px"; 114 | } 115 | }else 116 | { 117 | if(target.x != 0 || target.y != 0) ctx.translate(target.x, target.y); 118 | if(target.rotation%360 != 0) ctx.rotate(target.rotation%360*Quark.DEG_TO_RAD); 119 | if(target.scaleX != 1 || target.scaleY != 1) ctx.scale(target.scaleX, target.scaleY); 120 | if(target.regX != 0 || target.regY != 0) ctx.translate(-target.regX, -target.regY); 121 | } 122 | 123 | if(target.alpha > 0) ctx.globalAlpha *= target.alpha; 124 | }; 125 | 126 | /** 127 | * 清除画布上的指定区域内容。 128 | * @param {Number} x 指定区域的x轴坐标。 129 | * @param {Number} y 指定区域的y轴坐标。 130 | * @param {Number} width 指定区域的宽度。 131 | * @param {Number} height 指定区域的高度。 132 | */ 133 | CanvasContext.prototype.clear = function(x, y, width, height) 134 | { 135 | this.context.clearRect(x, y, width, height); 136 | //this.canvas.width = this.canvas.width; 137 | }; 138 | 139 | })(); -------------------------------------------------------------------------------- /docs/tutorial_context.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |HTML5提供了一些图形渲染方法,比如Canvas、DIV+CSS3、VML、SVG等。一般的我们使用Canvas,但是在一些移动设备上(如iPhone),Canvas性能还不够好,我们在实际开发中发现DIV+CSS3在某些应用场景中性能更好。因此我们设计了上下文Context来实现不同的渲染方式,类似CanvasRenderingContext2D的设计。
81 |当前,我们有两种上下文:CanvasContext 和 DOMContext。
87 |CanvasContext示例:
88 |var canvas = document.getElementById("myCanvas"); //myCanvas是一个canvas元素
89 | var context = new Quark.CanvasContext({canvas:canvas});
90 | DOMContext示例:
91 |var container = document.getElementById("container"); //container是一个div元素
92 | var context = new Quark.DOMContext({canvas:container}); //把container作为canvas参数传给DOMContext
93 | 当上下文Context初始化并传给一个舞台stage后,你就可以几乎不用关心它的存在,而集中专注于游戏逻辑的开发。
94 |var em = new Q.EventManager(); 84 | var events = Q.supportTouch ? ["touchstart", "touchmove", "touchend"] : ["mousedown", "mousemove", "mouseup"]; 85 | em.registerStage(stage, events);86 |
obj.addEventListener("touchend", function(e)
92 | {
93 | //do something
94 | });
95 | 事件侦听函数会接收一个事件参数e,它包含e.eventX,e.eventY,e.eventTarget,e.lastEventTarget等属性。
96 |//删除指定事件类型的指定侦听函数
102 | obj.removeEventListener("touchend", touchendHandler);
103 |
104 | //删除指定事件类型的所有侦听函数
105 | obj.removeEventListener("touchend");
106 | em.unregisterStage(stage, events);112 |
obj.on = obj.addEventListener 118 | obj.un = obj.removeEventListener 119 | obj.fire = obj.dispatchEvent120 |
image - Image对象。
11 | *up - 按钮弹起状态下的显示帧数组对象。如:[0,0,50,50]。 12 | *
over - 按钮经过状态下的显示帧数组对象。如:[50,0,50,50]。 13 | *
down - 按钮按下状态下的显示帧数组对象。如:[100,0,50,50]。 14 | *
disabled - 按钮不可用状态下的显示帧数组对象。如:[150,0,50,50]。 15 | */ 16 | var Button = Quark.Button = function(props) 17 | { 18 | this.state = Button.UP; 19 | this.enabled = true; 20 | 21 | props = props || {}; 22 | Button.superClass.constructor.call(this, props); 23 | this.id = props.id || Quark.UIDUtil.createUID("Button"); 24 | 25 | this._skin = new Quark.MovieClip({id:"skin", image:props.image}); 26 | this.addChild(this._skin); 27 | this._skin.stop(); 28 | 29 | this.eventChildren = false; 30 | if(props.useHandCursor === undefined) this.useHandCursor = true; 31 | if(props.up) this.setUpState(props.up); 32 | if(props.over) this.setOverState(props.over); 33 | if(props.down) this.setDownState(props.down); 34 | if(props.disabled) this.setDisabledState(props.disabled); 35 | }; 36 | Quark.inherit(Button, Quark.DisplayObjectContainer); 37 | 38 | /** 39 | * 按钮的弹起状态。常量值。 40 | */ 41 | Button.UP = "up"; 42 | /** 43 | * 按钮的经过状态。常量值。 44 | */ 45 | Button.OVER = "over"; 46 | /** 47 | * 按钮的按下状态。常量值。 48 | */ 49 | Button.DOWN = "down"; 50 | /** 51 | * 按钮的不可用状态。常量值。 52 | */ 53 | Button.DISABLED = "disabled"; 54 | 55 | /** 56 | * 设置按钮弹起状态的显示帧。 57 | * @param {Array} upState 弹起状态的显示帧。 58 | * @return {Button} 返回按钮本身。 59 | */ 60 | Button.prototype.setUpState = function(upState) 61 | { 62 | upState.label = Button.UP; 63 | this._skin.setFrame(upState, 0); 64 | this.upState = upState; 65 | return this; 66 | }; 67 | 68 | /** 69 | * 设置按钮经过状态的显示帧。 70 | * @param {Array} overState 经过状态的显示帧。 71 | * @return {Button} 返回按钮本身。 72 | */ 73 | Button.prototype.setOverState = function(overState) 74 | { 75 | overState.label = Button.OVER; 76 | this._skin.setFrame(overState, 1); 77 | this.overState = overState; 78 | return this; 79 | }; 80 | 81 | /** 82 | * 设置按钮按下状态的显示帧。 83 | * @param {Array} downState 点击状态的显示帧。 84 | * @return {Button} 返回按钮本身。 85 | */ 86 | Button.prototype.setDownState = function(downState) 87 | { 88 | downState.label = Button.DOWN; 89 | this._skin.setFrame(downState, 2); 90 | this.downState = downState; 91 | return this; 92 | }; 93 | 94 | /** 95 | * 设置按钮不可用状态的显示帧。 96 | * @param {Array} disabledState 不可用状态的显示帧。 97 | * @return {Button} 返回按钮本身。 98 | */ 99 | Button.prototype.setDisabledState = function(disabledState) 100 | { 101 | disabledState.label = Button.DISABLED; 102 | this._skin.setFrame(disabledState, 3); 103 | this.disabledState = disabledState; 104 | return this; 105 | }; 106 | 107 | /** 108 | * 设置按钮是否启用。 109 | * @param {Boolean} enabled 指定按钮是否启用。默认为false。 110 | * @return {Button} 返回按钮本身。 111 | */ 112 | Button.prototype.setEnabled = function(enabled) 113 | { 114 | if(this.enabled == enabled) return this; 115 | this.eventEnabled = this.enabled = enabled; 116 | if(!enabled) 117 | { 118 | if(this.disabledState) this._skin.gotoAndStop(Button.DISABLED); 119 | else this._skin.gotoAndStop(Button.UP); 120 | }else 121 | { 122 | if(this._skin.currentFrame == 3) this._skin.gotoAndStop(Button.UP); 123 | } 124 | return this; 125 | }; 126 | 127 | /** 128 | * 改变按钮的显示状态。 129 | * @param {String} state 指定按钮的显示状态。 130 | * @return {Button} 返回按钮本身。 131 | */ 132 | Button.prototype.changeState = function(state) 133 | { 134 | if(this.state == state) return; 135 | this.state = state; 136 | 137 | switch(state) 138 | { 139 | case Button.OVER: 140 | case Button.DOWN: 141 | case Button.UP: 142 | if(!this.enabled) this.eventEnabled = this.enabled = true; 143 | this._skin.gotoAndStop(state); 144 | break; 145 | case Button.DISABLED: 146 | this.setEnabled(false); 147 | break; 148 | } 149 | return this; 150 | }; 151 | 152 | /** 153 | * 按钮的默认事件处理行为。 154 | * @private 155 | */ 156 | Button.prototype.dispatchEvent = function(e) 157 | { 158 | if(!this.enabled) return; 159 | 160 | switch(e.type) 161 | { 162 | case "mousemove": 163 | if(this.overState) this.changeState(Button.OVER); 164 | break; 165 | case "mousedown": 166 | case "touchstart": 167 | case "touchmove": 168 | if(this.downState) this.changeState(Button.DOWN); 169 | break; 170 | case "mouseup": 171 | if(this.overState) this.changeState(Button.OVER); 172 | else this.changeState(Button.UP); 173 | break; 174 | case "mouseout": 175 | case "touchout": 176 | case "touchend": 177 | if(this.upState) this.changeState(Button.UP); 178 | break; 179 | } 180 | Button.superClass.dispatchEvent.call(this, e); 181 | }; 182 | 183 | /** 184 | * 把Button的drawable置空,否则传入image参数时会绘制成Button的背景。 185 | * @private 186 | */ 187 | Button.prototype.setDrawable = function(drawable) 188 | { 189 | Button.superClass.setDrawable.call(this, null); 190 | }; 191 | 192 | })(); -------------------------------------------------------------------------------- /docs/tutorial_infrastructure.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 |
显示对象列表、上下文、计时器三者分工合作,共同组成了Quark Base的架构。
115 |canvas - 渲染上下文所对应的画布,HTMLDivElement对象。
39 | */ 40 | var DOMContext = Quark.DOMContext = function(props) 41 | { 42 | DOMContext.superClass.constructor.call(this, props); 43 | }; 44 | Quark.inherit(DOMContext, Quark.Context); 45 | 46 | /** 47 | * 绘制指定对象的DOM到舞台上。 48 | * @param {DisplayObject} target 要绘制的显示对象。 49 | */ 50 | DOMContext.prototype.draw = function(target) 51 | { 52 | if(!target._addedToDOM) 53 | { 54 | var parent = target.parent; 55 | var targetDOM = target.getDrawable(this); 56 | if(parent != null) 57 | { 58 | var parentDOM = parent.getDrawable(this); 59 | if(targetDOM.parentNode != parentDOM) parentDOM.appendChild(targetDOM); 60 | if(parentDOM.parentNode == null && parent instanceof Quark.Stage) 61 | { 62 | this.canvas.appendChild(parentDOM); 63 | parent._addedToDOM = true; 64 | } 65 | target._addedToDOM = true; 66 | } 67 | } 68 | }; 69 | 70 | /** 71 | * 对指定的显示对象的DOM进行css属性设置或变换。 72 | * @param {DisplayObject} target 要进行属性设置或变换的显示对象。 73 | */ 74 | DOMContext.prototype.transform = function(target) 75 | { 76 | var image = target.getDrawable(this); 77 | //优化:可以对那些添加到DOM后就不再需要变换的显示对象设置transformEnabled=false。 78 | if(!target.transformEnabled && target._addedToDOM) return; 79 | 80 | var prefix = Quark.cssPrefix, 81 | origin = prefix + "TransformOrigin", 82 | transform = prefix + "Transform", 83 | style = image.style; 84 | 85 | if(!style.display || target.propChanged("visible", "alpha")) 86 | { 87 | style.display = (!target.visible || target.alpha <= 0) ? "none" : ""; 88 | } 89 | if(!style.opacity || target.propChanged("alpha")) 90 | { 91 | style.opacity = target.alpha; 92 | } 93 | if(!style.backgroundPosition || target.propChanged("rectX", "rectY")) 94 | { 95 | style.backgroundPosition = (-target.rectX) + "px " + (-target.rectY) + "px"; 96 | } 97 | if(!style.width || target.propChanged("width", "height")) 98 | { 99 | style.width = target.width + "px"; 100 | style.height = target.height + "px"; 101 | } 102 | if(!style[origin] || target.propChanged("regX", "regY")) 103 | { 104 | style[origin] = target.regX + "px " + target.regY + "px"; 105 | } 106 | if(!style[transform] || target.propChanged("x", "y", "regX", "regY", "scaleX", "scaleY", "rotation")) 107 | { 108 | var css = Quark.supportTransform3D ? getTransformCSS(target, true) : getTransformCSS(target, false); 109 | style[transform] = css; 110 | } 111 | if(!style.zIndex || target.propChanged("_depth")) 112 | { 113 | style.zIndex = target._depth; 114 | } 115 | if(target.mask != null) 116 | { 117 | style[Q.cssPrefix + "MaskImage"] = target.mask.getDrawable(this).style.backgroundImage; 118 | style[Q.cssPrefix + "MaskRepeat"] = "no-repeat"; 119 | style[Q.cssPrefix + "MaskPosition"] = target.mask.x + "px " + target.mask.y + "px"; 120 | } 121 | style.pointerEvents = target.eventEnabled ? "auto" : "none"; 122 | }; 123 | 124 | /** 125 | * 根据指定对象生成css变换的样式。 126 | * @param {DisplayObject} target 显示对象。 127 | * @param {Boolean} useTransform3D 是否采用transform—3d变换。在支持transform—3d的浏览器中推荐使用。默认为false。 128 | * @return {String} 生成的css样式。 129 | */ 130 | function getTransformCSS(target, useTransform3D) 131 | { 132 | var css = ""; 133 | 134 | if(useTransform3D) 135 | { 136 | css += "translate3d(" + (target.x-target.regX) + "px, " + (target.y-target.regY) + "px, 0px)" 137 | + "rotate3d(0, 0, 1, " + target.rotation + "deg)" 138 | + "scale3d(" + target.scaleX + ", " + target.scaleY + ", 1)"; 139 | }else 140 | { 141 | css += "translate(" + (target.x-target.regX) + "px, " + (target.y-target.regY) + "px)" 142 | + "rotate(" + target.rotation + "deg)" 143 | + "scale(" + target.scaleX + ", " + target.scaleY + ")"; 144 | } 145 | return css; 146 | }; 147 | 148 | /** 149 | * 隐藏指定对象渲染的dom节点,用于当显示对象visible=0或alpha=0等情况,由显示对象内部方法调用。 150 | * @param {DisplayObject} target 要隐藏的显示对象。 151 | */ 152 | DOMContext.prototype.hide = function(target) 153 | { 154 | target.getDrawable(this).style.display = "none"; 155 | }; 156 | 157 | /** 158 | * 删除指定显示对象渲染的dom节点,由显示对象内部方法调用。 159 | * @param {DisplayObject} target 要删除的显示对象。 160 | */ 161 | DOMContext.prototype.remove = function(target) 162 | { 163 | var targetDOM = target.getDrawable(this); 164 | var parentNode = targetDOM.parentNode; 165 | if(parentNode != null) parentNode.removeChild(targetDOM); 166 | target._addedToDOM = false; 167 | }; 168 | 169 | })(); -------------------------------------------------------------------------------- /src/base/display/Text.js: -------------------------------------------------------------------------------- 1 | 2 | (function(){ 3 | 4 | /** 5 | * 构造函数。 6 | * @name Text 7 | * @augments DisplayObject 8 | * @class Text类提供简单的文字显示功能。 9 | * @property text 指定要显示的文本内容。 10 | * @property font 指定使用的字体样式。 11 | * @property color 指定使用的字体颜色。 12 | * @property textAlign 指定文本的对齐方式。可以是以下任意一个值:"start", "end", "left", "right", and "center"。 13 | * @property outline 指定文本是绘制边框还是填充。 14 | * @property maxWidth 指定文本绘制的最大宽度。仅在canvas中使用。 15 | * @property lineWidth 指定文本行的最大宽度。 16 | * @property lineSpacing 指定文本的行距。单位为像素。 17 | * @property fontMetrics 指定字体的度量对象。一般可忽略此属性,可用于提高性能。 18 | */ 19 | var Text = Quark.Text = function(props) 20 | { 21 | this.text = ""; 22 | this.font = "12px arial"; 23 | this.color = "#000"; 24 | this.textAlign = "start"; 25 | this.outline = false; 26 | this.maxWidth = 10000; 27 | this.lineWidth = null; 28 | this.lineSpacing = 0; 29 | this.fontMetrics = null; 30 | 31 | props = props || {}; 32 | Text.superClass.constructor.call(this, props); 33 | this.id = Quark.UIDUtil.createUID("Text"); 34 | 35 | if(this.fontMetrics == null) this.fontMetrics = Text.getFontMetrics(this.font); 36 | } 37 | Quark.inherit(Text, Quark.DisplayObject); 38 | 39 | 40 | /** 41 | * 在指定的渲染上下文上绘制文本。 42 | * @private 43 | */ 44 | Text.prototype._draw = function(context) 45 | { 46 | if(!this.text || this.text.length == 0) return; 47 | 48 | //set drawing style 49 | context.font = this.font; 50 | context.textAlign = this.textAlign; 51 | context.textBaseline = "top"; 52 | if(this.outline) context.strokeStyle = this.color; 53 | else context.fillStyle = this.color; 54 | 55 | //find and draw all explicit lines 56 | var lines = this.text.split(/\r\n|\r|\n|

到GitHub上下载quarkjs的最新版本:http://github.com/quark-dev-team/quarkjs 82 | 直接下载 »
83 |然后把quarkjs类库引入到html页面:
84 |<script src="js/quark.base-1.0.0.js"></script>85 |
上下文Context在quark中负责渲染,目前有DOMContext和CanvasContext两种。
90 |//create a DOMContext
91 | var container = Quark.getDOM("container");
92 | var domContext = new Quark.DOMContext({canvas:container});
93 |
94 | //or create a CanvasContext
95 | var container = Quark.getDOM("container");
96 | var canvas = Quark.createDOM("canvas", {width:480, height:320, style:
97 | {
98 | position:"absolute",
99 | backgroundColor:"#fff"
100 | }});
101 | container.appendChild(canvas);
102 | var canvasContext = new Quark.CanvasContext({canvas:canvas});
103 | 显示对象通过Context在舞台Stage上被渲染出来。
108 |var stage = new Quark.Stage({width:480, height:320, context:canvasContext, update:function()
109 | {
110 | //write your own update code here
111 | }});
112 | 舞台Stage上的物体的运动等变化,都是通过一个计时器Timer不断地调用Stage.step()方法来实现刷新的。
117 |var fps = 60; 118 | var timer = new Q.Timer(1000/fps); 119 | timer.addListener(stage); 120 | timer.start();121 |
要想舞台上的显示对象能响应用户的点击、触碰等交互事件,就必需为舞台注册相应的事件。
126 |var em = new Quark.EventManager(); 127 | var events = Quark.supportTouch ? ["touchstart", "touchmove", "touchend"] : ["mousedown", "mousemove", "mouseup"]; 128 | em.registerStage(stage, events);129 |
至此,初始化工作基本完成。你可以开始利用quark提供的各种类和方法来创建各种显示对象。开始创建你的第一个HTML5游戏吧!
134 |var bmp = new Quark.Bitmap({image:imgElem, rect:[0,0,100,100], update:function()
135 | {
136 | //update code here
137 | }});
138 | stage.addChild(bmp);
139 | 类 |
112 | 说明 |
113 |
|---|---|
Audio | Audio类是原生Audio的封装。 |
Bitmap | Bitmap位图类,表示位图图像的显示对象,简单说它就是Image对象的某个区域的抽象表示。 |
Button | Button类继承自DisplayObjectContainer,是Quark中的简单按钮实现。 |
CanvasContext | CanvasContext是Canvas渲染上下文,将显示对象渲染到指定的Canvas上。 |
Context | Context是Quark框架中显示对象结构的上下文,实现显示对象结构的渲染。此类为抽象类。 |
DisplayObject | DisplayObject类是可放在舞台上的所有显示对象的基类。DisplayObject类定义了若干显示对象的基本属性。渲染一个DisplayObject其实是进行若干变换后再渲染其drawable对象。 |
DisplayObjectContainer | DisplayObjectContainer类继承自DisplayObject,是显示列表中显示对象容器的基类。每个DisplayObjectContainer对象都有自己的子级列表children,用于组织对象的Z轴顺序。注意:DisplayObjectContainer对象的宽高默认为0,在autoSize=false的情况下,需要手动设置宽高。 |
DOMContext | DOMContext是DOM渲染上下文,将显示对象以dom方式渲染到舞台上。 |
Drawable | Drawable是可绘制图像或DOM的包装。当封装的是HTMLImageElement、HTMLCanvasElement或HTMLVideoElement对象时,可同时支持canvas和dom两种渲染方式,而如果封装的是dom时,则不支持canvas方式。 |
EventDispatcher | EventDispatcher类是可调度事件的类的基类,它允许显示列表上的任何对象都是一个事件目标。 |
EventManager | EventManager是一个简单的系统事件管理器。 |
Graphics | Graphics类包含一组创建矢量图形的方法。 |
ImageLoader | ImageLoader类是一个图片加载器,用于动态加载图片资源。 |
MovieClip | MovieClip影片剪辑类,表示一组动画片段。MovieClip是由Image对象的若干矩形区域组成的集合序列,并按照一定规则顺序播放。帧frame的定义格式为:{rect:*required*, label:"", interval:0, stop:0, jump:-1}。 |
Quark | Quark是QuarkJS框架的全局对象,也是框架内部所有类的全局命名空间。在全局Q未被占用的情况下,也可以使用其缩写Q。 |
Stage | 舞台是显示对象的根,所有显示对象都会被添加到舞台上,必须传入一个context使得舞台能被渲染。舞台是一种特殊显示对象容器,可以容纳子显示对象。 |
Text | Text类提供简单的文字显示功能。 |
Timer | Timer是一个计时器。它能按指定的时间序列运行代码。 |
Tween | Tween类是一个缓动动画类。使用它能实现移动、改变大小、淡入淡出等效果。 |
地址:http://quark-dev-team.github.com/quarkjs/examples/squirrel/squirrel.html
81 |此demo演示了如何使用quark创建一个基本的交互动画。下面将一步一步介绍是如何实现的。
82 | 83 | 84 |<div id="container" style="position:absolute;left:0;top:0;width:480px;height:320px;background:#eee;"></div> 89 | <img id="bodyWalk" src="images/body_walk.png" style="display:none;" /> 90 | <img id="headIdle" src="images/head_idle.png" style="display:none;" />91 |
这里的容器就是一个普通的div,并设定好其宽高。另外为了演示方便,我们把项目所需的2个图片素材使用img标签做了预加载。
92 |container = Q.getDOM("container");
97 | container.style.background = "-ms-linear-gradient(top, #00889d, #94d7e1, #58B000)";
98 | container.style.background = "-moz-linear-gradient(top, #00889d, #94d7e1, #58B000)";
99 | container.style.background = "-webkit-gradient(linear, 0 0, 0 bottom, from(#00889d), to(#58B000), color-stop(0.5,#94d7e1))";
100 | container.style.background = "-o-linear-gradient(top, #00889d, #94d7e1, #58B000)";
101 | container.style.filter = "progid:DXImageTransform.Microsoft.gradient(startColorstr=#00889d, endColorstr=#94d7e1)";
102 | 这里使用了css的线性渐变背景。
103 |params = Q.getUrlParams();
108 | if(params.canvas)
109 | {
110 | var canvas = Quark.createDOM("canvas", {width:480, height:320, style:{position:"absolute",backgroundColor:"#eee"}});
111 | container.appendChild(canvas);
112 | context = new Quark.CanvasContext({canvas:canvas});
113 | }else{
114 | context = new Quark.DOMContext({canvas:container});
115 | }
116 | 上下文在quark中负责渲染工作。这里可以根据URL参数canvas来选择使用CanvasContext还是DOMContext。
117 |stage = new Q.Stage({context:context, width:480, height:320,
122 | update:function()
123 | {
124 | frames++;
125 | }});
126 |
127 | timer = new Q.Timer(1000/30);
128 | timer.addListener(stage);
129 | timer.start();
130 |
131 | em = new Q.EventManager();
132 | var events = Q.supportTouch ? ["touchend"] : ["mouseup"];
133 | em.registerStage(stage, events, true, true);
134 | 在这一步,我们初始化了一个舞台,并把刚才创建的上下文context传给舞台。这样quark就知道如何把舞台上面的元素渲染出来了。但是舞台默认是静止的,不会主动刷新,因此我们需要一个计时器timer来定时更新舞台,从而驱动整个游戏运行。然后注册舞台事件,使舞台上的元素能接收交互事件,这里只接收touchend和mouseup事件。
135 |squirrel = new Squirrel({id:"squirrel", x:200, y:160, autoSize:true});
140 | stage.addChild(squirrel);
141 |
142 | squirrel.addEventListener(events[0], squirrel.jump);
143 | 创建一只小松鼠,并使用stage.addChild()方法添加到舞台。这里的松鼠类Squirrel是我们预先创建好的,待会再讲解如何创建这个类。通过addEventListener()方法为松鼠添加touchend或mouseup事件侦听,这样玩家就可以控制其跳跃。
144 |var Squirrel = function(props)
149 | {
150 | Squirrel.superClass.constructor.call(this, props);
151 | this.init();
152 | };
153 | Q.inherit(Squirrel, Q.DisplayObjectContainer);
154 | Squirrel类是在Squirrel.js文件中实现的。在这里松鼠是由头部和身体两部分组成,因此Squirrel类继承自DisplayObjectContainer容器类。
155 |this.head = new Q.MovieClip({id:"head", image:Q.getDOM("headIdle"), useFrames:true, interval:2, x:5, y:0});
160 | this.head.addFrame([
161 | {rect:[0,0,66,56]},
162 | {rect:[69,0,66,56]},
163 | {rect:[138,0,66,56]},
164 | {rect:[207,0,66,56]}]);
165 |
166 | this.body = new Q.MovieClip({id:"body", image:Q.getDOM('bodyWalk'), useFrames:true, interval:2, x:0, y:25});
167 | this.body.addFrame([
168 | {rect:[0,0,108,66]},
169 | {rect:[109,0,108,66]},
170 | {rect:[218,0,108,66]},
171 | {rect:[327,0,108,66]},
172 | {rect:[436,0,108,66]},
173 | {rect:[545,0,108,66]},
174 | {rect:[0,70,108,66]},
175 | {rect:[109,70,108,66]},
176 | {rect:[218,70,108,66]},
177 | {rect:[327,70,108,66]},
178 | {rect:[436,70,108,66]}]);
179 |
180 | this.addChild(this.body, this.head);
181 | 松鼠的头部和身体都有各自的动作,因此head和body都采用MovieClip类来实现。再用addChild()方法添加到Squirrel容器类里,这样一只松鼠的形象就组成了。
182 |Squirrel.prototype.jump = function(e)
187 | {
188 | if(!this.jumping)
189 | {
190 | this.jumping = true;
191 | this.currentSpeedY = this.speedY;
192 | }
193 | };
194 |
195 | Squirrel.prototype.update = function()
196 | {
197 | if(this.jumping)
198 | {
199 | this.currentSpeedY -= 0.3;
200 | this.y -= this.currentSpeedY;
201 | if(this.originY <= this.y)
202 | {
203 | this.y = this.originY;
204 | this.jumping = false;
205 | }
206 | }
207 | };
208 | 为了实现松鼠的跳跃,我们首先创建jump方法,在第5步中可以看到我们把touchend或mouseup事件绑定到了jump方法。然后我们在Squirrel的update方法里实现具体的跳跃逻辑。
209 |var path = "M250 150 L150 350 L350 350 Z";
189 | *var shape = new Quark.Graphics({width:500, height:500});
190 | *shape.drawSVGPath(path).beginFill("#0ff").endFill();
191 | */ 192 | Graphics.prototype.drawSVGPath = function(pathData) 193 | { 194 | var path = pathData.split(/,| (?=[a-zA-Z])/); 195 | 196 | this._addAction(["beginPath"]); 197 | for(var i = 0, len = path.length; i < len; i++) 198 | { 199 | var str = path[i], cmd = str[0].toUpperCase(), p = str.substring(1).split(/,| /); 200 | if(p[0].length == 0) p.shift(); 201 | 202 | switch(cmd) 203 | { 204 | case "M": 205 | this._addAction(["moveTo", p[0], p[1]]); 206 | break; 207 | case "L": 208 | this._addAction(["lineTo", p[0], p[1]]); 209 | break; 210 | case "C": 211 | this._addAction(["bezierCurveTo", p[0], p[1], p[2], p[3], p[4], p[5]]); 212 | break; 213 | case "Z": 214 | this._addAction(["closePath"]); 215 | break; 216 | default: 217 | break; 218 | } 219 | } 220 | return this; 221 | }; 222 | 223 | /** 224 | * 执行全部绘制动作。内部私有方法。 225 | * @private 226 | */ 227 | Graphics.prototype._draw = function(context) 228 | { 229 | context.beginPath(); 230 | for(var i = 0, len = this._actions.length; i < len; i++) 231 | { 232 | var action = this._actions[i], 233 | f = action[0], 234 | args = action.length > 1 ? action.slice(1) : null; 235 | 236 | if(typeof(context[f]) == "function") context[f].apply(context, args); 237 | else context[f] = action[1]; 238 | } 239 | }; 240 | 241 | /** 242 | * Override method. 243 | * @private 244 | */ 245 | Graphics.prototype.getDrawable = function(context) 246 | { 247 | //for DOMContext drawing only 248 | if(this.drawable == null) this.setDrawable(this.toImage()); 249 | return this.drawable.get(this, context); 250 | }; 251 | 252 | /** 253 | * 缓存graphics到一个canvas或image。可用来提高渲染效率。 254 | */ 255 | Graphics.prototype.cache = function(toImage) 256 | { 257 | var canvas = Quark.createDOM("canvas", {width:this.width, height:this.height}); 258 | this._draw(canvas.getContext("2d")); 259 | 260 | this._cache = canvas; 261 | if(toImage) this._cache = this.toImage(); 262 | return this._cache; 263 | }; 264 | 265 | /** 266 | * 清除缓存。 267 | */ 268 | Graphics.prototype.uncache = function() 269 | { 270 | this._cache = null; 271 | }; 272 | 273 | /** 274 | * 把Graphics对象转换成dataURL格式的位图。 275 | * @param {String} type 指定转换为DataURL格式的图片mime类型。默认为"image/png"。 276 | */ 277 | Graphics.prototype.toImage = function(type) 278 | { 279 | var cache = this._cache || this.cache(true); 280 | if(cache instanceof HTMLImageElement) return cache; 281 | 282 | var img = new Image(); 283 | img.src = cache.toDataURL(type || "image/png"); 284 | img.width = this.width; 285 | img.height = this.height; 286 | return img; 287 | }; 288 | 289 | /** 290 | * 清除所有绘制动作并复原所有初始状态。 291 | */ 292 | Graphics.prototype.clear = function() 293 | { 294 | this._actions.length = 0; 295 | this._cache = null; 296 | 297 | this.lineWidth = 1; 298 | this.strokeStyle = "0"; 299 | this.lineAlpha = 1; 300 | this.lineCap = null; 301 | this.lineJoin = null; 302 | this.miterLimit = 10; 303 | this.hasStroke = false; 304 | 305 | this.fillStyle = "0"; 306 | this.fillAlpha = 1; 307 | }; 308 | 309 | /** 310 | * 添加一个绘制动作。内部私有方法。 311 | * @private 312 | */ 313 | Graphics.prototype._addAction = function(action) 314 | { 315 | this._actions.push(action); 316 | return this; 317 | }; 318 | 319 | /** 320 | * @private 321 | */ 322 | Graphics._getContext = function() 323 | { 324 | var ctx = Quark.createDOM("canvas").getContext("2d"); 325 | this._getContext = function() 326 | { 327 | return ctx; 328 | }; 329 | return ctx; 330 | }; 331 | 332 | })(); 333 | -------------------------------------------------------------------------------- /src/base/display/DisplayObjectContainer.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | 3 | /** 4 | * 构造函数. 5 | * @name DisplayObjectContainer 6 | * @augments DisplayObject 7 | * @class DisplayObjectContainer类继承自DisplayObject,是显示列表中显示对象容器的基类。每个DisplayObjectContainer对象都有自己的子级列表children,用于组织对象的Z轴顺序。注意:DisplayObjectContainer对象的宽高默认为0,在autoSize=false的情况下,需要手动设置宽高。 8 | * @property eventChildren 指示DisplayObjectContainer的子元素是否接受交互事件,如mousedown,touchstart等。默认为true。 9 | * @property autoSize 指示DisplayObjectContainer是否随子元素自动设置大小。默认为false。 10 | */ 11 | var DisplayObjectContainer = Quark.DisplayObjectContainer = function(props) 12 | { 13 | this.eventChildren = true; 14 | this.autoSize = false; 15 | 16 | props = props || {}; 17 | DisplayObjectContainer.superClass.constructor.call(this, props); 18 | this.id = props.id || Quark.UIDUtil.createUID("DisplayObjectContainer"); 19 | this.setDrawable(props.drawable || props.image || null); 20 | 21 | this.children = []; 22 | if(props.children) 23 | { 24 | for(var i = 0; i < props.children.length; i++) 25 | { 26 | this.addChild(props.children[i]); 27 | } 28 | } 29 | }; 30 | Quark.inherit(DisplayObjectContainer, Quark.DisplayObject); 31 | 32 | /** 33 | * 将一个DisplayObject子实例添加到该DisplayObjectContainer实例的子级列表中的指定位置。 34 | * @param {DisplayObject} child 要添加的显示对象。 35 | * @param {Integer} index 指定显示对象要被添加到的索引位置。 36 | * @return {DisplayObjectContainer} 返回显示容器本身。 37 | */ 38 | DisplayObjectContainer.prototype.addChildAt = function(child, index) 39 | { 40 | if(index < 0) index = 0; 41 | else if(index > this.children.length) index = this.children.length; 42 | 43 | var childIndex = this.getChildIndex(child); 44 | if(childIndex != -1) 45 | { 46 | if(childIndex == index) return this; 47 | this.children.splice(childIndex, 1); 48 | }else if(child.parent) 49 | { 50 | child.parent.removeChild(child); 51 | } 52 | 53 | this.children.splice(index, 0, child); 54 | child.parent = this; 55 | 56 | if(this.autoSize) 57 | { 58 | var rect = new Quark.Rectangle(0, 0, this.rectWidth || this.width, this.rectHeight || this.height); 59 | var childRect = new Quark.Rectangle(child.x, child.y, child.rectWidth || child.width, child.rectHeight || child.height); 60 | rect.union(childRect); 61 | this.width = rect.width; 62 | this.height = rect.height; 63 | } 64 | 65 | return this; 66 | }; 67 | 68 | /** 69 | * 将一个DisplayObject子实例添加到该DisplayObjectContainer实例的子级列表中。 70 | * @param {DisplayObject} child 要添加的显示对象。 71 | * @return {DisplayObjectContainer} 返回显示容器本身。 72 | */ 73 | DisplayObjectContainer.prototype.addChild = function(child) 74 | { 75 | var start = this.children.length; 76 | for(var i = 0; i < arguments.length; i++) 77 | { 78 | var child = arguments[i]; 79 | this.addChildAt(child, start + i); 80 | } 81 | return this; 82 | }; 83 | 84 | /** 85 | * 从DisplayObjectContainer的子级列表中指定索引处删除子对象。 86 | * @param {Integer} index 指定要删除的显示对象的索引位置。 87 | * @return {Boolean} 删除成功返回true,否则返回false。 88 | */ 89 | DisplayObjectContainer.prototype.removeChildAt = function(index) 90 | { 91 | if (index < 0 || index >= this.children.length) return false; 92 | var child = this.children[index]; 93 | if (child != null) 94 | { 95 | var stage = this.getStage(); 96 | if(stage != null) stage.context.remove(child); 97 | child.parent = null; 98 | } 99 | this.children.splice(index, 1); 100 | return true; 101 | }; 102 | 103 | /** 104 | * 从DisplayObjectContainer的子级列表中删除指定子对象。 105 | * @param {DisplayObject} child 指定要删除的显示对象。 106 | * @return {Boolean} 删除成功返回true,否则返回false。 107 | */ 108 | DisplayObjectContainer.prototype.removeChild = function(child) 109 | { 110 | return this.removeChildAt(this.children.indexOf(child)); 111 | }; 112 | 113 | /** 114 | * 删除DisplayObjectContainer的所有子对象。 115 | */ 116 | DisplayObjectContainer.prototype.removeAllChildren = function() 117 | { 118 | while(this.children.length > 0) this.removeChildAt(0); 119 | }; 120 | 121 | /** 122 | * 返回DisplayObjectContainer的位于指定索引处的子显示对象。 123 | * @param {Integer} index 指定子显示对象的索引位置。 124 | * @return {DisplayObject} 返回指定的子显示对象。 125 | */ 126 | DisplayObjectContainer.prototype.getChildAt = function(index) 127 | { 128 | if (index < 0 || index >= this.children.length) return null; 129 | return this.children[index]; 130 | }; 131 | 132 | /** 133 | * 返回指定对象在DisplayObjectContainer的子级列表中的索引位置。 134 | * @param {Integer} child 指定子显示对象。 135 | * @return {Integer} 返回指定子显示对象的索引位置。 136 | */ 137 | DisplayObjectContainer.prototype.getChildIndex = function(child) 138 | { 139 | return this.children.indexOf(child); 140 | }; 141 | 142 | /** 143 | * 设置指定对象在DisplayObjectContainer的子级列表中的索引位置。 144 | * @param {DisplayObject} child 指定子显示对象。 145 | * @param {Integer} index 指定子显示对象新的索引位置。 146 | */ 147 | DisplayObjectContainer.prototype.setChildIndex = function(child, index) 148 | { 149 | if(child.parent != this) return; 150 | var oldIndex = this.children.indexOf(child); 151 | if(index == oldIndex) return; 152 | this.children.splice(oldIndex, 1); 153 | this.children.splice(index, 0, child); 154 | }; 155 | 156 | /** 157 | * 交换在DisplayObjectContainer的子级列表中的两个子对象的索引位置。 158 | * @param {DisplayObject} child1 指定交换索引位置的子显示对象1。 159 | * @param {DisplayObject} child2 指定交换索引位置的子显示对象2。 160 | */ 161 | DisplayObjectContainer.prototype.swapChildren = function(child1, child2) 162 | { 163 | var index1 = this.getChildIndex(child1), index2 = this.getChildIndex(child2); 164 | this.children[index1] = child2; 165 | this.children[index2] = child1; 166 | }; 167 | 168 | /** 169 | * 交换在DisplayObjectContainer的子级列表中的指定索引位置的两个子对象。 170 | * @param {Integer} index1 指定交换索引位置1。 171 | * @param {Integer} index2 指定交换索引位置2。 172 | */ 173 | DisplayObjectContainer.prototype.swapChildrenAt = function(index1, index2) 174 | { 175 | var child1 = this.getChildAt(index1), child2 = this.getChildAt(index2); 176 | this.children[index1] = child2; 177 | this.children[index2] = child1; 178 | }; 179 | 180 | /** 181 | * 返回DisplayObjectContainer中指定id的子显示对象。 182 | * @param {String} 指定子显示对象的id。 183 | * @return {DisplayObject} 返回指定id的子显示对象。 184 | */ 185 | DisplayObjectContainer.prototype.getChildById = function(id) 186 | { 187 | for(var i = 0, len = this.children.length; i < len; i++) 188 | { 189 | var child = this.children[i]; 190 | if(child.id == id) return child; 191 | } 192 | return null; 193 | }; 194 | 195 | /** 196 | * 删除并返回DisplayObjectContainer中指定id的子显示对象。 197 | * @param {String} 指定子显示对象的id。 198 | * @return {DisplayObject} 返回删除的指定id的子显示对象。 199 | */ 200 | DisplayObjectContainer.prototype.removeChildById = function(id) 201 | { 202 | for(var i = 0, len = this.children.length; i < len; i++) 203 | { 204 | if(this.children[i].id == id) 205 | { 206 | return this.removeChildAt(i); 207 | } 208 | } 209 | return null; 210 | }; 211 | 212 | /** 213 | * 根据参数keyOrFunction指定的子元素键值或自定义函数对DisplayObjectContainer的子元素进行排序。 214 | * @param keyOrFunction 指定排序的子元素的键值或自定义函数。 215 | */ 216 | DisplayObjectContainer.prototype.sortChildren = function(keyOrFunction) 217 | { 218 | var f = keyOrFunction; 219 | if(typeof(f) == "string") 220 | { 221 | var key = f; 222 | f = function(a, b) 223 | { 224 | return b[key] - a[key]; 225 | }; 226 | } 227 | this.children.sort(f); 228 | }; 229 | 230 | /** 231 | * 确定指定对象是否为DisplayObjectContainer的子显示对象。 232 | * @param {DisplayObject} child 指定的显示对象。 233 | * @return {Boolean} 指定对象为DisplayObjectContainer的子显示对象返回true,否则返回false。 234 | */ 235 | DisplayObjectContainer.prototype.contains = function(child) 236 | { 237 | return this.getChildIndex(child) != -1; 238 | }; 239 | 240 | /** 241 | * 返回DisplayObjectContainer的子显示对象的数量。 242 | * @return {Integer} 返回子显示对象的数量。 243 | */ 244 | DisplayObjectContainer.prototype.getNumChildren = function() 245 | { 246 | return this.children.length; 247 | }; 248 | 249 | /** 250 | * 覆盖父类DisplayObject的_update方法,更新所有子显示对象的深度。 251 | * @protected 252 | */ 253 | DisplayObjectContainer.prototype._update = function(timeInfo) 254 | { 255 | //先更新容器本身的数据,再更新子元素的数据 256 | var result = true; 257 | if(this.update != null) result = this.update(timeInfo); 258 | if(result === false) return; 259 | 260 | var copy = this.children.slice(0); 261 | for(var i = 0, len = copy.length; i < len; i++) 262 | { 263 | var child = copy[i]; 264 | child._depth = i + 1; 265 | child._update(timeInfo); 266 | } 267 | }; 268 | 269 | /** 270 | * 渲染DisplayObjectContainer本身及其所有子显示对象。 271 | * @param {Context} 渲染上下文。 272 | */ 273 | DisplayObjectContainer.prototype.render = function(context) 274 | { 275 | DisplayObjectContainer.superClass.render.call(this, context); 276 | 277 | for(var i = 0, len = this.children.length; i < len; i++) 278 | { 279 | var child = this.children[i]; 280 | child._render(context); 281 | } 282 | }; 283 | 284 | /** 285 | * 返回x和y指定点下的DisplayObjectContainer的子项(或孙子项,依此类推)的数组集合。默认只返回最先加入的子显示对象。 286 | * @param {Number} x 指定点的x轴坐标。 287 | * @param {Number} y 指定点的y轴坐标。 288 | * @param {Boolean} usePolyCollision 指定是否采用多边形碰撞检测。默认为false。 289 | * @param {Boolean} returnAll 指定是否返回指定点下的所有显示对象。默认为false。 290 | * @return 返回指定点下的显示对象集合,当然returnAll为false时只返回最先加入的子显示对象。 291 | */ 292 | DisplayObjectContainer.prototype.getObjectUnderPoint = function(x, y, usePolyCollision, returnAll) 293 | { 294 | if(returnAll) var result = []; 295 | 296 | for(var i = this.children.length - 1; i >= 0; i--) 297 | { 298 | var child = this.children[i]; 299 | if(child == null || (!child.eventEnabled && child.children == undefined) || !child.visible || child.alpha <= 0) continue; 300 | 301 | if(child.children != undefined && child.eventChildren && child.getNumChildren() > 0) 302 | { 303 | var obj = child.getObjectUnderPoint(x, y, usePolyCollision, returnAll); 304 | if(obj) 305 | { 306 | if(returnAll) {if(obj.length > 0) result = result.concat(obj);} 307 | else return obj; 308 | }else if(child.hitTestPoint(x, y, usePolyCollision) >= 0) 309 | { 310 | if(returnAll) result.push(child); 311 | else return child; 312 | } 313 | }else 314 | { 315 | if(child.hitTestPoint(x, y, usePolyCollision) >= 0) 316 | { 317 | if(returnAll) result.push(child); 318 | else return child; 319 | } 320 | } 321 | } 322 | if(returnAll) return result; 323 | return null; 324 | }; 325 | 326 | })(); 327 | -------------------------------------------------------------------------------- /docs/css/bootstrap-responsive.min.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Responsive v2.0.4 3 | * 4 | * Copyright 2012 Twitter, Inc 5 | * Licensed under the Apache License v2.0 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Designed and built with all the love in the world @twitter by @mdo and @fat. 9 | */.clearfix{*zoom:1}.clearfix:before,.clearfix:after{display:table;content:""}.clearfix:after{clear:both}.hide-text{font:0/0 a;color:transparent;text-shadow:none;background-color:transparent;border:0}.input-block-level{display:block;width:100%;min-height:28px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;box-sizing:border-box}.hidden{display:none;visibility:hidden}.visible-phone{display:none!important}.visible-tablet{display:none!important}.hidden-desktop{display:none!important}@media(max-width:767px){.visible-phone{display:inherit!important}.hidden-phone{display:none!important}.hidden-desktop{display:inherit!important}.visible-desktop{display:none!important}}@media(min-width:768px) and (max-width:979px){.visible-tablet{display:inherit!important}.hidden-tablet{display:none!important}.hidden-desktop{display:inherit!important}.visible-desktop{display:none!important}}@media(max-width:480px){.nav-collapse{-webkit-transform:translate3d(0,0,0)}.page-header h1 small{display:block;line-height:18px}input[type="checkbox"],input[type="radio"]{border:1px solid #ccc}.form-horizontal .control-group>label{float:none;width:auto;padding-top:0;text-align:left}.form-horizontal .controls{margin-left:0}.form-horizontal .control-list{padding-top:0}.form-horizontal .form-actions{padding-right:10px;padding-left:10px}.modal{position:absolute;top:10px;right:10px;left:10px;width:auto;margin:0}.modal.fade.in{top:auto}.modal-header .close{padding:10px;margin:-10px}.carousel-caption{position:static}}@media(max-width:767px){body{padding-right:20px;padding-left:20px}.navbar-fixed-top,.navbar-fixed-bottom{margin-right:-20px;margin-left:-20px}.container-fluid{padding:0}.dl-horizontal dt{float:none;width:auto;clear:none;text-align:left}.dl-horizontal dd{margin-left:0}.container{width:auto}.row-fluid{width:100%}.row,.thumbnails{margin-left:0}[class*="span"],.row-fluid [class*="span"]{display:block;float:none;width:auto;margin-left:0}.input-large,.input-xlarge,.input-xxlarge,input[class*="span"],select[class*="span"],textarea[class*="span"],.uneditable-input{display:block;width:100%;min-height:28px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;box-sizing:border-box}.input-prepend input,.input-append input,.input-prepend input[class*="span"],.input-append input[class*="span"]{display:inline-block;width:auto}}@media(min-width:768px) and (max-width:979px){.row{margin-left:-20px;*zoom:1}.row:before,.row:after{display:table;content:""}.row:after{clear:both}[class*="span"]{float:left;margin-left:20px}.container,.navbar-fixed-top .container,.navbar-fixed-bottom .container{width:724px}.span12{width:724px}.span11{width:662px}.span10{width:600px}.span9{width:538px}.span8{width:476px}.span7{width:414px}.span6{width:352px}.span5{width:290px}.span4{width:228px}.span3{width:166px}.span2{width:104px}.span1{width:42px}.offset12{margin-left:764px}.offset11{margin-left:702px}.offset10{margin-left:640px}.offset9{margin-left:578px}.offset8{margin-left:516px}.offset7{margin-left:454px}.offset6{margin-left:392px}.offset5{margin-left:330px}.offset4{margin-left:268px}.offset3{margin-left:206px}.offset2{margin-left:144px}.offset1{margin-left:82px}.row-fluid{width:100%;*zoom:1}.row-fluid:before,.row-fluid:after{display:table;content:""}.row-fluid:after{clear:both}.row-fluid [class*="span"]{display:block;float:left;width:100%;min-height:28px;margin-left:2.762430939%;*margin-left:2.709239449638298%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;box-sizing:border-box}.row-fluid [class*="span"]:first-child{margin-left:0}.row-fluid .span12{width:99.999999993%;*width:99.9468085036383%}.row-fluid .span11{width:91.436464082%;*width:91.38327259263829%}.row-fluid .span10{width:82.87292817100001%;*width:82.8197366816383%}.row-fluid .span9{width:74.30939226%;*width:74.25620077063829%}.row-fluid .span8{width:65.74585634900001%;*width:65.6926648596383%}.row-fluid .span7{width:57.182320438000005%;*width:57.129128948638304%}.row-fluid .span6{width:48.618784527%;*width:48.5655930376383%}.row-fluid .span5{width:40.055248616%;*width:40.0020571266383%}.row-fluid .span4{width:31.491712705%;*width:31.4385212156383%}.row-fluid .span3{width:22.928176794%;*width:22.874985304638297%}.row-fluid .span2{width:14.364640883%;*width:14.311449393638298%}.row-fluid .span1{width:5.801104972%;*width:5.747913482638298%}input,textarea,.uneditable-input{margin-left:0}input.span12,textarea.span12,.uneditable-input.span12{width:714px}input.span11,textarea.span11,.uneditable-input.span11{width:652px}input.span10,textarea.span10,.uneditable-input.span10{width:590px}input.span9,textarea.span9,.uneditable-input.span9{width:528px}input.span8,textarea.span8,.uneditable-input.span8{width:466px}input.span7,textarea.span7,.uneditable-input.span7{width:404px}input.span6,textarea.span6,.uneditable-input.span6{width:342px}input.span5,textarea.span5,.uneditable-input.span5{width:280px}input.span4,textarea.span4,.uneditable-input.span4{width:218px}input.span3,textarea.span3,.uneditable-input.span3{width:156px}input.span2,textarea.span2,.uneditable-input.span2{width:94px}input.span1,textarea.span1,.uneditable-input.span1{width:32px}}@media(min-width:1200px){.row{margin-left:-30px;*zoom:1}.row:before,.row:after{display:table;content:""}.row:after{clear:both}[class*="span"]{float:left;margin-left:30px}.container,.navbar-fixed-top .container,.navbar-fixed-bottom .container{width:1170px}.span12{width:1170px}.span11{width:1070px}.span10{width:970px}.span9{width:870px}.span8{width:770px}.span7{width:670px}.span6{width:570px}.span5{width:470px}.span4{width:370px}.span3{width:270px}.span2{width:170px}.span1{width:70px}.offset12{margin-left:1230px}.offset11{margin-left:1130px}.offset10{margin-left:1030px}.offset9{margin-left:930px}.offset8{margin-left:830px}.offset7{margin-left:730px}.offset6{margin-left:630px}.offset5{margin-left:530px}.offset4{margin-left:430px}.offset3{margin-left:330px}.offset2{margin-left:230px}.offset1{margin-left:130px}.row-fluid{width:100%;*zoom:1}.row-fluid:before,.row-fluid:after{display:table;content:""}.row-fluid:after{clear:both}.row-fluid [class*="span"]{display:block;float:left;width:100%;min-height:28px;margin-left:2.564102564%;*margin-left:2.510911074638298%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;box-sizing:border-box}.row-fluid [class*="span"]:first-child{margin-left:0}.row-fluid .span12{width:100%;*width:99.94680851063829%}.row-fluid .span11{width:91.45299145300001%;*width:91.3997999636383%}.row-fluid .span10{width:82.905982906%;*width:82.8527914166383%}.row-fluid .span9{width:74.358974359%;*width:74.30578286963829%}.row-fluid .span8{width:65.81196581200001%;*width:65.7587743226383%}.row-fluid .span7{width:57.264957265%;*width:57.2117657756383%}.row-fluid .span6{width:48.717948718%;*width:48.6647572286383%}.row-fluid .span5{width:40.170940171000005%;*width:40.117748681638304%}.row-fluid .span4{width:31.623931624%;*width:31.5707401346383%}.row-fluid .span3{width:23.076923077%;*width:23.0237315876383%}.row-fluid .span2{width:14.529914530000001%;*width:14.4767230406383%}.row-fluid .span1{width:5.982905983%;*width:5.929714493638298%}input,textarea,.uneditable-input{margin-left:0}input.span12,textarea.span12,.uneditable-input.span12{width:1160px}input.span11,textarea.span11,.uneditable-input.span11{width:1060px}input.span10,textarea.span10,.uneditable-input.span10{width:960px}input.span9,textarea.span9,.uneditable-input.span9{width:860px}input.span8,textarea.span8,.uneditable-input.span8{width:760px}input.span7,textarea.span7,.uneditable-input.span7{width:660px}input.span6,textarea.span6,.uneditable-input.span6{width:560px}input.span5,textarea.span5,.uneditable-input.span5{width:460px}input.span4,textarea.span4,.uneditable-input.span4{width:360px}input.span3,textarea.span3,.uneditable-input.span3{width:260px}input.span2,textarea.span2,.uneditable-input.span2{width:160px}input.span1,textarea.span1,.uneditable-input.span1{width:60px}.thumbnails{margin-left:-30px}.thumbnails>li{margin-left:30px}.row-fluid .thumbnails{margin-left:0}}@media(max-width:979px){body{padding-top:0}.navbar-fixed-top,.navbar-fixed-bottom{position:static}.navbar-fixed-top{margin-bottom:18px}.navbar-fixed-bottom{margin-top:18px}.navbar-fixed-top .navbar-inner,.navbar-fixed-bottom .navbar-inner{padding:5px}.navbar .container{width:auto;padding:0}.navbar .brand{padding-right:10px;padding-left:10px;margin:0 0 0 -5px}.nav-collapse{clear:both}.nav-collapse .nav{float:none;margin:0 0 9px}.nav-collapse .nav>li{float:none}.nav-collapse .nav>li>a{margin-bottom:2px}.nav-collapse .nav>.divider-vertical{display:none}.nav-collapse .nav .nav-header{color:#999;text-shadow:none}.nav-collapse .nav>li>a,.nav-collapse .dropdown-menu a{padding:6px 15px;font-weight:bold;color:#999;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.nav-collapse .btn{padding:4px 10px 4px;font-weight:normal;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.nav-collapse .dropdown-menu li+li a{margin-bottom:2px}.nav-collapse .nav>li>a:hover,.nav-collapse .dropdown-menu a:hover{background-color:#222}.nav-collapse.in .btn-group{padding:0;margin-top:5px}.nav-collapse .dropdown-menu{position:static;top:auto;left:auto;display:block;float:none;max-width:none;padding:0;margin:0 15px;background-color:transparent;border:0;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0;-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}.nav-collapse .dropdown-menu:before,.nav-collapse .dropdown-menu:after{display:none}.nav-collapse .dropdown-menu .divider{display:none}.nav-collapse .navbar-form,.nav-collapse .navbar-search{float:none;padding:9px 15px;margin:9px 0;border-top:1px solid #222;border-bottom:1px solid #222;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.1);-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.1);box-shadow:inset 0 1px 0 rgba(255,255,255,0.1),0 1px 0 rgba(255,255,255,0.1)}.navbar .nav-collapse .nav.pull-right{float:none;margin-left:0}.nav-collapse,.nav-collapse.collapse{height:0;overflow:hidden}.navbar .btn-navbar{display:block}.navbar-static .navbar-inner{padding-right:10px;padding-left:10px}}@media(min-width:980px){.nav-collapse.collapse{height:auto!important;overflow:visible!important}} 10 | -------------------------------------------------------------------------------- /docs/api/symbols/Drawable.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |119 | 120 | 121 | 122 | Drawable是可绘制图像或DOM的包装。当封装的是HTMLImageElement、HTMLCanvasElement或HTMLVideoElement对象时,可同时支持canvas和dom两种渲染方式,而如果封装的是dom时,则不支持canvas方式。 123 | 124 |
125 | 126 | 127 | 128 || 133 | | 说明 | 134 |
|---|---|
| 139 | |
140 |
141 | Drawable(drawable, isDOM)
142 |
143 | 构造函数.
144 | |
145 |
| 162 | | 说明 | 163 |
|---|---|
| 169 | |
170 | get(obj, context)
171 |
172 | 根据context上下文获取不同的Drawable包装的对象。
173 | |
174 |
| 178 | |
179 | set(drawable, isDOM)
180 |
181 | 设置Drawable对象。
182 | |
183 |