Commit 806bbcae authored by huoshizhe's avatar huoshizhe

feat: 图片小于512的时候

parent e8f1cac2
...@@ -76,18 +76,27 @@ ...@@ -76,18 +76,27 @@
}, },
{ {
"__id__": 7 "__id__": 7
},
{
"__id__": 9
},
{
"__id__": 11
},
{
"__id__": 13
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 9 "__id__": 15
}, },
{ {
"__id__": 10 "__id__": 16
}, },
{ {
"__id__": 11 "__id__": 17
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -273,7 +282,7 @@ ...@@ -273,7 +282,7 @@
"__type__": "TypedArray", "__type__": "TypedArray",
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
0, 282,
56, 56,
0, 0,
0, 0,
...@@ -367,7 +376,7 @@ ...@@ -367,7 +376,7 @@
"__type__": "TypedArray", "__type__": "TypedArray",
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
0, 282,
-266, -266,
0, 0,
0, 0,
...@@ -425,6 +434,289 @@ ...@@ -425,6 +434,289 @@
"_N$cacheMode": 0, "_N$cacheMode": 0,
"_id": "30YKiyGk9CEbTC7Bpq2nEk" "_id": "30YKiyGk9CEbTC7Bpq2nEk"
}, },
{
"__type__": "cc.Node",
"_name": "bg_biga2",
"_objFlags": 0,
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 10
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 278,
"height": 275
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
-256,
186,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "e71hjZtN5ODZc9jIdfmZ+3"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 9
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "b00d89ac-54ee-4b06-878a-acef8c97f0df"
},
"_type": 0,
"_sizeMode": 1,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": "09DKjDFFVCUqTT9IP+lXLh"
},
{
"__type__": "cc.Node",
"_name": "New Label",
"_objFlags": 0,
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 12
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 506.74,
"height": 130.4
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
-344,
-10,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "5c4lOtFHROuZdGq/I+Ylx/"
},
{
"__type__": "cc.Label",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 11
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_string": "图片宽高都小于512的时候,\n图片资源的packable属性\n要设置为false",
"_N$string": "图片宽高都小于512的时候,\n图片资源的packable属性\n要设置为false",
"_fontSize": 40,
"_lineHeight": 40,
"_enableWrapText": true,
"_N$file": null,
"_isSystemFontUsed": true,
"_spacingX": 0,
"_batchAsBitmap": false,
"_styleFlags": 0,
"_underlineHeight": 0,
"_N$horizontalAlign": 1,
"_N$verticalAlign": 1,
"_N$fontFamily": "Arial",
"_N$overflow": 0,
"_N$cacheMode": 0,
"_id": "9dcpR1ilZHR7gbt3dAgv4Z"
},
{
"__type__": "cc.Node",
"_name": "QQ图片20211002174831",
"_objFlags": 0,
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 14
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 310,
"height": 389
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
-516,
209,
0,
0,
0,
0,
1,
0.7,
0.7,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "3b/6IPXGRJyKw+ljrx/W2g"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 13
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "5a6e7e46-3e7f-4f3f-a75a-731f1d221be7"
},
"_type": 0,
"_sizeMode": 1,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": "5a2PpVUkNG1JxLJK5RLySE"
},
{ {
"__type__": "cc.Canvas", "__type__": "cc.Canvas",
"_name": "", "_name": "",
......
...@@ -9,94 +9,104 @@ cc.Class({ ...@@ -9,94 +9,104 @@ cc.Class({
}, },
start () { start() {
const sprite = cc.find('Canvas/bg_biga'); this._textureIdMapDataContainer = {};
const sprite = cc.find('Canvas/bg_biga');
sprite.on(cc.Node.EventType.TOUCH_START, () => { sprite.on(cc.Node.EventType.TOUCH_START, () => {
console.log('汪汪汪');
sprite.color = cc.color(RandomInt(255), RandomInt(255), RandomInt(255)); sprite.color = cc.color(RandomInt(255), RandomInt(255), RandomInt(255));
}); });
sprite._hitTest = this._hitTest.bind(this);
const sprite2 = cc.find('Canvas/bg_biga2');
sprite2.on(cc.Node.EventType.TOUCH_START, () => {
sprite2.color = cc.color(RandomInt(255), RandomInt(255), RandomInt(255));
});
sprite2._hitTest = this._hitTest.bind(this);
},
_hitTest(location, listener) {
const sprite = listener.owner;
let _textureIdMapDataContainer = {} let spriteFrame = sprite.getComponent(cc.Sprite).spriteFrame;
sprite._hitTest = (location, listener) => {
let spriteFrame = sprite.getComponent(cc.Sprite).spriteFrame
if (spriteFrame == null) { if (spriteFrame == null) {
return false return false;
} }
let posInNode = sprite.convertToNodeSpaceAR(location) let posInNode = sprite.convertToNodeSpaceAR(location);
let rect = spriteFrame.getRect() let rect = spriteFrame.getRect();
let offset = spriteFrame.getOffset() let offset = spriteFrame.getOffset();
if ((posInNode.x < offset.x - rect.width / 2) if ((posInNode.x < offset.x - rect.width / 2)
|| (posInNode.y < offset.y - rect.height / 2) || (posInNode.y < offset.y - rect.height / 2)
|| (posInNode.x > (offset.x + rect.width / 2)) || (posInNode.x > (offset.x + rect.width / 2))
|| (posInNode.y > (offset.y + rect.height / 2))) { || (posInNode.y > (offset.y + rect.height / 2))) {
return false return false;
} else { } else {
let posInRect = cc.v2(parseInt(posInNode.x - offset.x + rect.width / 2), parseInt(posInNode.y - offset.y + rect.height / 2)) 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 tex = spriteFrame.getTexture();
let data; let data;
if (tex instanceof cc.RenderTexture) { // 细图(width <= 512 && height <= 512) 被引擎自动打包了 if (tex instanceof cc.RenderTexture) { // 细图(width <= 512 && height <= 512) 被引擎自动打包了
if (cc.sys.platform === cc.sys.QQ_PLAY) { // 玩一玩平台 if (cc.sys.platform === cc.sys.QQ_PLAY) { // 玩一玩平台
throw "在玩一玩平台,请确保你的SpriteFrame 的宽高至少有一个大于512, 这样不会被Atlas, 不然被引擎自动Atlas之后,因为玩一玩不支持gl.readPixels 或 getImageData这样的接口,像素就读不出来了" throw "在玩一玩平台,请确保你的SpriteFrame 的宽高至少有一个大于512, 这样不会被Atlas, 不然被引擎自动Atlas之后,因为玩一玩不支持gl.readPixels 或 getImageData这样的接口,像素就读不出来了"
} }
var buffer = new Uint8Array(4);
// data就是这个texture的rgba值数组 // data就是这个texture的rgba值数组
if (spriteFrame.isRotated()) { if (spriteFrame.isRotated()) {
data = rt.readPixels(null, rect.x + posInRect.y, rect.y + posInRect.x, 1, 1) data = tex.readPixels(buffer, rect.x + posInRect.y, rect.y + posInRect.x, 1, 1);
} else { } else {
data = rt.readPixels(null, rect.x + posInRect.x, rect.y + rect.height - posInRect.y, 1, 1) data = tex.readPixels(buffer, rect.x + posInRect.x, rect.y + rect.height - posInRect.y, 1, 1);
} }
console.log(tex);
} else { } else {
var dataContainer = _textureIdMapDataContainer[tex.getId()] var dataContainer = this._textureIdMapDataContainer[tex.getId()];
if (cc.sys.platform === cc.sys.QQ_PLAY) { // 针对玩一玩的特殊方式 if (cc.sys.platform === cc.sys.QQ_PLAY) { // 针对玩一玩的特殊方式
if (!dataContainer) { if (!dataContainer) {
tex.getHtmlElementObj().bkImage || tex.getHtmlElementObj()._generateBKImage() tex.getHtmlElementObj().bkImage || tex.getHtmlElementObj()._generateBKImage();
dataContainer = tex.getHtmlElementObj().bkImage dataContainer = tex.getHtmlElementObj().bkImage;
_textureIdMapDataContainer[tex.getId()] = dataContainer this._textureIdMapDataContainer[tex.getId()] = dataContainer;
} }
var buffer = dataContainer.buffer var buffer = dataContainer.buffer;
buffer.rewind() buffer.rewind();
if (spriteFrame.isRotated()) { if (spriteFrame.isRotated()) {
buffer.jumpBytes(((rect.x + posInRect.y) + (rect.y + posInRect.x) * tex.width) * 4) buffer.jumpBytes(((rect.x + posInRect.y) + (rect.y + posInRect.x) * tex.width) * 4);
} else { } else {
buffer.jumpBytes(((rect.x + posInRect.x) + (rect.y + rect.height - posInRect.y) * tex.width) * 4) buffer.jumpBytes(((rect.x + posInRect.x) + (rect.y + rect.height - posInRect.y) * tex.width) * 4);
} }
data = [buffer.readUint8Buffer(), buffer.readUint8Buffer(), buffer.readUint8Buffer(), buffer.readUint8Buffer()] data = [buffer.readUint8Buffer(), buffer.readUint8Buffer(), buffer.readUint8Buffer(), buffer.readUint8Buffer()];
} else { } else {
//Canvas 方式 //Canvas 方式
var scale = 8 var scale = 8;
var cvs = dataContainer var cvs = dataContainer;
if (!cvs) { if (!cvs) {
cvs = document.createElement("canvas") cvs = document.createElement("canvas");
var ctx = cvs.getContext('2d') var ctx = cvs.getContext('2d');
cvs.width = tex.width cvs.width = tex.width;
cvs.height = tex.height cvs.height = tex.height;
ctx.drawImage(tex.getHtmlElementObj(), 0, 0, tex.width, tex.height, 0, 0, tex.width / scale, tex.height / scale) ctx.drawImage(tex.getHtmlElementObj(), 0, 0, tex.width, tex.height, 0, 0, tex.width / scale, tex.height / scale);
_textureIdMapDataContainer[tex.getId()] = cvs this._textureIdMapDataContainer[tex.getId()] = cvs;
} }
var ctx = cvs.getContext('2d') var ctx = cvs.getContext('2d');
if (spriteFrame.isRotated()) { if (spriteFrame.isRotated()) {
data = ctx.getImageData((rect.x + posInRect.y) / scale, (rect.y + posInRect.x) / scale, 1, 1).data data = ctx.getImageData((rect.x + posInRect.y) / scale, (rect.y + posInRect.x) / scale, 1, 1).data;
} else { } else {
data = ctx.getImageData((rect.x + posInRect.x) / scale, (rect.y + rect.height - posInRect.y) / scale, 1, 1).data data = ctx.getImageData((rect.x + posInRect.x) / scale, (rect.y + rect.height - posInRect.y) / scale, 1, 1).data;
} }
} }
} }
if (data[3] <= 0) { if (data[3] <= 0) {
return false return false;
} else { } else {
return true return true;
} }
} }
};
}, },
// update (dt) {}, // update (dt) {},
......
{
"ver": "1.1.2",
"uuid": "90735cea-6082-489f-acb9-97d317b36c1e",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "47b37aca-fd01-47f4-806b-0ff0db60ab63",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 310,
"height": 389,
"platformSettings": {},
"subMetas": {
"QQ图片20211002174831": {
"ver": "1.0.4",
"uuid": "5a6e7e46-3e7f-4f3f-a75a-731f1d221be7",
"rawTextureUuid": "47b37aca-fd01-47f4-806b-0ff0db60ab63",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 310,
"height": 389,
"rawWidth": 310,
"rawHeight": 389,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
"filterMode": "bilinear", "filterMode": "bilinear",
"premultiplyAlpha": false, "premultiplyAlpha": false,
"genMipmaps": false, "genMipmaps": false,
"packable": true, "packable": false,
"width": 278, "width": 278,
"height": 275, "height": 275,
"platformSettings": {}, "platformSettings": {},
......
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