課程
/前端開發(fā)
/HTML/CSS
/HTML5小游戲---愛心魚(上)
JavaScript編譯時(shí)Chrome報(bào)告Uncaught?TypeError:?undefined?is?not?a?function錯(cuò)誤,
2016-11-24
源自:HTML5小游戲---愛心魚(上) 2-3
正在回答
我也有這個(gè)錯(cuò)誤 后來發(fā)現(xiàn) 是我的分號用了中文寫
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>tinyHeart</title>
<style type="text/css">
body {
padding-top: 10px;
}
.all_bg{
width: 800px;
height: 600px;
margin: 0px auto;
#allcanvas{?
position: relative;
margin: 0px;
#canvas1{
position: absolute;
bottom: 0;
left: 0;
z-index: 1;
#canvas2{?
z-index: 0;
</style> ??
</head>
<body>
<div class = "all_bg">
<div id="allcanvas">
<canvas id ="canvas1" width ="800" height ="600"></canvas>?
<canvas id ="canvas2" width ="800" height ="600"></canvas>
</div>
<script type="text/javascript" src = "js/main.js"></script>
<script type="text/javascript" src = "js/commonFunctions.js"></script>
<script type="text/javascript" src = "js/background.js"></script>
<script type="text/javascript" src = "js/ane.js">
</script>
</body>
</html>
var aneObj = function()
{
this.x = [];
this.len = [];
aneObj.prototype.num = 50;
aneObj.prototype.init = function()
? for (var i = 0; i< this.num; i++)
? {
? this.x[i] = i * 20 + Math.random()*20;//[0,1)
? this.len[i] = 200+Math.random()*50;
? }
aneObj.prototype.draw = function()
for(var i=0 ;i<this.num; i++)
//beginPath,moveto,LineTo,stroke,strokestyle,LineWidth,LineCap,globleAlpha
ctx2.beginPath();
ctx2.moveto(this.x[i],600);
ctx2.lineTo(this.x[i],600 - this.len[i]);
ctx2.lineWidth = 20;
ctx2.lineCap = "round";
ctx2.strokestyle = "purple";
ctx2.stroke();
var can1;
var can2;
var ctx1;
var ctx2;
var canWidth;
var canHeight;
var lastTime;
var deltaTime;
var bgPic = new Image();
var ane;
document.body.onload = game;/*body 加載完后把game作為所有js腳本的入口*/
function game()
init();//console.log("onload");//輸出普通信息
lastTime = Date.now();
deltaTime = 0;
gameloop();
?
?function init()
?{ ? ? ??
? ? ? ?//獲得canvas context
? ? ? ?can1 = document.getElementById("canvas1");//fishes,dust,UI,circle
? ? ? ?ctx1 = can1.getContext("2d");//獲得2D場景
? ? ? ?can2 = document.getElementById("canvas2");//background,ane,fruits
? ? ? ?ctx2 = can2.getContext("2d");
? ? ? ?bgPic. src = "./src/background.jpg";
? ? ? ?
? ? ? ?canWidth = can1.width;?
? ? ? ?canHeight = can1.height;
? ? ? ?ane = new aneObj();
? ? ? ?ane.init();
?}
function gameloop()
window.requestAnimationFrame(gameloop);//比setInterval,setTimeout(time)更科學(xué)智能計(jì)算?
var now = Date.now();
deltaTime = now - lastTime;
lastTime = now;
drawBackground();
ane.draw();
}?
分別是html,ane,main的
謝謝你哦
貼代碼看看 ?可能是沒有在循環(huán)里面調(diào)用吧
xiaxiaaichixia 提問者
舉報(bào)
學(xué)做HTML5游戲,輕輕松松帶你上手,適合剛?cè)胧钟螒蜷_發(fā)的同學(xué)
1 回答海葵出不來
1 回答??麤]出來
1 回答??怀鰜碓趺崔k
1 回答海葵畫不出
1 回答??嫴怀鰜韲聡聡?/p>
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2017-02-25
我也有這個(gè)錯(cuò)誤 后來發(fā)現(xiàn) 是我的分號用了中文寫
2016-11-25
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>tinyHeart</title>
<style type="text/css">
body {
padding-top: 10px;
}
.all_bg{
width: 800px;
height: 600px;
margin: 0px auto;
}
#allcanvas{?
position: relative;
width: 800px;
height: 600px;
margin: 0px;
}
#canvas1{
position: absolute;
bottom: 0;
left: 0;
z-index: 1;
}
#canvas2{?
position: absolute;
bottom: 0;
left: 0;
z-index: 0;
}
</style> ??
</head>
<body>
<div class = "all_bg">
<div id="allcanvas">
<canvas id ="canvas1" width ="800" height ="600"></canvas>?
<canvas id ="canvas2" width ="800" height ="600"></canvas>
</div>
</div>
<script type="text/javascript" src = "js/main.js"></script>
<script type="text/javascript" src = "js/commonFunctions.js"></script>
<script type="text/javascript" src = "js/background.js"></script>
<script type="text/javascript" src = "js/ane.js">
</script>
</body>
</html>
var aneObj = function()
{
this.x = [];
this.len = [];
}
aneObj.prototype.num = 50;
aneObj.prototype.init = function()
{
? for (var i = 0; i< this.num; i++)
? {
? this.x[i] = i * 20 + Math.random()*20;//[0,1)
? this.len[i] = 200+Math.random()*50;
? }
}
aneObj.prototype.draw = function()
{
for(var i=0 ;i<this.num; i++)
{
//beginPath,moveto,LineTo,stroke,strokestyle,LineWidth,LineCap,globleAlpha
ctx2.beginPath();
ctx2.moveto(this.x[i],600);
ctx2.lineTo(this.x[i],600 - this.len[i]);
ctx2.lineWidth = 20;
ctx2.lineCap = "round";
ctx2.strokestyle = "purple";
ctx2.stroke();
}
}
var can1;
var can2;
var ctx1;
var ctx2;
var canWidth;
var canHeight;
var lastTime;
var deltaTime;
var bgPic = new Image();
var ane;
document.body.onload = game;/*body 加載完后把game作為所有js腳本的入口*/
function game()
{
init();//console.log("onload");//輸出普通信息
lastTime = Date.now();
deltaTime = 0;
gameloop();
}
?
?function init()
?{ ? ? ??
? ? ? ?//獲得canvas context
? ? ? ?can1 = document.getElementById("canvas1");//fishes,dust,UI,circle
? ? ? ?ctx1 = can1.getContext("2d");//獲得2D場景
? ? ? ?can2 = document.getElementById("canvas2");//background,ane,fruits
? ? ? ?ctx2 = can2.getContext("2d");
? ? ? ?bgPic. src = "./src/background.jpg";
? ? ? ?
? ? ? ?canWidth = can1.width;?
? ? ? ?canHeight = can1.height;
? ? ? ?ane = new aneObj();
? ? ? ?ane.init();
?}
function gameloop()
{
window.requestAnimationFrame(gameloop);//比setInterval,setTimeout(time)更科學(xué)智能計(jì)算?
var now = Date.now();
deltaTime = now - lastTime;
lastTime = now;
drawBackground();
ane.draw();
}?
分別是html,ane,main的
謝謝你哦
2016-11-25
貼代碼看看 ?可能是沒有在循環(huán)里面調(diào)用吧