0
有人可以告訴我我做錯了什麼。我試圖給我的舞臺添加文字,但舞臺沒有顯示任何文字,也沒有給出任何錯誤。我做錯什麼了嗎。我添加了addChild的txt,所以它應該出現?爲什麼它沒有顯示任何內容,這不是因爲顏色,因爲我改變了文本的顏色。Txt不會出現在舞臺上
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>game</title>
<script type="text/javascript" src="game.js"></script>
<script type="text/javascript" src="js/easel.js"></script>
</head>
<body onload="init();">
<canvas id=canvas width="960" height="580"></canvas>
</body>
</html>
的javascript:
var canvas;
var stage;
var score;
var bitmap;
var bmpList;
var txt;
var play;
function init() {
canvas = document.getElementById("canvas");
stage = new Stage(canvas);
score = 0;
var image = new Image();
image.src = "imgs/stone.png";
image.onload = maakTegenstander;
}
function maakTegenstander(event){
var image = event.target;
var container = new Container();
stage.addChild(container);
var l = 5;
bmpList=[]; // dit is een array
for(var i=0; i<l; i++){
bitmap = new Bitmap(image);
container.addChild(bitmap);
bitmap.name="stone"+i;
verwijderTegenstander(bitmap);
bitmap.regX = bitmap.image.width/2|0;
bitmap.regY = bitmap.image.height/2|0;
bitmap.mouseEnabled = true;
bmpList.push(bitmap);
}
txt = new Text ("Score: 0", "24px Arial", "#333");
txt.textBaseline="top";
txt.x = 400;
txt.y = 20;
stage.addChild(txt);
play=true;
Ticker.addListener(window);
}
function verwijderTegenstander(stone){
stone.y = canvas.height - 700;
stone.x = canvas.width* Math.random() + 30;
stone.speed = (Math.random()*5)+2;
}
function tick(){
if(play == true){
var l=bmpList.length;
}
if (play == true){
var l = bmpList.length;
for(var i=0; i<l; i++){
var bmp = bmpList[i];
if (bmp.y < 650){
bmp.y += bmp.speed;
}else{
//gameOver();
console.log("game over");
}
}
}
txt.text = "Punten: "+score;
stage.update();
}
Heey thx!這是ik現在得到的錯誤:Uncaught ReferenceError:createjs未定義 – user3356007
您是否使用最新的easelJS文件?你是否從createjs網站下載它? – kihu
你正在做與我完全一樣的我爲什麼會得到錯誤,並且是你的工作。 – user3356007