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
806bbcae
Commit
806bbcae
authored
Oct 02, 2021
by
huoshizhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 图片小于512的时候
parent
e8f1cac2
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
427 additions
and
76 deletions
+427
-76
demo_05_alphaClick.fire
play/assets/unit_demo/scene/demo_05_alphaClick.fire
+297
-5
demo_05_alphaClick.js
play/assets/unit_demo/scene/demo_05_alphaClick.js
+80
-70
New Folder.meta
play/assets/unit_demo/textures/New Folder.meta
+12
-0
QQ图片20211002174831.png
...sets/unit_demo/textures/New Folder/QQ图片20211002174831.png
+0
-0
QQ图片20211002174831.png.meta
...unit_demo/textures/New Folder/QQ图片20211002174831.png.meta
+37
-0
icon_bigstar.png.meta
play/assets/unit_demo/textures/icon_bigstar.png.meta
+1
-1
No files found.
play/assets/unit_demo/scene/demo_05_alphaClick.fire
View file @
806bbcae
...
@@ -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__": 1
0
"__id__": 1
6
},
},
{
{
"__id__": 1
1
"__id__": 1
7
}
}
],
],
"_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": "",
...
...
play/assets/unit_demo/scene/demo_05_alphaClick.js
View file @
806bbcae
...
@@ -6,97 +6,107 @@ cc.Class({
...
@@ -6,97 +6,107 @@ cc.Class({
extends
:
cc
.
Component
,
extends
:
cc
.
Component
,
properties
:
{
properties
:
{
},
},
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
);
let
_textureIdMapDataContainer
=
{}
const
sprite2
=
cc
.
find
(
'
Canvas/bg_biga2
'
);
sprite
.
_hitTest
=
(
location
,
listener
)
=>
{
sprite2
.
on
(
cc
.
Node
.
EventType
.
TOUCH_START
,
()
=>
{
let
spriteFrame
=
sprite
.
getComponent
(
cc
.
Sprite
).
spriteFrame
sprite2
.
color
=
cc
.
color
(
RandomInt
(
255
),
RandomInt
(
255
),
RandomInt
(
255
));
if
(
spriteFrame
==
null
)
{
});
return
false
sprite2
.
_hitTest
=
this
.
_hitTest
.
bind
(
this
);
}
},
let
posInNode
=
sprite
.
convertToNodeSpaceAR
(
location
)
let
rect
=
spriteFrame
.
getRect
()
_hitTest
(
location
,
listener
)
{
let
offset
=
spriteFrame
.
getOffset
()
const
sprite
=
listener
.
owner
;
if
((
posInNode
.
x
<
offset
.
x
-
rect
.
width
/
2
)
let
spriteFrame
=
sprite
.
getComponent
(
cc
.
Sprite
).
spriteFrame
;
||
(
posInNode
.
y
<
offset
.
y
-
rect
.
height
/
2
)
if
(
spriteFrame
==
null
)
{
||
(
posInNode
.
x
>
(
offset
.
x
+
rect
.
width
/
2
))
return
false
;
||
(
posInNode
.
y
>
(
offset
.
y
+
rect
.
height
/
2
)))
{
}
return
false
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
)))
{
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
{
}
else
{
let
posInRect
=
cc
.
v2
(
parseInt
(
posInNode
.
x
-
offset
.
x
+
rect
.
width
/
2
),
parseInt
(
posInNode
.
y
-
offset
.
y
+
rect
.
height
/
2
))
var
dataContainer
=
this
.
_textureIdMapDataContainer
[
tex
.
getId
()];
let
tex
=
spriteFrame
.
getTexture
()
if
(
cc
.
sys
.
platform
===
cc
.
sys
.
QQ_PLAY
)
{
// 针对玩一玩的特殊方式
let
data
;
if
(
!
dataContainer
)
{
if
(
tex
instanceof
cc
.
RenderTexture
)
{
// 细图(width <= 512 && height <= 512) 被引擎自动打包了
tex
.
getHtmlElementObj
().
bkImage
||
tex
.
getHtmlElementObj
().
_generateBKImage
();
if
(
cc
.
sys
.
platform
===
cc
.
sys
.
QQ_PLAY
)
{
// 玩一玩平台
dataContainer
=
tex
.
getHtmlElementObj
().
bkImage
;
th
row
"
在玩一玩平台,请确保你的SpriteFrame 的宽高至少有一个大于512, 这样不会被Atlas, 不然被引擎自动Atlas之后,因为玩一玩不支持gl.readPixels 或 getImageData这样的接口,像素就读不出来了
"
th
is
.
_textureIdMapDataContainer
[
tex
.
getId
()]
=
dataContainer
;
}
}
// data就是这个texture的rgba值数组
var
buffer
=
dataContainer
.
buffer
;
buffer
.
rewind
();
if
(
spriteFrame
.
isRotated
())
{
if
(
spriteFrame
.
isRotated
())
{
data
=
rt
.
readPixels
(
null
,
rect
.
x
+
posInRect
.
y
,
rect
.
y
+
posInRect
.
x
,
1
,
1
)
buffer
.
jumpBytes
(((
rect
.
x
+
posInRect
.
y
)
+
(
rect
.
y
+
posInRect
.
x
)
*
tex
.
width
)
*
4
);
}
else
{
}
else
{
data
=
rt
.
readPixels
(
null
,
rect
.
x
+
posInRect
.
x
,
rect
.
y
+
rect
.
height
-
posInRect
.
y
,
1
,
1
)
buffer
.
jumpBytes
(((
rect
.
x
+
posInRect
.
x
)
+
(
rect
.
y
+
rect
.
height
-
posInRect
.
y
)
*
tex
.
width
)
*
4
);
}
}
}
else
{
var
dataContainer
=
_textureIdMapDataContainer
[
tex
.
getId
()]
if
(
cc
.
sys
.
platform
===
cc
.
sys
.
QQ_PLAY
)
{
// 针对玩一玩的特殊方式
data
=
[
buffer
.
readUint8Buffer
(),
buffer
.
readUint8Buffer
(),
buffer
.
readUint8Buffer
(),
buffer
.
readUint8Buffer
()];
if
(
!
dataContainer
)
{
}
else
{
tex
.
getHtmlElementObj
().
bkImage
||
tex
.
getHtmlElementObj
().
_generateBKImage
()
//Canvas 方式
dataContainer
=
tex
.
getHtmlElementObj
().
bkImage
var
scale
=
8
;
_textureIdMapDataContainer
[
tex
.
getId
()]
=
dataContainer
var
cvs
=
dataContainer
;
}
if
(
!
cvs
)
{
cvs
=
document
.
createElement
(
"
canvas
"
);
var
buffer
=
dataContainer
.
buffer
var
ctx
=
cvs
.
getContext
(
'
2d
'
);
buffer
.
rewind
()
cvs
.
width
=
tex
.
width
;
cvs
.
height
=
tex
.
height
;
if
(
spriteFrame
.
isRotated
())
{
ctx
.
drawImage
(
tex
.
getHtmlElementObj
(),
0
,
0
,
tex
.
width
,
tex
.
height
,
0
,
0
,
tex
.
width
/
scale
,
tex
.
height
/
scale
);
buffer
.
jumpBytes
(((
rect
.
x
+
posInRect
.
y
)
+
(
rect
.
y
+
posInRect
.
x
)
*
tex
.
width
)
*
4
)
this
.
_textureIdMapDataContainer
[
tex
.
getId
()]
=
cvs
;
}
else
{
}
buffer
.
jumpBytes
(((
rect
.
x
+
posInRect
.
x
)
+
(
rect
.
y
+
rect
.
height
-
posInRect
.
y
)
*
tex
.
width
)
*
4
)
}
data
=
[
buffer
.
readUint8Buffer
(),
buffer
.
readUint8Buffer
(),
buffer
.
readUint8Buffer
(),
buffer
.
readUint8Buffer
()]
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
{
}
else
{
//Canvas 方式
data
=
ctx
.
getImageData
((
rect
.
x
+
posInRect
.
x
)
/
scale
,
(
rect
.
y
+
rect
.
height
-
posInRect
.
y
)
/
scale
,
1
,
1
).
data
;
var
scale
=
8
var
cvs
=
dataContainer
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
)
_textureIdMapDataContainer
[
tex
.
getId
()]
=
cvs
}
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
)
{
if
(
data
[
3
]
<=
0
)
{
return
false
return
false
;
}
else
{
}
else
{
return
true
return
true
;
}
}
}
}
;
}
},
},
// update (dt) {},
// update (dt) {},
...
...
play/assets/unit_demo/textures/New Folder.meta
0 → 100644
View file @
806bbcae
{
"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
play/assets/unit_demo/textures/New Folder/QQ图片20211002174831.png
0 → 100644
View file @
806bbcae
23.3 KB
play/assets/unit_demo/textures/New Folder/QQ图片20211002174831.png.meta
0 → 100644
View file @
806bbcae
{
"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
play/assets/unit_demo/textures/icon_bigstar.png.meta
View file @
806bbcae
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
"filterMode": "bilinear",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"premultiplyAlpha": false,
"genMipmaps": false,
"genMipmaps": false,
"packable":
tru
e,
"packable":
fals
e,
"width": 278,
"width": 278,
"height": 275,
"height": 275,
"platformSettings": {},
"platformSettings": {},
...
...
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