gpt4 book ai didi

javascript - Canvas fillRect 不工作

转载 作者:行者123 更新时间:2023-11-28 05:30:59 29 4
gpt4 key购买 nike

我不知道哪里出了问题。这是在一个全新的网站上制作的,因此没有缓存问题,javascript 控制台也没有返回错误。 Canvas 横跨整个页面,并被正确标记。这是脚本:

<script type = "text/javascript">
var game = document.getElementById("game");
var context = game.getContext("2d");
var gamePieces = []
function gamePiece(width, height, color, x, y){
this.width = width;
this.height = height;
this.x = x;
this.y = y;
update = function(){
context.fillStyle = color;
context.fillRect(this.x, this.y, this.height, this.width);
}
gamePieces[gamePieces.length] = this
}
var p1 = gamePiece(50, 50, "blue", 0, 0);
function update(){
context.clearRect(0, 0, game.width, game.height);
for(var i = 0; i < gamePieces.length; i++){
gamePieces[i].update();
}
}
</script>

最佳答案

没关系。我想到了。一切运行顺利,我只需要添加另一个 context.fillstyle 和 context.fillRect() 语句。小蜘蛛。

关于javascript - Canvas fillRect 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38515793/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com