common-game
Advanced tools
Comparing version 0.0.15 to 0.0.16
{ | ||
"name": "common-game", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "common-game.js", |
@@ -40,2 +40,4 @@ import * as PIXI from "@tbminiapp/pixi-miniprogram-engine"; | ||
}); | ||
this.PIXI = PIXI; | ||
} | ||
@@ -98,2 +100,3 @@ // 全局点击事件 | ||
this[`${name}Container`] = new PIXI.Container(); | ||
this[`${name}Container`].name = name; | ||
this.stage.addChild(this[`${name}Container`]); | ||
@@ -208,2 +211,3 @@ } | ||
sprite.texture = this.frame(img, x || 0, y || 0); | ||
sprite.imgObj = img; | ||
} | ||
@@ -210,0 +214,0 @@ // 生成精灵 |
46
utils.js
@@ -73,2 +73,48 @@ export default { | ||
}, | ||
getRandomImg: function (images, opsFilter) { | ||
let filter = Object.assign({ not: {}, is: {} }, opsFilter); | ||
let isArr = Object.keys(filter.is); | ||
let notArr = Object.keys(filter.not); | ||
images.forEach(item => { item.del = false; }) | ||
images.forEach(item => { | ||
isArr.forEach(isName => { | ||
if (item[isName] != filter.is[isName]) { | ||
item.del = true; | ||
} | ||
}) | ||
notArr.forEach(isName => { | ||
if (item[isName] == filter.not[isName]) { | ||
item.del = true; | ||
} | ||
}) | ||
}) | ||
let arr = []; | ||
images.forEach(item => { | ||
if (!item.del) { | ||
arr.push(item); | ||
} | ||
}) | ||
let totalProbability = 0; | ||
arr.forEach(item => { | ||
item.maxProbability = totalProbability + (item.probability || 1); | ||
totalProbability = item.maxProbability; | ||
}); | ||
arr.forEach(item => { | ||
item.totalProbability = totalProbability; | ||
}); | ||
let imgObj; | ||
let idx = 0; | ||
if (arr.length > 1) { | ||
idx = this.random({ max: totalProbability }); | ||
} | ||
arr.forEach(item => { | ||
if (!imgObj && idx < item.maxProbability) { | ||
imgObj = item; | ||
} | ||
}); | ||
return imgObj; | ||
} | ||
} |
43817
1256