|
@@ -761,33 +761,33 @@ const draw = () => {
|
|
|
if (!ctx) return;
|
|
|
|
|
|
// 绘制背景
|
|
|
-if (gameState.res['/static/images/basketball/background.png']) {
|
|
|
- const img = gameState.res['/static/images/basketball/background.png'];
|
|
|
- const canvasWidth = gameState.canvas.width;
|
|
|
- const canvasHeight = gameState.canvas.height;
|
|
|
-
|
|
|
- // 计算图片与画布的比例
|
|
|
- const imgRatio = img.width / img.height;
|
|
|
- const canvasRatio = canvasWidth / canvasHeight;
|
|
|
-
|
|
|
- let drawWidth, drawHeight, drawX = 0, drawY = 0;
|
|
|
-
|
|
|
- // 根据比例计算绘制尺寸
|
|
|
- if (canvasRatio > imgRatio) {
|
|
|
- // 画布更宽,按宽度缩放,高度可能超出
|
|
|
- drawWidth = canvasWidth;
|
|
|
- drawHeight = canvasWidth / imgRatio;
|
|
|
- drawY = (canvasHeight - drawHeight) / 2; // 垂直居中
|
|
|
- } else {
|
|
|
- // 画布更高,按高度缩放,宽度可能超出
|
|
|
- drawHeight = canvasHeight;
|
|
|
- drawWidth = canvasHeight * imgRatio;
|
|
|
- drawX = (canvasWidth - drawWidth) / 2; // 水平居中
|
|
|
+ if (gameState.res['/static/images/basketball/background.png']) {
|
|
|
+ const img = gameState.res['/static/images/basketball/background.png'];
|
|
|
+ const canvasWidth = gameState.canvas.width;
|
|
|
+ const canvasHeight = gameState.canvas.height;
|
|
|
+
|
|
|
+ // 计算图片与画布的比例
|
|
|
+ const imgRatio = img.width / img.height;
|
|
|
+ const canvasRatio = canvasWidth / canvasHeight;
|
|
|
+
|
|
|
+ let drawWidth, drawHeight, drawX = 0, drawY = 0;
|
|
|
+
|
|
|
+ // 根据比例计算绘制尺寸
|
|
|
+ if (canvasRatio > imgRatio) {
|
|
|
+ // 画布更宽,按宽度缩放,高度可能超出
|
|
|
+ drawWidth = canvasWidth;
|
|
|
+ drawHeight = canvasWidth / imgRatio;
|
|
|
+ drawY = (canvasHeight - drawHeight) / 2; // 垂直居中
|
|
|
+ } else {
|
|
|
+ // 画布更高,按高度缩放,宽度可能超出
|
|
|
+ drawHeight = canvasHeight;
|
|
|
+ drawWidth = canvasHeight * imgRatio;
|
|
|
+ drawX = (canvasWidth - drawWidth) / 2; // 水平居中
|
|
|
+ }
|
|
|
+
|
|
|
+ // 绘制图片(可能裁剪边缘)
|
|
|
+ ctx.drawImage(img, drawX, drawY, drawWidth, drawHeight);
|
|
|
}
|
|
|
-
|
|
|
- // 绘制图片(可能裁剪边缘)
|
|
|
- ctx.drawImage(img, drawX, drawY, drawWidth, drawHeight);
|
|
|
-}
|
|
|
// 绘制菜单状态
|
|
|
if (gameState.state === 'menu') {
|
|
|
if (gameState.res['/static/images/basketball/title.png']) {
|
|
@@ -833,8 +833,10 @@ if (gameState.res['/static/images/basketball/background.png']) {
|
|
|
}
|
|
|
|
|
|
// 绘制分数和时间
|
|
|
- drawText(ctx, 'Score: ' + gameState.score, 45, 70, 50);
|
|
|
- drawText(ctx, 'Time: ' + gameState.time, 435, 70, 50);
|
|
|
+ // 更靠左的得分
|
|
|
+ drawText(ctx, '得分: ' + gameState.score, 100, 70, 50);
|
|
|
+ // 更靠右的时间
|
|
|
+ drawText(ctx, '时间: ' + gameState.time, clientObj.value.width - 115, 70, 50);
|
|
|
|
|
|
// 绘制弹出文字
|
|
|
gameState.texts.forEach(text => text.draw(ctx, { drawText }));
|