js学习回顾

本文介绍了游戏界面设计中页面跳转的实现方法,并详细展示了如何通过JavaScript创建爆炸效果。同时,作者分享了自己在学习过程中遇到的问题,包括函数调用的理解及碰撞检测的实现。

我在这段时间的学习中学到了:

  1. 页面的跳转如何实现(如下所示)

/******全局变量********/
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);
    }
}

    

我在这里还有些是是而非的:

  1. 对函数的调用:当一个函数调用到另一个事件里时,还觉得可以理解,但函数有好几个的时候就有点晕乎乎的了。

  2. 对于碰撞检测,以前遇见的时候完全没有思路,现在有点想法了,但还是没理解透彻!



转载于:https://my.oschina.net/xiuhong/blog/204474

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值