Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
U
unit_demo
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
unit_demo
Commits
7f038a34
Commit
7f038a34
authored
Oct 08, 2021
by
范雪寒
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 透明像素check方法支持原生环境
parent
a2bc518b
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
594 additions
and
78 deletions
+594
-78
demo_05_alphaClick.fire
play/assets/unit_demo/scene/demo_05_alphaClick.fire
+469
-46
demo_05_alphaClick.js
play/assets/unit_demo/scene/demo_05_alphaClick.js
+38
-20
QQ20211008-115534.png
...ssets/unit_demo/textures/New Folder/QQ20211008-115534.png
+0
-0
QQ20211008-115534.png.meta
.../unit_demo/textures/New Folder/QQ20211008-115534.png.meta
+10
-10
QQ20211008-115640.png
...ssets/unit_demo/textures/New Folder/QQ20211008-115640.png
+0
-0
QQ20211008-115640.png.meta
.../unit_demo/textures/New Folder/QQ20211008-115640.png.meta
+36
-0
QQ图片20211002174831.png
...sets/unit_demo/textures/New Folder/QQ图片20211002174831.png
+0
-0
icon_bigstar.png.meta
play/assets/unit_demo/textures/icon_bigstar.png.meta
+1
-1
project.json
play/settings/project.json
+40
-1
No files found.
play/assets/unit_demo/scene/demo_05_alphaClick.fire
View file @
7f038a34
This diff is collapsed.
Click to expand it.
play/assets/unit_demo/scene/demo_05_alphaClick.js
View file @
7f038a34
...
...
@@ -2,7 +2,9 @@ import {
RandomInt
}
from
"
../script/utils
"
;
// 参考: https://forum.cocos.org/t/creator/38530/56
// 参考:
// https://forum.cocos.org/t/creator/38530/56
// https://forum.cocos.org/t/topic/116551
cc
.
Class
({
extends
:
cc
.
Component
,
...
...
@@ -44,33 +46,49 @@ cc.Class({
return
false
;
}
if
(
!
this
.
camera
)
{
const
checkCameraNode
=
cc
.
find
(
'
Canvas/CheckCamera
'
);
if
(
!
checkCameraNode
)
{
throw
'
找不到[Canvas/CheckCamera]。
'
;
}
this
.
camera
=
checkCameraNode
.
getComponent
(
cc
.
Camera
);
}
if
(
this
.
camera
.
cullingMask
!=
-
2
)
{
console
.
warn
(
`[
${
this
.
camera
.
cullingMask
}
]: 检查CheckCamera的cullingMask值,应该只选择camera`
);
}
this
.
camera
.
node
.
active
=
true
;
let
posInRect
=
cc
.
v2
(
parseInt
(
posInNode
.
x
-
offset
.
x
+
(
rect
.
width
*
sprite
.
anchorX
)
),
parseInt
(
posInNode
.
y
-
offset
.
y
+
(
rect
.
height
*
sprite
.
anchorY
)
)
parseInt
(
posInNode
.
x
-
offset
.
x
+
rect
.
width
*
sprite
.
anchorX
),
parseInt
(
posInNode
.
y
-
offset
.
y
+
rect
.
height
*
sprite
.
anchorY
)
);
let
tex
=
spriteFrame
.
getTexture
();
this
.
camera
.
enable
=
true
;
let
rt
;
let
destory
=
false
;
if
(
tex
instanceof
cc
.
RenderTexture
)
{
throw
"
图片宽高都小于512的时候,图片资源的packable属性要设置为false。
"
;
}
var
scale
=
8
;
var
cvs
=
this
.
_textureIdMapDataContainer
[
tex
.
getId
()];
if
(
!
cvs
)
{
cvs
=
document
.
createElement
(
"
canvas
"
);
var
ctx
=
cvs
.
getContext
(
'
2d
'
);
cvs
.
width
=
tex
.
width
;
cvs
.
height
=
tex
.
height
;
ctx
.
drawImage
(
tex
.
getHtmlElementObj
(),
0
,
0
,
tex
.
width
,
tex
.
height
,
0
,
0
,
tex
.
width
/
scale
,
tex
.
height
/
scale
);
this
.
_textureIdMapDataContainer
[
tex
.
getId
()]
=
cvs
;
rt
=
tex
;
}
else
{
rt
=
new
cc
.
RenderTexture
()
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
);
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
;
data
=
rt
.
readPixels
(
null
,
rect
.
x
+
posInRect
.
y
,
rect
.
y
+
posInRect
.
x
,
1
,
1
)
;
}
else
{
data
=
ctx
.
getImageData
((
rect
.
x
+
posInRect
.
x
)
/
scale
,
(
rect
.
y
+
rect
.
height
-
posInRect
.
y
)
/
scale
,
1
,
1
).
data
;
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
;
if
(
destory
)
{
rt
.
destroy
();
}
if
(
data
[
3
]
>
0
)
{
...
...
play/assets/unit_demo/textures/New Folder/QQ20211008-115534.png
0 → 100644
View file @
7f038a34
11 KB
play/assets/unit_demo/textures/New Folder/QQ
图片20211002174831
.png.meta
→
play/assets/unit_demo/textures/New Folder/QQ
20211008-115534
.png.meta
View file @
7f038a34
{
"ver": "2.3.5",
"uuid": "
47b37aca-fd01-47f4-806b-0ff0db60ab63
",
"uuid": "
2b5f48f2-ec1c-4557-bbe5-4844d164689e
",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width":
310
,
"height":
389
,
"width":
217
,
"height":
180
,
"platformSettings": {},
"subMetas": {
"QQ
图片20211002174831
": {
"QQ
20211008-115534
": {
"ver": "1.0.4",
"uuid": "
5a6e7e46-3e7f-4f3f-a75a-731f1d221be7
",
"rawTextureUuid": "
47b37aca-fd01-47f4-806b-0ff0db60ab63
",
"uuid": "
40f686d0-e3e8-4898-86a5-cd61e848cab1
",
"rawTextureUuid": "
2b5f48f2-ec1c-4557-bbe5-4844d164689e
",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
...
...
@@ -22,10 +22,10 @@
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width":
310
,
"height":
389
,
"rawWidth":
310
,
"rawHeight":
389
,
"width":
217
,
"height":
180
,
"rawWidth":
217
,
"rawHeight":
180
,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
...
...
play/assets/unit_demo/textures/New Folder/QQ20211008-115640.png
0 → 100644
View file @
7f038a34
28.5 KB
play/assets/unit_demo/textures/New Folder/QQ20211008-115640.png.meta
0 → 100644
View file @
7f038a34
{
"ver": "2.3.5",
"uuid": "4eb7cf8b-6dde-4163-98ab-3a63ac62fe8c",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 468,
"height": 415,
"platformSettings": {},
"subMetas": {
"QQ20211008-115640": {
"ver": "1.0.4",
"uuid": "44119ee4-7023-4988-9c82-f7f734482b08",
"rawTextureUuid": "4eb7cf8b-6dde-4163-98ab-3a63ac62fe8c",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 468,
"height": 415,
"rawWidth": 468,
"rawHeight": 415,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
play/assets/unit_demo/textures/New Folder/QQ图片20211002174831.png
deleted
100644 → 0
View file @
a2bc518b
23.3 KB
play/assets/unit_demo/textures/icon_bigstar.png.meta
View file @
7f038a34
...
...
@@ -6,7 +6,7 @@
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable":
fals
e,
"packable":
tru
e,
"width": 278,
"height": 275,
"platformSettings": {},
...
...
play/settings/project.json
View file @
7f038a34
...
...
@@ -2,5 +2,44 @@
"last-module-event-record-time"
:
1600327709742
,
"migrate-history"
:
[
"cloud-function"
]
],
"group-list"
:
[
"default"
,
"camera"
],
"collision-matrix"
:
[
[
true
],
[
false
,
false
]
],
"excluded-modules"
:
[
"3D Physics/Builtin"
],
"preview-port"
:
7456
,
"design-resolution-width"
:
960
,
"design-resolution-height"
:
640
,
"fit-width"
:
false
,
"fit-height"
:
true
,
"use-project-simulator-setting"
:
false
,
"simulator-orientation"
:
false
,
"use-customize-simulator"
:
true
,
"simulator-resolution"
:
{
"width"
:
960
,
"height"
:
640
},
"clear-simulator-cache"
:
true
,
"facebook"
:
{
"enable"
:
false
,
"appID"
:
""
,
"live"
:
{
"enable"
:
false
},
"audience"
:
{
"enable"
:
false
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment