图像不会绘制,但另一个图像会绘制。

时间:2015-04-23 14:59:28

标签: javascript html5 html5-canvas

我有一个画布可以绘制一个图像,但不会绘制同一文件类型的另一个图像。这是我的代码。

var context = document.getElementById('canv').getContext("2d");
        var vx = 0;
        var W = canv.width;
        var H = canv.height;

        var canvback = new Image();         
        canvback.src = "canvback.png";

        var vx = 0;
        var canvroad = new Image();
        canvroad.src = "canvroad.png";

        var car = new Image();
        car.src = "mooncrash.png";

        (function renderGame() {
            window.requestAnimationFrame(renderGame);

            context.clearRect(0, 0, W, H);


            context.drawImage(canvback, 0, 0);              
            context.drawImage(canvroad, vx, 465);               
            context.drawImage(canvroad, canvroad.width-Math.abs(vx), 465);


            if (Math.abs(vx) > canvroad.width) {
            vx = 0;
            }

            vx -= 2;
            context.drawImage(car, 500, 300);
        }());

但是当我将mooncrash.png更改为car.png时,它不会绘制。有什么想法吗?

0 个答案:

没有答案