Commit a2bc518b authored by 范雪寒's avatar 范雪寒

feat: 删除无用的分支;添加参考url;增加对修改锚点的支持

parent 806bbcae
......@@ -275,15 +275,15 @@
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
"x": 0.2,
"y": 0.2
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
282,
56,
142,
-115,
0,
0,
0,
......
......@@ -2,6 +2,8 @@ import {
RandomInt
} from "../script/utils";
// 参考: https://forum.cocos.org/t/creator/38530/56
cc.Class({
extends: cc.Component,
......@@ -35,54 +37,25 @@ cc.Class({
let posInNode = sprite.convertToNodeSpaceAR(location);
let rect = spriteFrame.getRect();
let offset = spriteFrame.getOffset();
if ((posInNode.x < offset.x - rect.width / 2)
|| (posInNode.y < offset.y - rect.height / 2)
|| (posInNode.x > (offset.x + rect.width / 2))
|| (posInNode.y > (offset.y + rect.height / 2))) {
if ((posInNode.x < offset.x - (rect.width * sprite.anchorX))
|| (posInNode.y < offset.y - (rect.height * sprite.anchorY))
|| (posInNode.x > (offset.x + (rect.width * (1 - sprite.anchorX))))
|| (posInNode.y > (offset.y + (rect.height * (1 - sprite.anchorY))))) {
return false;
} else {
let posInRect = cc.v2(parseInt(posInNode.x - offset.x + rect.width / 2), parseInt(posInNode.y - offset.y + rect.height / 2))
let tex = spriteFrame.getTexture();
let data;
if (tex instanceof cc.RenderTexture) { // 细图(width <= 512 && height <= 512) 被引擎自动打包了
if (cc.sys.platform === cc.sys.QQ_PLAY) { // 玩一玩平台
throw "在玩一玩平台,请确保你的SpriteFrame 的宽高至少有一个大于512, 这样不会被Atlas, 不然被引擎自动Atlas之后,因为玩一玩不支持gl.readPixels 或 getImageData这样的接口,像素就读不出来了"
}
var buffer = new Uint8Array(4);
// data就是这个texture的rgba值数组
if (spriteFrame.isRotated()) {
data = tex.readPixels(buffer, rect.x + posInRect.y, rect.y + posInRect.x, 1, 1);
} else {
data = tex.readPixels(buffer, rect.x + posInRect.x, rect.y + rect.height - posInRect.y, 1, 1);
}
console.log(tex);
} else {
var dataContainer = this._textureIdMapDataContainer[tex.getId()];
if (cc.sys.platform === cc.sys.QQ_PLAY) { // 针对玩一玩的特殊方式
if (!dataContainer) {
tex.getHtmlElementObj().bkImage || tex.getHtmlElementObj()._generateBKImage();
dataContainer = tex.getHtmlElementObj().bkImage;
this._textureIdMapDataContainer[tex.getId()] = dataContainer;
}
var buffer = dataContainer.buffer;
buffer.rewind();
let posInRect = cc.v2(
parseInt(posInNode.x - offset.x + (rect.width * sprite.anchorX)),
parseInt(posInNode.y - offset.y + (rect.height * sprite.anchorY))
);
if (spriteFrame.isRotated()) {
buffer.jumpBytes(((rect.x + posInRect.y) + (rect.y + posInRect.x) * tex.width) * 4);
} else {
buffer.jumpBytes(((rect.x + posInRect.x) + (rect.y + rect.height - posInRect.y) * tex.width) * 4);
let tex = spriteFrame.getTexture();
if (tex instanceof cc.RenderTexture) {
throw "图片宽高都小于512的时候,图片资源的packable属性要设置为false。";
}
data = [buffer.readUint8Buffer(), buffer.readUint8Buffer(), buffer.readUint8Buffer(), buffer.readUint8Buffer()];
} else {
//Canvas 方式
var scale = 8;
var cvs = dataContainer;
var cvs = this._textureIdMapDataContainer[tex.getId()];
if (!cvs) {
cvs = document.createElement("canvas");
var ctx = cvs.getContext('2d');
......@@ -92,22 +65,18 @@ cc.Class({
this._textureIdMapDataContainer[tex.getId()] = cvs;
}
let data;
var ctx = cvs.getContext('2d');
if (spriteFrame.isRotated()) {
data = ctx.getImageData((rect.x + posInRect.y) / scale, (rect.y + posInRect.x) / scale, 1, 1).data;
} else {
data = ctx.getImageData((rect.x + posInRect.x) / scale, (rect.y + rect.height - posInRect.y) / scale, 1, 1).data;
}
}
}
if (data[3] <= 0) {
return false;
} else {
if (data[3] > 0) {
return true;
}
} else {
return false;
}
},
// update (dt) {},
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment