Dynamic Object Initiation As3

前端 未结 6 2009
被撕碎了的回忆
被撕碎了的回忆 2021-01-17 04:33

I notice in older version of flash you can create an instance of a dynamic class. I am creating a game that will have many different classes that can be displayed on the sta

6条回答
  •  佛祖请我去吃肉
    2021-01-17 05:02

    Interfaces is good. I am using an array that maps out how the bricks will be put down on the stage

     mapArry =  [
          [[1],[1],[1],[1],[1],[1],[1],[1],[1],[1]], 
          [[1],[1],[1],[1],[1],[1],[1],[1],[1],[1]],
          [[1],[1],[1],[1],[1],[1],[1],[1],[1],[1]],
          [[1],[1],[1],[1],[1],[1],[1],[1],[1],[1]],
          ];
    

    1 specifies brick type Number 1. but what if the next map has brick type 2 or 3

     mapArry =  [
          [[1],[1],[1],[1],[1],[1],[1],[1],[1],[1]], 
          [[1],[1],[1],[1],[1],[1],[1],[1],[1],[1]],
          [[1],[1],[1],[1],[1],[1],[1],[1],[1],[1]],
          [[2],[2],[2],[2],[2],[2],[2],[2],[2],[2]],
          ];
    

    Again, I loop through the array, getting each brick. how would I use interfaces to supply the given brick ?.

    The only answer I could think of is the create a brickManager class. a class that identifies each type of brick and retrieves them. But I am trying to be more efficient. I would like to know if there is a better way.

    Only thing i could think of is to use dynamic initiations. I didnt know that approach went against oop.

    var newVar = new ["brick"+i]();
    

提交回复
热议问题