mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
transform should be computed immediately in canvas mode
This commit is contained in:
+16
-10
@@ -215,6 +215,21 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
|
||||
this._scheduler.update(deltaTime);
|
||||
},
|
||||
|
||||
_visitScene: function () {
|
||||
if (this._runningScene) {
|
||||
var renderer = cc.renderer;
|
||||
if (renderer.childrenOrderDirty) {
|
||||
renderer.clearRenderCommands();
|
||||
this._runningScene._renderCmd._curLevel = 0; //level start from 0;
|
||||
this._runningScene.visit();
|
||||
renderer.resetFlag();
|
||||
}
|
||||
else if (renderer.transformDirty()) {
|
||||
renderer.transform();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
visit: function (deltaTime) {
|
||||
this.emit(cc.Director.EVENT_BEFORE_VISIT, this);
|
||||
|
||||
@@ -228,16 +243,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
|
||||
}
|
||||
|
||||
// update the scene
|
||||
if (this._runningScene) {
|
||||
var renderer = cc.renderer;
|
||||
if (renderer.childrenOrderDirty === true) {
|
||||
renderer.clearRenderCommands();
|
||||
this._runningScene._renderCmd._curLevel = 0; //level start from 0;
|
||||
this._runningScene.visit();
|
||||
renderer.resetFlag();
|
||||
} else if (renderer.transformDirty() === true)
|
||||
renderer.transform();
|
||||
}
|
||||
this._visitScene();
|
||||
|
||||
// visit the notifications node
|
||||
if (this._notificationNode)
|
||||
|
||||
@@ -1774,12 +1774,12 @@ _ccsg.Node = cc.Class({
|
||||
* @return {cc.AffineTransform}
|
||||
*/
|
||||
getNodeToWorldTransform: function () {
|
||||
//TODO renderCmd has a WorldTransform
|
||||
var t;
|
||||
if (this._renderCmd && cc._renderType === cc.game.RENDER_TYPE_CANVAS) {
|
||||
t = this._renderCmd._worldTransform;
|
||||
}
|
||||
else {
|
||||
//TODO renderCmd has a WorldTransform
|
||||
t = this.getNodeToParentTransform();
|
||||
for (var p = this._parent; p !== null; p = p.parent) {
|
||||
t = cc.affineTransformConcat(t, p.getNodeToParentTransform());
|
||||
|
||||
@@ -1407,7 +1407,13 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
|
||||
*/
|
||||
getNodeToWorldTransform: function () {
|
||||
var contentSize = this.getContentSize();
|
||||
|
||||
if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) {
|
||||
// ensure transform computed
|
||||
cc.director._visitScene();
|
||||
}
|
||||
var mat = this._sgNode.getNodeToWorldTransform();
|
||||
|
||||
if (this._isSgTransformArToMe(contentSize)) {
|
||||
// _sgNode.getNodeToWorldTransform is not anchor relative (AR), in this case,
|
||||
// we should translate to bottem left to consistent with it
|
||||
@@ -1435,7 +1441,13 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
|
||||
*/
|
||||
getNodeToWorldTransformAR: function () {
|
||||
var contentSize = this.getContentSize();
|
||||
|
||||
if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) {
|
||||
// ensure transform computed
|
||||
cc.director._visitScene();
|
||||
}
|
||||
var mat = this._sgNode.getNodeToWorldTransform();
|
||||
|
||||
if ( !this._isSgTransformArToMe(contentSize) ) {
|
||||
// see getNodeToWorldTransform
|
||||
var tx = this._anchorPoint.x * contentSize.width;
|
||||
@@ -1454,6 +1466,10 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
|
||||
* var affineTransform = node.getWorldToNodeTransform();
|
||||
*/
|
||||
getWorldToNodeTransform: function () {
|
||||
if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) {
|
||||
// ensure transform computed
|
||||
cc.director._visitScene();
|
||||
}
|
||||
return this._sgNode.getWorldToNodeTransform();
|
||||
},
|
||||
|
||||
@@ -1467,6 +1483,10 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
|
||||
* var newVec2 = node.convertToNodeSpace(cc.v2(100, 100));
|
||||
*/
|
||||
convertToNodeSpace: function (worldPoint) {
|
||||
if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) {
|
||||
// ensure transform computed
|
||||
cc.director._visitScene();
|
||||
}
|
||||
var nodePositionIgnoreAnchorPoint = this._sgNode.convertToNodeSpace(worldPoint);
|
||||
return cc.pAdd(nodePositionIgnoreAnchorPoint, cc.p(this._anchorPoint.x * this._contentSize.width, this._anchorPoint.y * this._contentSize.height));
|
||||
},
|
||||
@@ -1481,6 +1501,10 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
|
||||
* var newVec2 = node.convertToWorldSpace(cc.v2(100, 100));
|
||||
*/
|
||||
convertToWorldSpace: function (nodePoint) {
|
||||
if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) {
|
||||
// ensure transform computed
|
||||
cc.director._visitScene();
|
||||
}
|
||||
var worldPositionIgnoreAnchorPoint = this._sgNode.convertToWorldSpace(nodePoint);
|
||||
return cc.pSub(worldPositionIgnoreAnchorPoint, cc.p(this._anchorPoint.x * this._contentSize.width, this._anchorPoint.y * this._contentSize.height));
|
||||
},
|
||||
@@ -1499,6 +1523,10 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
|
||||
* var newVec2 = node.convertToNodeSpaceAR(cc.v2(100, 100));
|
||||
*/
|
||||
convertToNodeSpaceAR: function (worldPoint) {
|
||||
if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) {
|
||||
// ensure transform computed
|
||||
cc.director._visitScene();
|
||||
}
|
||||
if (this._sgNode.isIgnoreAnchorPointForPosition()) {
|
||||
// see https://github.com/cocos-creator/engine/pull/391
|
||||
return cc.v2(this._sgNode.convertToNodeSpace(worldPoint));
|
||||
@@ -1522,6 +1550,10 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
|
||||
* var newVec2 = node.convertToWorldSpaceAR(cc.v2(100, 100));
|
||||
*/
|
||||
convertToWorldSpaceAR: function (nodePoint) {
|
||||
if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) {
|
||||
// ensure transform computed
|
||||
cc.director._visitScene();
|
||||
}
|
||||
if (this._sgNode.isIgnoreAnchorPointForPosition()) {
|
||||
// see https://github.com/cocos-creator/engine/pull/391
|
||||
return cc.v2(this._sgNode.convertToWorldSpace(nodePoint));
|
||||
@@ -1531,10 +1563,6 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
|
||||
}
|
||||
},
|
||||
|
||||
// _convertToWindowSpace: function (nodePoint) {
|
||||
// return this._sgNode._convertToWindowSpace(nodePoint);
|
||||
// },
|
||||
|
||||
/**
|
||||
* !#en convenience methods which take a cc.Touch instead of cc.Vec2.
|
||||
* !#zh 将触摸点转换成本地坐标系中位置。
|
||||
|
||||
@@ -188,8 +188,8 @@ proto._updateChild = function(){
|
||||
else {
|
||||
//var regionScaleX = attachment.width / attachment.regionOriginalWidth * attachment.scaleX;
|
||||
//ax = attachment.x + attachment.regionOffsetX * regionScaleX - (attachment.width * attachment.scaleX - attachment.regionWidth * regionScaleX) / 2;
|
||||
ax = (attachment.offset[0] + attachment.offset[2] + attachment.offset[4] + attachment.offset[6]) * 0.25;
|
||||
ay = (attachment.offset[1] + attachment.offset[3] + attachment.offset[5] + attachment.offset[7]) * 0.25;
|
||||
ax = (attachment.offset[0] + attachment.offset[4]) * 0.5;
|
||||
ay = (attachment.offset[1] + attachment.offset[5]) * 0.5;
|
||||
}
|
||||
slotNode.setPosition(bone.worldX + ax * bone.m00 + ay * bone.m01, bone.worldY + ax * bone.m10 + ay * bone.m11);
|
||||
slotNode.setScale(bone.worldScaleX, bone.worldScaleY);
|
||||
|
||||
Reference in New Issue
Block a user