Files
dvcp_v2_webapp/project/dvui/components/AiSprite.vue

56 lines
1.2 KiB
Vue
Raw Normal View History

2022-06-28 15:37:13 +08:00
<template>
<section class="AiSprite" :ref="ref"/>
</template>
<script>
import * as spritejs from 'spritejs'
export default {
name: "AiSprite",
props: {
width: {default: 400},
height: {default: 300},
2022-06-28 15:48:12 +08:00
is3D: Boolean
2022-06-28 15:37:13 +08:00
},
data() {
return {
ref: ""
}
},
methods: {
init(count = 0) {
const container = this.$refs[this.ref]
if (container) {
2022-06-28 15:48:12 +08:00
let loadTasks = []
2022-06-28 15:37:13 +08:00
let {width, height} = this.$props
2022-06-28 15:48:12 +08:00
if (this.is3D) {
loadTasks.push(this.$injectLib("https://unpkg.com/sprite-extend-3d/dist/sprite-extend-3d.js"))
}
Promise.all(loadTasks).then(() => {
const scene = new spritejs.Scene({container, width, height, ...this.$attrs}),
layer = scene.layer()
/**
* layer 图层
* lib spritejs的依赖库
*/
this.$emit("init", {layer, lib: spritejs})
})
2022-06-28 15:37:13 +08:00
} else if (count == 20) {
console.log(this.$refs)
} else setTimeout(() => this.init(++count), 500)
}
},
created() {
this.ref = "AiSprite_" + new Date().getTime()
},
mounted() {
this.init()
}
}
</script>
<style lang="scss" scoped>
.AiSprite {
}
</style>