function sprite(options) { let that = {}, frameIndex = 0, tickCount = 0, ticksPerFrame = options.ticksPerFrame || 0, numberOfFrames = options.numberOfFrames || 1, isLastFrame = false; that.videofenbianlv = options.videofenbianlv || 1080/1080; that.context = options.context; that.width = options.width; that.height = options.height; that.drawWidth = options.drawWidth; that.drawHeight = options.drawHeight; that.x = 0; that.y = 0; that.image = options.image; that.workVideo = options.workVideo && options.workVideo[0]; that.scaleRatio = options.scale; that.setup = function () { isLastFrame = false; frameIndex = 0; if (that.workVideo) { that.workVideo.addEventListener("ended", function () { isLastFrame = true; that.workVideo.src = ''; }); } }; that.update = function () { // tickCount += 1; // if (tickCount > ticksPerFrame) { // tickCount = 0; // if (frameIndex < numberOfFrames - 1) { // frameIndex += 1; // isLastFrame = false; // } else { // //frameIndex = 0; // isLastFrame = true; // } // } }; that.render = function () { // that.context.drawImage( // that.image, // frameIndex * that.width / numberOfFrames, // 0, // that.width / numberOfFrames, // that.height, // that.x, // that.y, // that.drawWidth, // that.drawHeight); // console.log(that.workVideo); if (that.workVideo) { if (that.workVideo.paused && that.workVideo.src) { that.workVideo.play(); } that.context.drawImage(that.workVideo, 0, 0, that.drawHeight * that.videofenbianlv, that.drawHeight); } }; that.isAnimStop = function () { return isLastFrame; }; that.setPosition = function (x, y) { that.x = x; that.y = y; }; that.getPosition = function () { return { x: that.x, y: that.y }; }; that.getSize = function () { return { width: that.width, height: that.height }; }; return that; }