Skip to content

Commit ce9be4f

Browse files
committed
Bug fixes
1 parent cb0060b commit ce9be4f

32 files changed

+409
-1049
lines changed

Diff for: cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
proto.transform = function(parentCmd, recursive){
5858
var node = this._node;
59-
cc.Node.WebGLRenderCmd.prototype.transform.call(this, parentCmd, recursive);
59+
this.originTransform(parentCmd, recursive);
6060
if(node._stencil) {
6161
node._stencil._renderCmd.transform(this, recursive);
6262
}

Diff for: cocos2d/core/CCDirector.js

+27-12
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,6 @@
2626

2727
cc.g_NumberOfDraws = 0;
2828

29-
cc.GLToClipTransform = function (transformOut) {
30-
//var projection = new cc.math.Matrix4();
31-
//cc.kmGLGetMatrix(cc.KM_GL_PROJECTION, projection);
32-
cc.kmGLGetMatrix(cc.KM_GL_PROJECTION, transformOut);
33-
34-
var modelview = new cc.math.Matrix4();
35-
cc.kmGLGetMatrix(cc.KM_GL_MODELVIEW, modelview);
36-
37-
transformOut.multiply(modelview);
38-
};
3929
//----------------------------------------------------------------------------------------------------------------------
4030

4131
/**
@@ -191,7 +181,16 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
191181
* @param {cc.Point} uiPoint
192182
* @return {cc.Point}
193183
*/
194-
convertToGL: null,
184+
convertToGL: function (uiPoint) {
185+
var docElem = document.documentElement;
186+
var view = cc.view;
187+
var box = element.getBoundingClientRect();
188+
box.left += window.pageXOffset - docElem.clientLeft;
189+
box.top += window.pageYOffset - docElem.clientTop;
190+
var x = view._devicePixelRatio * (uiPoint.x - box.left);
191+
var y = view._devicePixelRatio * (box.top + box.height - uiPoint.y);
192+
return view._isRotated ? {x: view._viewPortRect.width - y, y: x} : {x: x, y: y};
193+
},
195194

196195
/**
197196
* Converts an WebGL coordinate to a view coordinate<br/>
@@ -201,7 +200,23 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
201200
* @param {cc.Point} glPoint
202201
* @return {cc.Point}
203202
*/
204-
convertToUI: null,
203+
convertToUI: function (glPoint) {
204+
var docElem = document.documentElement;
205+
var view = cc.view;
206+
var box = element.getBoundingClientRect();
207+
box.left += window.pageXOffset - docElem.clientLeft;
208+
box.top += window.pageYOffset - docElem.clientTop;
209+
var uiPoint = {x: 0, y: 0};
210+
if (view._isRotated) {
211+
uiPoint.x = box.left + glPoint.y / view._devicePixelRatio;
212+
uiPoint.y = box.top + box.height - (view._viewPortRect.width - glPoint.x) / view._devicePixelRatio;
213+
}
214+
else {
215+
uiPoint.x = box.left + glPoint.x / view._devicePixelRatio;
216+
uiPoint.y = box.top + box.height - glPoint.y / view._devicePixelRatio;
217+
}
218+
return uiPoint;
219+
},
205220

206221
/**
207222
* Draw the scene. This method is called every frame. Don't call it manually.

Diff for: cocos2d/core/CCDirectorWebGL.js

-34
Original file line numberDiff line numberDiff line change
@@ -164,40 +164,6 @@ cc.game.addEventListener(cc.game.EVENT_RENDERER_INITED, function () {
164164
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
165165
};
166166

167-
_p._beforeVisitScene = function () {
168-
cc.kmGLPushMatrix();
169-
};
170-
171-
_p._afterVisitScene = function () {
172-
cc.kmGLPopMatrix();
173-
};
174-
175-
_p.convertToGL = function (uiPoint) {
176-
var transform = new cc.math.Matrix4();
177-
cc.GLToClipTransform(transform);
178-
179-
var transformInv = transform.inverse();
180-
181-
// Calculate z=0 using -> transform*[0, 0, 0, 1]/w
182-
var zClip = transform.mat[14] / transform.mat[15];
183-
var glSize = this._openGLView.getDesignResolutionSize();
184-
var glCoord = new cc.math.Vec3(2.0 * uiPoint.x / glSize.width - 1.0, 1.0 - 2.0 * uiPoint.y / glSize.height, zClip);
185-
glCoord.transformCoord(transformInv);
186-
return cc.p(glCoord.x, glCoord.y);
187-
};
188-
189-
_p.convertToUI = function (glPoint) {
190-
var transform = new cc.math.Matrix4();
191-
cc.GLToClipTransform(transform);
192-
193-
var clipCoord = new cc.math.Vec3(glPoint.x, glPoint.y, 0.0);
194-
// Need to calculate the zero depth from the transform.
195-
clipCoord.transformCoord(transform);
196-
197-
var glSize = this._openGLView.getDesignResolutionSize();
198-
return cc.p(glSize.width * (clipCoord.x * 0.5 + 0.5), glSize.height * (-clipCoord.y * 0.5 + 0.5));
199-
};
200-
201167
_p.getVisibleSize = function () {
202168
//if (this._openGLView) {
203169
return this._openGLView.getVisibleSize();

Diff for: cocos2d/core/base-nodes/CCNodeCanvasRenderCmd.js

+35-36
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ cc.Node.RenderCmd.prototype = {
134134

135135
var hasRotation = node._rotationX || node._rotationY;
136136
var hasSkew = node._skewX || node._skewY;
137+
var sx = node._scaleX, sy = node._scaleY;
138+
var appX = this._anchorPointInPoints.x, appY = this._anchorPointInPoints.y;
139+
var a = 1, b = 0, c = 0, d = 1;
137140
if (hasRotation || hasSkew) {
138-
var sx = node._scaleX, sy = node._scaleY;
139-
var appX = this._anchorPointInPoints.x, appY = this._anchorPointInPoints.y;
140-
141141
// position
142142
t.tx = node._position.x;
143143
t.ty = node._position.y;
@@ -166,27 +166,26 @@ cc.Node.RenderCmd.prototype = {
166166

167167
// skew
168168
if (hasSkew) {
169-
// offset the anchorpoint
170-
var skx = Math.tan(-node._skewX * Math.PI / 180);
171-
var sky = Math.tan(-node._skewY * Math.PI / 180);
169+
var skx = Math.tan(node._skewX * Math.PI / 180);
170+
var sky = Math.tan(node._skewY * Math.PI / 180);
172171
if (skx === Infinity)
173172
skx = 99999999;
174173
if (sky === Infinity)
175174
sky = 99999999;
176-
var xx = appY * skx;
177-
var yy = appX * sky;
178-
t.a = a - c * sky;
179-
t.b = b - d * sky;
180-
t.c = c - a * skx;
181-
t.d = d - b * skx;
182-
t.tx += a * xx + c * yy;
183-
t.ty += b * xx + d * yy;
175+
t.a = a + b * sky;
176+
t.b = b + a * sky;
177+
t.c = c + d * skx;
178+
t.d = d + c * skx;
184179
}
185180

186-
// adjust anchorPoint
187-
if (!node._ignoreAnchorPointForPosition && (appX || appY)) {
181+
if (appX || appY) {
188182
t.tx -= t.a * appX + t.c * appY;
189183
t.ty -= t.b * appX + t.d * appY;
184+
// adjust anchorPoint
185+
if (node._ignoreAnchorPointForPosition) {
186+
t.tx += appX;
187+
t.ty += appY;
188+
}
190189
}
191190

192191
if (pt) {
@@ -207,17 +206,21 @@ cc.Node.RenderCmd.prototype = {
207206
}
208207
}
209208
else {
210-
t.a = node._scaleX;
209+
t.a = sx;
211210
t.b = 0;
212211
t.c = 0;
213-
t.d = node._scaleY;
214-
if (node._ignoreAnchorPointForPosition) {
215-
t.tx = node._position.x;
216-
t.ty = node._position.y;
217-
}
218-
else {
219-
t.tx = node._position.x - this._anchorPointInPoints.x * t.a;
220-
t.ty = node._position.y - this._anchorPointInPoints.y * t.d;
212+
t.d = sy;
213+
t.tx = node._position.x;
214+
t.ty = node._position.y;
215+
216+
if (appX || appY) {
217+
t.tx -= t.a * appX;
218+
t.ty -= t.d * appY;
219+
// adjust anchorPoint
220+
if (node._ignoreAnchorPointForPosition) {
221+
t.tx += appX;
222+
t.ty += appY;
223+
}
221224
}
222225

223226
if (pt) {
@@ -255,14 +258,20 @@ cc.Node.RenderCmd.prototype = {
255258
},
256259

257260
visit: function (parentCmd) {
258-
var node = this._node;
261+
var node = this._node, renderer = cc.renderer;
259262
// quick return if not visible
260263
if (!node._visible)
261264
return;
262265

263266
parentCmd = parentCmd || this.getParentRenderCmd();
264267
if (parentCmd)
265268
this._curLevel = parentCmd._curLevel + 1;
269+
270+
if (isNaN(node._customZ)) {
271+
node._vertexZ = renderer.assignedZ;
272+
renderer.assignedZ += renderer.assignedZStep;
273+
}
274+
266275
this._syncStatus(parentCmd);
267276
this.visitChildren();
268277
},
@@ -471,22 +480,12 @@ cc.Node.RenderCmd.prototype = {
471480
}
472481
}
473482

474-
if (isNaN(node._customZ)) {
475-
node._vertexZ = renderer.assignedZ;
476-
renderer.assignedZ += renderer.assignedZStep;
477-
}
478-
479483
renderer.pushRenderCommand(this);
480484
for (; i < len; i++) {
481485
child = children[i];
482486
child._renderCmd.visit(this);
483487
}
484488
} else {
485-
if (isNaN(node._customZ)) {
486-
node._vertexZ = renderer.assignedZ;
487-
renderer.assignedZ += renderer.assignedZStep;
488-
}
489-
490489
renderer.pushRenderCommand(this);
491490
}
492491
this._dirtyFlag = 0;

Diff for: cocos2d/core/layers/CCLayer.js

-18
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,6 @@ cc.LayerColor = cc.Layer.extend(/** @lends cc.LayerColor# */{
203203
* @return {Boolean}
204204
*/
205205
init: function (color, width, height) {
206-
if (cc._renderType !== cc.game.RENDER_TYPE_CANVAS)
207-
this.shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_COLOR);
208-
209206
var winSize = cc.director.getWinSize();
210207
color = color || cc.color(0, 0, 0, 255);
211208
width = width === undefined ? winSize.width : width;
@@ -239,21 +236,6 @@ cc.LayerColor = cc.Layer.extend(/** @lends cc.LayerColor# */{
239236
this._renderCmd.updateBlendFunc(locBlendFunc);
240237
},
241238

242-
_setWidth: function(width){
243-
cc.Node.prototype._setWidth.call(this, width);
244-
this._renderCmd._updateSquareVerticesWidth(width);
245-
},
246-
247-
_setHeight: function(height){
248-
cc.Node.prototype._setHeight.call(this, height);
249-
this._renderCmd._updateSquareVerticesHeight(height);
250-
},
251-
252-
setContentSize: function(size, height){
253-
cc.Layer.prototype.setContentSize.call(this, size, height);
254-
this._renderCmd._updateSquareVertices(size, height);
255-
},
256-
257239
_createRenderCmd: function(){
258240
if (cc._renderType === cc.game.RENDER_TYPE_CANVAS)
259241
return new cc.LayerColor.CanvasRenderCmd(this);

Diff for: cocos2d/core/layers/CCLayerCanvasRenderCmd.js

+11-15
Original file line numberDiff line numberDiff line change
@@ -355,18 +355,6 @@
355355
* cc.LayerGradient's rendering objects of Canvas
356356
*/
357357
(function(){
358-
cc.LayerGradient.RenderCmd = {
359-
updateStatus: function () {
360-
var flags = cc.Node._dirtyFlags, locFlag = this._dirtyFlag;
361-
if (locFlag & flags.gradientDirty) {
362-
this._dirtyFlag |= flags.colorDirty;
363-
this._dirtyFlag = this._dirtyFlag & flags.gradientDirty ^ this._dirtyFlag;
364-
}
365-
366-
cc.Node.RenderCmd.prototype.updateStatus.call(this);
367-
}
368-
};
369-
370358
cc.LayerGradient.CanvasRenderCmd = function(renderable){
371359
cc.LayerColor.CanvasRenderCmd.call(this, renderable);
372360
this._needDraw = true;
@@ -376,7 +364,6 @@
376364
this._endStopStr = null;
377365
};
378366
var proto = cc.LayerGradient.CanvasRenderCmd.prototype = Object.create(cc.LayerColor.CanvasRenderCmd.prototype);
379-
cc.inject(cc.LayerGradient.RenderCmd, proto);
380367
proto.constructor = cc.LayerGradient.CanvasRenderCmd;
381368

382369
proto.rendering = function (ctx, scaleX, scaleY) {
@@ -409,6 +396,16 @@
409396
cc.g_NumberOfDraws++;
410397
};
411398

399+
proto.updateStatus = function () {
400+
var flags = cc.Node._dirtyFlags, locFlag = this._dirtyFlag;
401+
if (locFlag & flags.gradientDirty) {
402+
this._dirtyFlag |= flags.colorDirty;
403+
this._dirtyFlag = this._dirtyFlag & flags.gradientDirty ^ this._dirtyFlag;
404+
}
405+
406+
cc.Node.RenderCmd.prototype.updateStatus.call(this);
407+
};
408+
412409
proto._syncStatus = function (parentCmd) {
413410
var flags = cc.Node._dirtyFlags, locFlag = this._dirtyFlag;
414411
if (locFlag & flags.gradientDirty) {
@@ -419,11 +416,10 @@
419416
cc.Node.RenderCmd.prototype._syncStatus.call(this, parentCmd);
420417
};
421418

422-
proto._updateColor = function(){
419+
proto._updateColor = function() {
423420
var node = this._node;
424421
var contentSize = node._contentSize;
425422
var tWidth = contentSize.width * 0.5, tHeight = contentSize.height * 0.5;
426-
this._dirtyFlag = this._dirtyFlag & cc.Node._dirtyFlags.gradientDirty ^ this._dirtyFlag;
427423

428424
//fix the bug of gradient layer
429425
var angle = cc.pAngleSigned(cc.p(0, -1), node._alongVector);

0 commit comments

Comments
 (0)