使用DrawImage函数在Android上加载图片 - JavaScript HTML5 Android PhoneGap

时间:2013-07-25 03:27:03

标签: javascript android html html5 cordova

我目前正在使用PhoneGap制作游戏,并尝试通过Adobe PhoneGap Build部署游戏。然而,当我在我的Android手机上打开应用程序时,它只显示空白屏幕,而在我的Ripple Emulator上,它完美地显示了所有元素(图像,音频,加速度计,触摸事件)。应用程序的第一个屏幕应该是欢迎图像(从img / * .jpg导入)和一些触摸事件(用于按下按钮验证)。

这是我在index.html中的代码

    var hello=new Image();
    var state = "start";

    function draw(){
                switch(state)
                {
                    case 'start' :
                        drawStart();
                        break();
                        ...
                }
                        requestAnimationFrame(draw);
    }...

函数drawStart()代码......

 function drawStart(){
                alert("drawStart called"); //just a test
                var canvas=document.getElementById('canvas');
                var ctx = canvas.getContext('2d');
                ctx.font="50px Georgia"; //just a test
                var text1width = ctx.measureText("Labyrinth").width; //just a test
                ctx.fillText("Labyrinth",(canvas.width/2)-(text1width/2) ,canvas.height/2 - 100); //just a test
                hello.src="img/Hello.jpg";
                    ctx.drawImage(hello,0,0);


 };

和身体......

<body>
        <script>
        $(window).on('load',function(){
            draw();
        });
        </script>

        <canvas id="canvas" height="800" width="480">
        </canvas>

</body>

我将一个警报和上下文绘制功能放入我的drawStart函数中,它们甚至没有出现在我的Android手机上。怎么了?我应该怎么做才能解决这个问题?

0 个答案:

没有答案