所以我有一個3D遊戲,有一個three.js視角相機在3D空間中移動。現在,當您在此3D空間中選擇了一個項目時,我想要一個按鈕出現在屏幕的左上角以取消選擇該項目。有沒有辦法使用HTML做到這一點?因爲現在我有一個按鈕,但它將遊戲推到了它的下面,而不是作爲html的一部分。我認爲我需要使按鈕的背景透明,並手動將遊戲推到屏幕的頂部。使HTML按鈕重疊到我的遊戲?
<body style="background-color: #222222;">
//Here is the button that I need to be transparent
//because I have no way to test it, I have no idea if that style code I have makes it transparent or not
<input type="image" id="myimage" style="height:200px;width:200px;border:0 none;background-color: transparent;" src="media/undo.png"/>
<script src="src/game.js"></script>
<script src="src/main.js"></script>
//Here is where I load in the game
<script>
$(document).ready(function(){
//All loading stuff
THREE.ImageUtils.crossOrigin = '';
var game = new Main($(document).width() - 10, $(document).height() - 20, "res/games.json");
game.init();
function gameUpdate(){
game.update();
window.requestAnimationFrame(gameUpdate, game.renderer.domElement);
}
gameUpdate();
});
</script>
//Done with game loading script
</body>
這是問題的一個畫面:http://puu.sh/dg4rJ/5a25c817b7.jpg 我需要比賽和按鈕待在一起。無論如何要做到這一點,還是應該在JS中的遊戲中工作?
您是否嘗試過加入的位置是:絕對的呢? – coopersita 2014-12-04 00:49:09
如有必要,更改CSS中的'z-index'。圖像的背景應該是透明的。 – irrelephant 2014-12-04 01:04:03