我在这段时间的学习中学到了:
页面的跳转如何实现(如下所示)
/******全局变量********/
var background_position = 0;//定义一个变量,赋值为0;
//进入界面
function Game() {
/*********清空内容区域 *********/
var game = document.getElementById("game");
var len =game.children.length;
for(var i=0;i<len;i++){
game.removeChild(game.children[0]); //从第一个开始,每次都删除一个子节点
}
/*******创建新的子节点********/
var background = document.createElement("div");//创建一个新的div块
background.setAttribute("id","background"); //设置background属性
background.setAttribute("class","background");
game.appendChild(background);//把background节点插入到game里面去
}
2.对于对象如何实现某些效果(如下所示的爆炸效果)
function Boom(dom){
this.element = document.createElement("div"); //创建一个div块
this.element.setAttribute("class","boom");
this.step = 8; //步速
dom.appendChild(this.element);
/* 对对象进行定位 */
this.setLocation = function(x,y){
this.element.style.left = x + "px";
this.element.style.top = y + "px";
}
/* 爆炸效果 */
this.display = function (x ,y){
this.element.style.left = x+"px";
this.element.style.top = y+"px";
var a = this;
var b = setInterval(function(){
if(a.step > 0){
a.element.style.backgroundPosition = (a.step * 136)+"px 0px";
a.step = a.step - 1;
}else{
a.element.remove();
window.clearInterval(b);
}
},100);
}
}
我在这里还有些是是而非的:
对函数的调用:当一个函数调用到另一个事件里时,还觉得可以理解,但函数有好几个的时候就有点晕乎乎的了。
对于碰撞检测,以前遇见的时候完全没有思路,现在有点想法了,但还是没理解透彻!