Commit c4026bc3 authored by Li MingZhe's avatar Li MingZhe

fix: 加载图片方式修改

parent 0db50b23
...@@ -183,7 +183,7 @@ ...@@ -183,7 +183,7 @@
"array": [ "array": [
0, 0,
0, 0,
623.5382907247958, 259.8076211353316,
0, 0,
0, 0,
0, 0,
......
import { playAudioByUrl } from "./util"; import { getSprNodeByUrl, playAudioByUrl } from "./util";
cc.Class({ cc.Class({
extends: cc.Component, extends: cc.Component,
...@@ -210,8 +210,14 @@ cc.Class({ ...@@ -210,8 +210,14 @@ cc.Class({
playAudio.play(); 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 cardNode = cc.instantiate(cc.find('Canvas/Card'));
const imgNode = cardNode.getChildByName('img'); const imgNode = cardNode.getChildByName('img');
const bgbackNode = cardNode.getChildByName('bgback'); const bgbackNode = cardNode.getChildByName('bgback');
// label 加载 // label 加载
...@@ -219,18 +225,29 @@ cc.Class({ ...@@ -219,18 +225,29 @@ cc.Class({
var label = labelNode.getComponent(cc.Label); var label = labelNode.getComponent(cc.Label);
label.string = this._textResList[index].text; label.string = this._textResList[index].text;
// img 加载 // img 加载
const img = imgNode.addComponent(cc.Sprite);
var imgUrl = this._imageResList[index].url; getSprNodeByUrl(picArr[index].left.pic_url, (spr) => {
cc.loader.load(imgUrl, function (err, texture) {
// Use texture to create sprite frame
var maxWidth = 160; var maxWidth = 160;
var maxHeight = 160; var maxHeight = 160;
const spriteFrame = new cc.SpriteFrame(texture); const sprNode = spr.node;
img.spriteFrame = spriteFrame; const sx = maxWidth / sprNode.width;
var scaleX = maxWidth / imgNode.width; const sy = maxHeight / sprNode.height;
var scaleY = maxHeight / imgNode.height; sprNode.scale = Math.min(sx, sy);
imgNode.scale = Math.min(scaleX, scaleY); 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 加载 // audio 加载
const playAudio = imgNode.getComponent(cc.AudioSource); const playAudio = imgNode.getComponent(cc.AudioSource);
......
...@@ -132,3 +132,33 @@ export function btnClickAnima(btn, time=0.15, rate=1.05) { ...@@ -132,3 +132,33 @@ export function btnClickAnima(btn, time=0.15, rate=1.05) {
.start() .start()
}) })
} }
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);
}
})
}
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
"premultiplyAlpha": false, "premultiplyAlpha": false,
"genMipmaps": false, "genMipmaps": false,
"packable": true, "packable": true,
"width": 74, "width": 55,
"height": 82, "height": 61,
"platformSettings": {}, "platformSettings": {},
"subMetas": { "subMetas": {
"播放中2": { "播放中2": {
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
"premultiplyAlpha": false, "premultiplyAlpha": false,
"genMipmaps": false, "genMipmaps": false,
"packable": true, "packable": true,
"width": 74, "width": 55,
"height": 82, "height": 61,
"platformSettings": {}, "platformSettings": {},
"subMetas": { "subMetas": {
"播放中3": { "播放中3": {
......
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