123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- class TickAnime {
- constructor(imgLen, x, y, w, h, ctx,name,zIndex,imgName,imgBaseUrl) {
- this.imgLen = imgLen
- this.x = x
- this.y = y
- this.w = w
- this.h = h
- this.ctx = ctx
- this.name = name
- this.zIndex = zIndex
- this.imgName = imgName
- this.currentIndex = 0
- this.imgBaseUrl = imgBaseUrl
- this.loadingState = false
- this.clickState = false
- this.imgList = []
- this.getDrawImgUrl()
- }
- async getDrawImgUrl() {
- for (let i = 1; i < this.imgLen + 1; i++) {
- let imgHostUrl = await this.getImgInfo(i)
- this.imgList.push(imgHostUrl)
- }
- this.initDraw()
- }
- initDraw(){
- for(let i=0;i<this.imgList.length;i++){
- this.ctx.drawImage(this.imgList[i], this.x, this.y, this.w, this.h)
- }
- setTimeout(()=>{
- this.loadingState = true
- },1000)
- }
- getImgInfo(index) {
- return new Promise((resolev, reject) => {
- uni.getImageInfo({
- src: `${this.imgBaseUrl}/${this.imgName} (${index}).png`,
- success: (res) => {
- resolev(res.path)
- },
- fail(err) {
- reject(err)
- }
- })
- })
- }
- draw() {
- if (this.loadingState) {
- this.ctx.drawImage(this.imgList[this.currentIndex], this.x, this.y, this.w, this.h)
- }
- }
- update() {
- if (!this.clickState) {
- if (this.currentIndex < this.imgLen - 1) {
- this.currentIndex++
- } else {
- this.currentIndex = 1
- }
- }
- }
- }
- export default TickAnime
|