Flash区块游戏之卷屏代码

  • 来源: 中国IT实验室 作者: xuqingzhong   2008-06-10/10:25

  • 以下是代码片段:
    //增加卷屏事件  
    function strollMap(dirx) {   
        var mc = this.target._parent;   
        if (mc._x<=0) {   
          var t = mc._x-dirx*this.speed;   
          if (t>0) {   
            mc._x = 0;   
          } else if (t<this.target.mapminx) {   
            mc._x = this.target.mapminx;   
          } else {   
            mc._x -= dirx*this.speed;   
            var t = Math.abs(Math.floor((this.target._parent._x)/Tile.width));   
            if (dirx == 1) {   
              this.dispatchEvent({type:"left", value:t});   
            } else if (dirx == -1) {   
              this.dispatchEvent({type:"right", value:t});   
            }   
          }   
        }   
      }   
    在Game类中   
    _char.addEventListener("left", Delegate.create(this, moveleft));   
        _char.addEventListener("right", Delegate.create(this, moveright));   
    private function moveleft(obj) {   
        var t = obj.value-1;   
        if (t != 0) {   
          var row = t-1;   
          if (row>=0 && (row+endx+1)<_mapData.width) {   
            this.removeRow(row);   
            this.addRow(row+endx+1);   
          }   
        }   
      }   
      private function moveright(obj) {   
        var t = obj.value-1;   
        if (t>=0) {   
          var row = t;   
          if (row>=0 && (row+endx)<_mapData.width) {   
            this.addRow(row);   
            this.removeRow(row+endx+1);   
          }   
        }   
      }   
      //绘制指定列   
      private function addRow(row:Number) {   
        var w = _mapData.width;   
        var h = _mapData.height;   
        var tileW = Tile.width;   
        var tileH = Tile.height;   
        for (var i = 0; i<h; i++) {   
          var name = "t_"+i+"_"+row;   
          var mc = _target.wholemap.attachMovie("tile", name, i*w+row);   
          //根据参数来创建区块   
          mc.instance = new Tile(_mapData.getData(_index)[i][row]);   
          mc.instance.target = mc;   
          mc._x = row*tileW;   
          mc._y = i*tileH;    #p#分页标题#e#
          mc._width = tileW;   
          mc._height = tileH;   
          mc.gotoAndStop(mc.instance.name.frame);   
        }   
      }   
      private function removeRow(row:Number) {   
        var h = _mapData.height;   
        for (var i = 0; i<h; i++) {   
          var name = "t_"+i+"_"+row;   
          _target.wholemap[name].removeMovieClip();   
        }   
      } 

    评论 {{userinfo.comments}}

    {{money}}

    {{question.question}}

    A {{question.A}}
    B {{question.B}}
    C {{question.C}}
    D {{question.D}}
    提交

    驱动号 更多