使用两张图片的javascript动画

时间:2018-12-21 11:32:45

标签: javascript

我正在用Javascript编写动画并陷入困境。这个想法是,切换两张钻石图片,以便用户看到闪耀的钻石。这是我的代码:

import IMovingObject from '../interface/IMovingObject'
import AssetLoader from '../utils/AssetLoader'

export default class Diamond extends IMovingObject {
    constructor (game, x, y){
        super (game, x, y)
        this.currentAnimationState = 0
        const spriteWidth = 32
        this.animationSprites = [
            { x: 0 * spriteWidth, y: 0 * spriteWidth }
        ]
        this.FrameCount = 0
        this.fps = 30
    } 

    handleCollisionWith(obj, direction, impact) {
        this.game.post('collected', this)
        this.emit('remove', this)

        return true
    }

    draw() {
        this.game.engine.drawImage(
            this.game.assets.diamond1,
            256,
            256,
            0,
            0,
            this.x,
            this.y,
            this.width
        ) // Diamond

    }
    update(){
        this.currentAnimationState =
            (this.currentAnimationState % this.FrameCount === 0)    
    } 

}
export const isDiamond = obj => obj instanceof Diamond

有人知道我应该对他的代码进行哪些更改才能使其正常工作吗?

0 个答案:

没有答案