Commit c4026bc3 authored by Li MingZhe's avatar Li MingZhe

fix: 加载图片方式修改

parent 0db50b23
......@@ -183,7 +183,7 @@
"array": [
0,
0,
623.5382907247958,
259.8076211353316,
0,
0,
0,
......
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);
......
......@@ -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);
}
})
}
......@@ -7,8 +7,8 @@
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 74,
"height": 82,
"width": 55,
"height": 61,
"platformSettings": {},
"subMetas": {
"播放中2": {
......
......@@ -7,8 +7,8 @@
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 74,
"height": 82,
"width": 55,
"height": 61,
"platformSettings": {},
"subMetas": {
"播放中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