fruit的问题,怎么这一节问题这么少

来源:2-4 果实绘制(静态果实)

greenhandc

2015-12-21 15:49

var fruitObject=function(){
this.alive=[];//boolean
this.orange=new Image();
this.blue=new Image();
this.x=[];
this.y=[];

}
fruitObject.prototype.num=30;
fruitObject.prototype.init=function() {
	for(var i=0;i<this.num;i++){
		this.alive[i]=true;
		this.x[i]=0;
		this.y[i]=0;
		this.born(i);
	}
	this.orange.src="./src/fruit.png";
	this.blue.src="./src/blue.png";
}
fruitObject.prototype.draw=function(){
	for(var i=0;i<this.name;i++){
		ctx2.drawImage(this.orange,this.x[i],this.y[i]);

	}

}

fruitObject.prototype.born=function(i){
	var aneid=Math.floor(Math.random()*ane.num);
	this.x[i]=ane.x[aneid];
	this.y[i]=canHeight-ane.length[aneid];
 

}


var can1;
var can2;

var ctx1;
var ctx2;

var canWidth;
var canHeight;

var lastTime;
var deltaTime;

var ane;
var fruit;

var bgPic=new Image();
document.body.onload=game;
function game()
{
	init();
	lastTime=Date.now();
	deltaTime=0;
	gameloop();
	}
function init(){
	//获得canves context
	can1=document.getElementById("canvas1");//fishes,dust,ui
	ctx1=can1.getContext('2d');
	can2=document.getElementById("canvas2");
	ctx2=can2.getContext('2d');

	bgPic.src="./src/background.jpg";

	canWidth=can1.width;
    canHeight=can1.height;

    ane=new aneObject();
    ane.init();

    fruit=new fruitObject();
    fruit.init();
}
function gameloop(){
	requestAnimFrame(gameloop);
	var now=Date.now();
	deltaTime=now-lastTime;
	lastTime=now;

	drawbackground();
	ane.draw();
	fruit.draw();

	
}

<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
	<title>爱心鱼</title>
	<style type="text/css">
	body{
		padding-top: 10px;
	}
	.all_bg{
		width: 800px;
		height: 600px;
		margin: 0px auto;
	}
	.allCanves{
		position: relative;;
		width: 800px;
		height: 600px;
		margin: 0px;
	}
	#canves1{
		position: absolute;
		bottom: 0;
		left: 0;
		z-index: 1;

	}
	#canves2{
		position: absolute;
		bottom: 0;
		left: 0;
		z-index: 0;
	}

	</style>


</head>
<body>
<div class="all_bg">
	<div id="allCanves">
		<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>
<script type="text/javascript" src="js/fruit.js"></script>


</body>

</html>

代码没有报错了 但是就是不显示fruit怎么办

写回答 关注

1回答

  • 0羽落0
    2016-01-07 10:22:41
    已采纳
    fruitObject.prototype.draw=function(){
        for(var i=0;i<this.name;i++){     //应该是i<this.num
            ctx2.drawImage(this.orange,this.x[i],this.y[i]);
     
        }
     
    }

    greenh...

    早就解决了,我也忘记是什么问题了。。

    2016-01-07 21:32:01

    共 1 条回复 >

HTML5小游戏---爱心鱼(上)

学做HTML5游戏,轻轻松松带你上手,适合刚入手游戏开发的同学

92350 学习 · 551 问题

查看课程

相似问题