let GameCommon = require(‘GameCommon’);
cc.dynamicAtlasManager.enabled = true;
cc.macro.CLEANUP_IMAGE_CACHE = false;
cc.Class({
extends: cc.Component,
properties: {
nodeTestHit: false,
transp: false,
},
// LIFE-CYCLE CALLBACKS:
onLoad() {
this.initEvent();
this.initUI();
},
// start () {
// },
setContent(content) {
this.content = content;
this.initContent();
},
initContent() {
},
removeSelf() {
this.content = null;
},
onDestroy() {
// this.removeSelf();
},
initUI() {
},
initEvent() {
if (!this.nodeTestHit) this.node._hitTest = this.hitTest.bind(this);
this.node.on(GameCommon.TOUCH_MOVE, this.touchMove, this);
this.node.on(GameCommon.TOUCH_END, this.touchEnd, this);
this.node.on(GameCommon.TOUCH_START, this.touchStart, this);
this.node.on(GameCommon.TOUCH_CANCEL, this.touchCancel, this);
},
canMove(grid) {
return true;
},
touchCancel(e) {
if (this.content) {
this.content.touchCancel(e);
}
},
touchMove(e) {
if (this.content) {
this.content.touchMove(e);
}
},
touchEnd(e) {
if (this.content) {
this.content.touchEnd(e);
}
},
touchStart(e) {
if (this.content) {
this.content.touchStart(e);
}
},
hitTest(location) {
let spriteFrame = this.node.getComponent(cc.Sprite).spriteFrame
if (spriteFrame == null) {
return false
}
let node = this.node;
let posInNode = this.node.convertToNodeSpaceAR(location)
var size = node.getContentSize();
let rect = spriteFrame.getRect()
let offset = spriteFrame.getOffset()
if(Math.abs(posInNode.x)>size.width/2||Math.abs(posInNode.y)>size.height/2)
{
return false
}
else if(require("UI3dtouch").s_instance.isTouch){
return false;
}
else {
if(!this.camera)
this.camera = require("UIDecorate").s_instance.check_camera;
if(!this.camera)return;
this.camera.node.active = true;
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
this.camera.enable = true;
let destory = false;
if( tex instanceof cc.RenderTexture){
this.node.group = "imgafter";
rt = tex;
}
else{
this.node.group = "camera";
var rt = new cc.RenderTexture()
if(tex.width == 2048)console.log("@@@@@@@@@@@@@@@@@@@@@@@" + this.node.name);
rt.initWithSize(tex.width, tex.height, cc.gfx.RB_FMT_S8)
rt.drawTextureAt(tex, 0, 0);
destory = true;
}
// data就是这个texture的rgba值数组
this.camera.targetTexture = rt;
this.camera.render(undefined);
if (spriteFrame.isRotated()) {
data = rt.readPixels(null, rect.x + posInRect.y, rect.y + posInRect.x, 1, 1)
}
else {
data = rt.readPixels(null, rect.x + posInRect.x, rect.y + rect.height - posInRect.y, 1, 1)
}
this.camera.targetTexture = null;
this.camera.enable = false;
this.camera.node.active = false;
this.node.group = "imgafter";
destory && rt.destroy();
if (data[3] <= 200) {
return false
}
else {
return true
}
}
},
onDestroy: function() {
if (!this.nodeTestHit) this.node._hitTest = this.hitTest.bind(null);
// eachAll(_textureIdMapDataContainer, (v, k)=>{
// v.destory();
// })
},
});