Commit f0f9841e authored by zjz1994's avatar zjz1994

代码暂存

parent 38829cf5
This diff is collapsed.
...@@ -48,7 +48,7 @@ function launchWithCustomModule(customModule) { ...@@ -48,7 +48,7 @@ function launchWithCustomModule(customModule) {
setTimeout(()=>{ setTimeout(()=>{
engine.globalEvent.dispatchEvent('pictures-initgame', { engine.globalEvent.dispatchEvent('pictures-initgame', {
gameUrls:[ gameUrls:[
"https://yun.duiba.com.cn/aurora/assets/5906e5670cb7061dfc77306087e9a79d4bbcb250.jpg", "https://yun.duiba.com.cn/aurora/assets/5906e5670cb7061dfc77306087e9a79d4bbcb2501.jpg",
"https://yun.duiba.com.cn/aurora/assets/61fd0754d7924305fd2851be86a480d71d2c2981.jpg", "https://yun.duiba.com.cn/aurora/assets/61fd0754d7924305fd2851be86a480d71d2c2981.jpg",
"https://yun.duiba.com.cn/aurora/assets/6b70d7ec626f35f21347bf5bc3e61bedc44167be.jpg" "https://yun.duiba.com.cn/aurora/assets/6b70d7ec626f35f21347bf5bc3e61bedc44167be.jpg"
], ],
......
This diff is collapsed.
This diff is collapsed.
...@@ -61,6 +61,12 @@ ...@@ -61,6 +61,12 @@
"url": "//yun.duiba.com.cn/aurora/assets/1c384d986504d5aabfffeb5125dc67e73ce1b539.png", "url": "//yun.duiba.com.cn/aurora/assets/1c384d986504d5aabfffeb5125dc67e73ce1b539.png",
"uuid": "kuang4", "uuid": "kuang4",
"ext": ".png" "ext": ".png"
},
{
"name":"testimg",
"url":"//yun.duiba.com.cn/aurora/assets/2628186c60c3b80013ae3178ff21a73ffbe71d43.jpg",
"uuid":"morentu",
"ext":".jpg"
} }
], ],
"events": { "events": {
......
...@@ -6,6 +6,7 @@ import { props } from "../props"; ...@@ -6,6 +6,7 @@ import { props } from "../props";
import qietu from "./qietu"; import qietu from "./qietu";
import { getTexture, loadImageByUrl,getTextureByName } from "./utils"; import { getTexture, loadImageByUrl,getTextureByName } from "./utils";
import ObjectPool = engine.ObjectPool; import ObjectPool = engine.ObjectPool;
import Tool from "./Tool";
export default class GameView extends engine.Container { export default class GameView extends engine.Container {
rows:number; rows:number;
...@@ -41,7 +42,7 @@ export default class GameView extends engine.Container { ...@@ -41,7 +42,7 @@ export default class GameView extends engine.Container {
gameUrls:Array<string> = []; gameUrls:Array<string> = [];
gameTimes:Array<number> = []; gameTimes:Array<number> = [];
onegamePics:Array<engine.Texture> = []; onegamePics:Array<any> = [];
movesteps:number = 0; movesteps:number = 0;
startime:number = 0; startime:number = 0;
constructor() { constructor() {
...@@ -67,27 +68,46 @@ export default class GameView extends engine.Container { ...@@ -67,27 +68,46 @@ export default class GameView extends engine.Container {
this.linecont.addChild(this.lineShape); this.linecont.addChild(this.lineShape);
console.log("拼图初始化完毕--------------"); // console.log("拼图初始化完毕--------------");
engine.globalEvent.dispatchEvent("pictures-time-initcomp",{}); engine.globalEvent.dispatchEvent("pictures-time-initcomp",{});
this.removeEventListener(engine.Event.ADDED_TO_STAGE,this.initScene,this); this.removeEventListener(engine.Event.ADDED_TO_STAGE,this.initScene,this);
// let testsuc = new engine.Label();
// testsuc.text = "直接成功";
// testsuc.size = 66;
// testsuc.fillColor = "red";
// this.addChild(testsuc);
// testsuc.y = 500;
// testsuc.width = 300;
// testsuc.height = 200;
// testsuc.addEventListener(engine.MouseEvent.CLICK,this.zhijieSuc,this);
} }
// //测试直接成功
// zhijieSuc(){
// this.gameover(1);
// }
async initgame(){ async initgame(){
console.log("initgame---------"); // console.log("initgame---------");
this.gameUrls = props.gameUrls; this.gameUrls = props.gameUrls||["https://yun.duiba.com.cn/db_games/activity/game/1596074071/resource/assets/ptimgs/28.jpg", "https://yun.duiba.com.cn/db_games/activity/game/1596074071/resource/assets/ptimgs/29.jpg", "https://yun.duiba.com.cn/db_games/activity/game/1596074071/resource/assets/ptimgs/30.jpg"];
this.gameTimes = props.gameTimes; this.gameTimes = props.gameTimes||[30,60,60];
this.onegamePics = new Array(); this.onegamePics = new Array();
for(let l=0;l<this.gameUrls.length;l++){ for(let l=0;l<this.gameUrls.length;l++){
let lurl = this.gameUrls[l]; let lurl = this.gameUrls[l];
let lt = await loadImageByUrl(lurl) as engine.Texture; let lt = await loadImageByUrl(lurl);
// console.log(lt);
if(lt){
lt = lt as engine.Texture
}else{
lt = null;
}
this.onegamePics.push(lt); this.onegamePics.push(lt);
if(this.onegamePics.length==1){//第一张图加载完毕,自动填充 if(this.onegamePics.length==1){//第一张图加载完毕,自动填充
this.startfirst(); this.startfirst();
} }
} }
this.removeSelectImg(); this.removeSelectImg();
} }
removeSelectImg(){ removeSelectImg(){
if(this.selectimg3){ if(this.selectimg3){
...@@ -97,8 +117,22 @@ export default class GameView extends engine.Container { ...@@ -97,8 +117,22 @@ export default class GameView extends engine.Container {
this.blockcont.removeChild(this.selectimg4); this.blockcont.removeChild(this.selectimg4);
} }
} }
removeDiPics(){
let nume = this.dicont.children.length;
for(let i=nume-1;i>=0;i--){
let ichild = this.dicont.getChildAt(i) as engine.Container;
if(ichild){
ichild.removeEventListener(engine.MouseEvent.MOUSE_DOWN,
this.touchPic,this);
this.dicont.removeChild(ichild);
Tool.repushToPool(ichild);
}
}
}
async startfirst(){ async startfirst(){
this.dicont.removeChildren(); // this.dicont.removeChildren();
this.removeDiPics();
this.movesteps = 0; this.movesteps = 0;
this.startime = Date.now(); this.startime = Date.now();
this.removeSelectImg(); this.removeSelectImg();
...@@ -113,7 +147,7 @@ export default class GameView extends engine.Container { ...@@ -113,7 +147,7 @@ export default class GameView extends engine.Container {
engine.globalEvent.dispatchEvent("pictures-time-passtime",{ engine.globalEvent.dispatchEvent("pictures-time-passtime",{
passtime:this.passtime passtime:this.passtime
}); });
console.log("start-----------------",actidx); // console.log("start-----------------",actidx);
this.rows = 3; this.rows = 3;
this.cols = 3; this.cols = 3;
...@@ -134,8 +168,9 @@ export default class GameView extends engine.Container { ...@@ -134,8 +168,9 @@ export default class GameView extends engine.Container {
let type1 = 1; let type1 = 1;
if(!tex){ if(!tex){
tex = this.gameUrls[actidx]; tex = this.gameUrls[actidx];
type1 = 2; type1 = 3;
} }
// type1 = 3;
let result = await qietu(tex,type1,this.rows,this.cols,this.dicont); let result = await qietu(tex,type1,this.rows,this.cols,this.dicont);
let res = result.res; let res = result.res;
if(res){ if(res){
...@@ -190,7 +225,8 @@ export default class GameView extends engine.Container { ...@@ -190,7 +225,8 @@ export default class GameView extends engine.Container {
} }
async start() { async start() {
this.dicont.removeChildren(); // this.dicont.removeChildren();
this.removeDiPics();
this.movesteps = 0; this.movesteps = 0;
this.startime = Date.now(); this.startime = Date.now();
this.removeSelectImg(); this.removeSelectImg();
...@@ -225,7 +261,7 @@ export default class GameView extends engine.Container { ...@@ -225,7 +261,7 @@ export default class GameView extends engine.Container {
let type1 = 1; let type1 = 1;
if(!tex){ if(!tex){
tex = this.gameUrls[actidx]; tex = this.gameUrls[actidx];
type1 = 2; type1 = 3;
} }
let result = await qietu(tex,type1,this.rows,this.cols,this.dicont); let result = await qietu(tex,type1,this.rows,this.cols,this.dicont);
let res = result.res; let res = result.res;
...@@ -325,12 +361,12 @@ export default class GameView extends engine.Container { ...@@ -325,12 +361,12 @@ export default class GameView extends engine.Container {
} }
pause(){ pause(){
this.ingame = false; this.ingame = false;
console.error("拼图暂停"); // console.error("拼图暂停");
} }
resume(){ resume(){
this.lastframetime = Date.now(); this.lastframetime = Date.now();
this.ingame = true; this.ingame = true;
console.error("拼图继续"); // console.error("拼图继续");
} }
...@@ -424,7 +460,7 @@ export default class GameView extends engine.Container { ...@@ -424,7 +460,7 @@ export default class GameView extends engine.Container {
} }
let isuc = this.checkSuccess(); let isuc = this.checkSuccess();
if(isuc){ if(isuc){
console.error("成功过关"); // console.error("成功过关");
this.gameover(1); this.gameover(1);
} }
} }
......
export default class Tool{
static picPool:Array<engine.Container> = new Array();
static getOnePic(){
if(this.picPool.length>0){
return this.picPool.shift();
}else{
let ipic = new engine.Container();
let isprite = new engine.ScrollView();
isprite.name = "iscrollv";
let nsp = new engine.Sprite();
nsp.name = "isprite";
nsp.texture
isprite.addChild(nsp);
ipic.addChild(isprite);
isprite.mouseEnabled = false;
nsp.mouseEnabled = false;
return ipic;
}
}
static repushToPool(icont:engine.Container){
this.picPool.push(icont);
}
}
\ No newline at end of file
import { props } from "../props"; import { props } from "../props";
import { loadImageByUrl } from "./utils"; import { loadImageByUrl, getTextureByName ,getTexture} from "./utils";
import qietu from "./qietu"; import qietu from "./qietu";
import Tool from "./Tool";
const urls = []; const urls = [];
const picMap = {}; const picMap = {};
const posMap = {}; const posMap = {};
...@@ -9,69 +10,77 @@ export default async(url:any,type1:number, rows:number, cols:number,parent:engin ...@@ -9,69 +10,77 @@ export default async(url:any,type1:number, rows:number, cols:number,parent:engin
let t:engine.Texture; let t:engine.Texture;
if(type1==1){ if(type1==1){
t = url; t = url;
}else{ }else if(type1==2){
t = await loadImageByUrl(url) as engine.Texture; let t1 = await loadImageByUrl(url);// as engine.Texture;
if(t1){
t = t1 as engine.Texture;
}
}else if(type1==3){
t = await getTextureByName("testimg") as engine.Texture;
}
if(!t){
return qietu("testimg",3,rows,cols,parent);
} }
let setimgwid = 612; let setimgwid = 612;
let mwid1 = setimgwid/rows; let mwid1 = setimgwid/rows;
let mhei1 = setimgwid/cols; let mhei1 = setimgwid/cols;
let mwid = t.width; // let mwid = t.width;
let mhei = t.height; // let mhei = t.height;
if(mwid<10||mhei<10){ // if(mwid<10||mhei<10){
await new Promise(res=>{ // await new Promise(res=>{
setTimeout(function(){ // setTimeout(function(){
res(); // res();
},200); // },200);
}) // })
return qietu(t,1,rows,cols,parent); // return qietu(t,1,rows,cols,parent);
} // }
if(mwid>mhei){ // if(mwid>mhei){
if(mhei<setimgwid){ // if(mhei<setimgwid){
mwid = mwid*setimgwid/mhei; // mwid = mwid*setimgwid/mhei;
mhei = setimgwid; // mhei = setimgwid;
} // }
}else{ // }else{
if(mwid<setimgwid){ // if(mwid<setimgwid){
mhei = mhei*setimgwid/mwid; // mhei = mhei*setimgwid/mwid;
mwid = setimgwid; // mwid = setimgwid;
} // }
} // }
let picarr = {}; let picarr = {};
let picnames = []; let picnames = [];
let chax; let chax;
let chay; let chay;
let startlix; let startlix = 0;
let addlix; let addlix = 1/rows;
let startliy; let startliy = 0;
let addliy; let addliy = 1/cols;
let twid1; let twid1 = setimgwid;
let thei1; let thei1 = setimgwid;
if(mwid>mhei){ // if(mwid>mhei){
chax = (mwid-mhei)/2; // chax = (mwid-mhei)/2;
startlix = chax/mwid; // startlix = chax/mwid;
addlix = (mhei/cols)/mwid; // addlix = (mhei/cols)/mwid;
startliy = 0; // startliy = 0;
addliy = 1/rows; // addliy = 1/rows;
twid1 = mwid*setimgwid/mhei; // twid1 = mwid*setimgwid/mhei;
thei1 = setimgwid; // thei1 = setimgwid;
}else{ // }else{
startlix = 0; // startlix = 0;
addlix = 1/cols; // addlix = 1/cols;
chay = (mhei-mwid)/2; // chay = (mhei-mwid)/2;
startliy = chay/mhei; // startliy = chay/mhei;
addliy = (mwid/rows)/mhei; // addliy = (mwid/rows)/mhei;
thei1 = mhei*setimgwid/mwid; // thei1 = mhei*setimgwid/mwid;
twid1 = setimgwid; // twid1 = setimgwid;
} // }
// console.log("切图准备",startlix,addlix,startliy,addliy,mwid,mhei); // console.log("切图准备",startlix,addlix,startliy,addliy,mwid,mhei);
// let txt1 = new engine.Label(); // let txt1 = new engine.Label();
...@@ -87,36 +96,46 @@ export default async(url:any,type1:number, rows:number, cols:number,parent:engin ...@@ -87,36 +96,46 @@ export default async(url:any,type1:number, rows:number, cols:number,parent:engin
let starty = startliy+addliy*c; let starty = startliy+addliy*c;
let endy = starty+addliy; let endy = starty+addliy;
let uvs = new Float32Array([ // let uvs = new Float32Array([
starty, // starty,
startx, // startx,
endy, // endy,
startx, // startx,
endy, // endy,
endx, // endx,
starty, // starty,
endx // endx
]) // ])
//方案1
// let isprite = new engine.Sprite(t); // let isprite = new engine.Sprite(t);
// isprite.uvs = uvs; // isprite.uvs = uvs;
let nsprite = new engine.Container();
let isprite = new engine.ScrollView(); //方案2
let nsp = new engine.Sprite(t); let nsprite = Tool.getOnePic();
isprite.addChild(nsp); let isprite = nsprite.getChildByName("iscrollv");
let nsp = isprite.getChildByName("isprite");
nsp.texture = t;
nsp.width = twid1; nsp.width = twid1;
nsp.height = thei1; nsp.height = thei1;
isprite.mouseEnabled = false; // let nsprite = new engine.Container();
isprite.mouseChildren = false;
// let isprite = new engine.ScrollView();
// let nsp = new engine.Sprite(t);
// isprite.addChild(nsp);
// nsp.width = twid1;
// nsp.height = thei1;
// isprite.mouseEnabled = false;
// isprite.mouseChildren = false;
nsp.x = -starty*twid1; nsp.x = -starty*twid1;
nsp.y = -startx*thei1; nsp.y = -startx*thei1;
isprite.width = mwid1; isprite.width = mwid1;
isprite.height = mhei1; isprite.height = mhei1;
nsprite.addChild(isprite); // nsprite.addChild(isprite);
nsprite.width = mwid1; nsprite.width = mwid1;
nsprite.height = mhei1; nsprite.height = mhei1;
...@@ -134,8 +153,16 @@ export default async(url:any,type1:number, rows:number, cols:number,parent:engin ...@@ -134,8 +153,16 @@ export default async(url:any,type1:number, rows:number, cols:number,parent:engin
picnames:picnames picnames:picnames
}; };
}catch(e){ }catch(e){
return { //获取那图失败
res:false
}; // return {
// res:false
// };
await new Promise(res=>{
setTimeout(function(){
res();
},200);
})
return qietu("testimg",3,rows,cols,parent);
} }
}; };
...@@ -20,13 +20,23 @@ export function createSvga(name, anchorName?) { ...@@ -20,13 +20,23 @@ export function createSvga(name, anchorName?) {
} }
export async function loadImageByUrl(url){ export async function loadImageByUrl(url){
console.log('loadImageByUrl----------:',url); // console.log('loadImageByUrl----------:',url);
return new Promise((resolve) => { try{
if (engine.TextureCache[url]) { // console.log("尝试加载44");
resolve(engine.TextureCache[url]) return new Promise((resolve) => {
} else { let t1 = setTimeout(()=>{
var t = engine.Texture.from(url); return resolve(null);
t.addEventListener("loaded", () => { resolve(t) }) },2000);
}
}) if (engine.TextureCache[url]) {
clearTimeout(t1);
resolve(engine.TextureCache[url])
} else {
var t = engine.Texture.from(url);
t.addEventListener("loaded", () => { clearTimeout(t1);resolve(t) });
}
})
}catch(e){
return null;
}
} }
\ No newline at end of file
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