Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
et15_flipcard
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
et15_flipcard
Commits
c4026bc3
Commit
c4026bc3
authored
Apr 12, 2021
by
Li MingZhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 加载图片方式修改
parent
0db50b23
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
18 deletions
+65
-18
flipCard.fire
play/assets/tmpGame/scene/flipCard.fire
+1
-1
flipCard.js
play/assets/tmpGame/script/flipCard.js
+29
-12
util.js
play/assets/tmpGame/script/util.js
+31
-1
播放中2.png.meta
play/assets/tmpGame/textures/播放中2.png.meta
+2
-2
播放中3.png.meta
play/assets/tmpGame/textures/播放中3.png.meta
+2
-2
No files found.
play/assets/tmpGame/scene/flipCard.fire
View file @
c4026bc3
...
...
@@ -183,7 +183,7 @@
"array": [
0,
0,
623.5382907247958
,
259.8076211353316
,
0,
0,
0,
...
...
play/assets/tmpGame/script/flipCard.js
View file @
c4026bc3
import
{
playAudioByUrl
}
from
"
./util
"
;
import
{
getSprNodeByUrl
,
playAudioByUrl
}
from
"
./util
"
;
cc
.
Class
({
extends
:
cc
.
Component
,
...
...
@@ -210,8 +210,14 @@ cc.Class({
playAudio
.
play
();
});
for
(
let
index
=
0
;
index
<
this
.
_imageResList
.
length
;
index
++
)
{
console
.
log
(
"
_imageResList:
"
,
this
.
_imageResList
);
const
picArr
=
this
.
data
.
contentObj
.
picArr
;
for
(
let
index
=
0
;
index
<
picArr
.
length
;
index
++
)
{
const
cardNode
=
cc
.
instantiate
(
cc
.
find
(
'
Canvas/Card
'
));
const
imgNode
=
cardNode
.
getChildByName
(
'
img
'
);
const
bgbackNode
=
cardNode
.
getChildByName
(
'
bgback
'
);
// label 加载
...
...
@@ -219,18 +225,29 @@ cc.Class({
var
label
=
labelNode
.
getComponent
(
cc
.
Label
);
label
.
string
=
this
.
_textResList
[
index
].
text
;
// img 加载
const
img
=
imgNode
.
addComponent
(
cc
.
Sprite
);
var
imgUrl
=
this
.
_imageResList
[
index
].
url
;
cc
.
loader
.
load
(
imgUrl
,
function
(
err
,
texture
)
{
// Use texture to create sprite frame
getSprNodeByUrl
(
picArr
[
index
].
left
.
pic_url
,
(
spr
)
=>
{
var
maxWidth
=
160
;
var
maxHeight
=
160
;
const
spriteFrame
=
new
cc
.
SpriteFrame
(
texture
);
img
.
spriteFrame
=
spriteFrame
;
var
scaleX
=
maxWidth
/
imgNode
.
width
;
var
scaleY
=
maxHeight
/
imgNode
.
height
;
imgNode
.
scale
=
Math
.
min
(
scaleX
,
scaleY
);
});
const
sprNode
=
spr
.
node
;
const
sx
=
maxWidth
/
sprNode
.
width
;
const
sy
=
maxHeight
/
sprNode
.
height
;
sprNode
.
scale
=
Math
.
min
(
sx
,
sy
);
sprNode
.
parent
=
imgNode
;
})
// const img = imgNode.addComponent(cc.Sprite);
// var imgUrl = this._imageResList[index].url;
// cc.loader.load(imgUrl, function (err, texture) {
// // Use texture to create sprite frame
// var maxWidth = 160;
// var maxHeight = 160;
// const spriteFrame = new cc.SpriteFrame(texture);
// img.spriteFrame = spriteFrame;
// var scaleX = maxWidth / imgNode.width;
// var scaleY = maxHeight / imgNode.height;
// imgNode.scale = Math.min(scaleX, scaleY);
// });
// audio 加载
const
playAudio
=
imgNode
.
getComponent
(
cc
.
AudioSource
);
...
...
play/assets/tmpGame/script/util.js
View file @
c4026bc3
...
...
@@ -131,4 +131,34 @@ export function btnClickAnima(btn, time=0.15, rate=1.05) {
.
to
(
time
/
2
,
{
scale
:
btn
.
tmpScale
})
.
start
()
})
}
\ No newline at end of file
}
export
function
getSpriteFrimeByUrl
(
url
,
cb
)
{
cc
.
loader
.
load
({
url
},
(
err
,
img
)
=>
{
const
spriteFrame
=
new
cc
.
SpriteFrame
(
img
)
if
(
cb
)
{
cb
(
spriteFrame
);
}
})
}
export
function
getSprNode
(
resName
)
{
const
sf
=
cc
.
find
(
'
Canvas/res/img/
'
+
resName
).
getComponent
(
cc
.
Sprite
).
spriteFrame
;
const
node
=
new
cc
.
Node
();
node
.
addComponent
(
cc
.
Sprite
).
spriteFrame
=
sf
;
return
node
;
}
export
function
getSprNodeByUrl
(
url
,
cb
)
{
const
node
=
new
cc
.
Node
();
const
spr
=
node
.
addComponent
(
cc
.
Sprite
);
getSpriteFrimeByUrl
(
url
,
(
sf
)
=>
{
spr
.
spriteFrame
=
sf
;
if
(
cb
)
{
cb
(
spr
);
}
})
}
play/assets/tmpGame/textures/播放中2.png.meta
View file @
c4026bc3
...
...
@@ -7,8 +7,8 @@
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width":
74
,
"height":
82
,
"width":
55
,
"height":
61
,
"platformSettings": {},
"subMetas": {
"播放中2": {
...
...
play/assets/tmpGame/textures/播放中3.png.meta
View file @
c4026bc3
...
...
@@ -7,8 +7,8 @@
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width":
74
,
"height":
82
,
"width":
55
,
"height":
61
,
"platformSettings": {},
"subMetas": {
"播放中3": {
...
...
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