我正在构建一个 HTML5/javascript“简单”游戏,但我的画布绘图遇到了一个不寻常的问题。它是不稳定的。
我有一张地图,需要这样绘制:
背景有 2 层:海洋和岛屿。UI 有 6 个或更多按钮/图像。
有时会画成这样:
有时甚至不绘制 UI:
但是在几次错误的绘图(F5)之后,它开始正确地绘制一切。所以,它非常不稳定,我不明白为什么。这是我的这些图纸的代码:
// Background Layers
Game.m_gameUI.drawBG();
// Draw User Interface
Game.m_gameUI.drawUI();
// Draw Score
Game.m_gameUI.drawScore();
drawBG : function () {
// Layer 1
var img1 = new Image();
img1.id = 'map2_bg';
img1.src = GameUI.BKGIMG3_SRC;
GameUI.m_canvasDraw.drawImage( img1, 0,0, GameUI.actualCanvasWidth, GameUI.actualCanvasHeight );
// Layer 2
var img2 = new Image();
img2.id = 'map_bg';
img2.src = GameUI.GAME_MAP_SRC;
GameUI.m_canvasDraw.drawImage( img2, 0,0, GameUI.actualCanvasWidth, GameUI.actualCanvasHeight );
},
drawUI : function () {
GameUI.m_canvasDraw.globalAlpha = 1;
// BagPack
GameUI.drawUiImage( 'mochila' , GameUI.actualCanvasWidth - 59, 110 , 59, 66 );
// Home
GameUI.drawUiImage( 'home' , GameUI.actualCanvasWidth - 102, 0 , 102, 58 );
//GameUI.setUiEvent( 'home' );
// Points
GameUI.drawUiImage( 'bandeira' , 0, 0 , 164, 34 );
// Help
GameUI.drawUiImage( 'ajuda' , 0, GameUI.actualCanvasHeight - 71 , 84, 71 );
// Email
GameUI.drawUiImage( 'email' , GameUI.actualCanvasWidth - 102 - 96, 0 , 131, 58 );
// Volume
GameUI.drawUiImage( 'volume' , GameUI.actualCanvasWidth - 66, GameUI.actualCanvasHeight - 71 , 66, 71 );
},
drawUiImage : function ( image, x, y, width, height ) {
GameUI.m_canvasDraw.restore();
var img = new Image();
var filename_off = image + '_off.png';
var filename_on = image + '_on.png';
img.id = image;
// Assuming you instantiated the image url on class atributes
img.src = GameUI.ui_img_folder + filename_off;
// Add the variable into class
GameUI[image] = image;
// Draw it
GameUI.m_canvasDraw.drawImage( img, x, y, width, height );
GameUI.m_canvasDraw.restore();
},
我是瞎了还是怎么了?还是只是画错了顺序?
任何提示将不胜感激。谢谢,维克多·索托