2012-03-31 23 views
0

私はゲームを作っています。以下は私にc.png(硬貨)の絵を描くはずですが、それは動かないのです。ctx.drawImage not working

リンク次の例があります: http://jonirautiainen.net/html5peli/testi.html

<div id="game"></div><script> 
var canvasWidth = window.innerWidth - 20; 
var canvasHeight = window.innerHeight - 100; 
var game = document.getElementById("game"); 
game.innerHTML = '<canvas id="canvas" width="' + canvasWidth + '"height="' + canvasHeight + '"style="border:solid black 1px"></canvas>'; 

var canvas = document.getElementById('canvas'); 
var ctx = canvas.getContext('2d'); 
var cimg = new Image(); 
//coin 
cimg.src = "c.png"; 
var time = 0; 
var delay = 0; 
var coin = { 
     srcX: 0, 
     srcY: 0, 
     w: 90, 
     h: 89, 
     dw: 40, 
     dw: 40, 
     x: Math.floor(Math.random() * canvasWidth), 
     y: Math.floor(Math.random() * canvasHeight) 
} 
ctx.drawImage(cimg, coin.srcX, coin.srcY, coin.w, coin.h, coin.x, coin.y, coin.dw, coin.dh); 



</script> 

任意のアイデア?それは私に何かエラーを与えません。

ありがとうございました。

答えて

1

あなたは二度ここにdwを入力した:

var coin = { 
     srcX: 0, 
     srcY: 0, 
     w: 90, 
     h: 89, 
     dw: 40, 
     dw: 40, 
     x: Math.floor(Math.random() * canvasWidth), 
     y: Math.floor(Math.random() * canvasHeight) 
}; 

秒1の代わりにdh: 40する必要があります。 =)

+0

OMGあなたは深刻です:) 3時間何が間違っているかを見つけようとしています...ありがとうございます。 –

+0

http://jonirautiainen.net/html5peli/開発中のゲーム –

+0

@JoniJuhaniRautiainen:うまくやった:)私はずっとそれを見続けていたし、[strict mode](https://developer.mozilla.org)/ja/JavaScript/Strict_mode)それが現れました。 – Ryan