ctx.drawImage not working
ctx.drawImage not working
我正在制作一个游戏。下面应该给我画一张c.png(硬币)的照片,但它不起作用。
以下链接中有一个示例: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>
有什么想法吗?它没有给我任何错误。
谢谢。
您已经在此处键入了两次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)
};
第二个应该是dh: 40
。=)
相关文章:
- $rootScope not working
- jQuery document.ready not working
- Javascript getElementsByTagName not working?
- JQuery.val( ) not working
- Tomcat websocket is not working
- Javascript JSON.parse not working
- NodeJS Multer is not working
- Regex not working
- Ember run.debounce not working
- AngularJs 1 not working
- document.getElementById.style.backgroundImage not working
- Rxjs5, distinct() is not working
- createOscillator noteOn not working
- Javascript - .getHours() not working
- Javascript setTimeout not working | onkeydown
- MongoDB $pull not working
- Express router.use not working
- JSONP not working
- window.opener not working in chrome & IE
- Backbone + RequireJS: Collection.each() is not working