Dealing with infinite/huge worlds in actionscript 2

前端 未结 1 1700
北海茫月
北海茫月 2021-01-28 02:44

How are infinite/huge procedural generated worlds achieved with minimal lag in actionscript 2? In a game like Terraria or Minecraft for example. What would the best way to go ab

相关标签:
1条回答
  • 2021-01-28 03:35

    If your game is predominantly tile-based, that is, the world has same-size blocks as its base unit, it is most practical to store your world in an array. Instead of placing your blocks by hand, an array like the following can store keys that correspond to specific block types:

    "grass" "grass" "grass" "water" "water"
    "grass" "water" "water" "water" "water"
    "grass" "grass" "woods" "woods" "woods"
    "grass" "grass" "woods" "woods" "woods"
    "grass" "grass" "woods" "woods" "woods"
    "grass" "grass" "grass" "woods" "woods"
    

    Imagine that in the above example, the player can only see nine blocks at a time, i.e.

    "grass" "woods" "woods"
    "grass" "woods" "woods"
    "grass" "woods" "woods"
    

    This is the player at position 2,2 on the world array.

    Whenever the player moves, its position with respect to the array is incremented or decremented respectively. So moving upward to would decrease the position value to 2,1 and load the blocks that are located farther north.

    From the array, you would retrieve that the blocks immediately above are "water" "water" "water", and would load three water movieclips. Just in case, this answer shows how to load movieclips dynamically.

    Also, a quick way to move the player with respect to the world, instead of moving the entire world with respect to the player, is to change the values _root._x and _root._y.

    In the end, if the game is too graphics intensive, have you considered traversing the world on a 'room-based' system, where the player's position is not fixed, and every fifty blocks or so goes to a new screen of blocks? That would easily cut down on the strain.

    AS2 is absolutely great for working with simple games that you want to get up and running quickly, although the nature of AS3 may be more suited for loading many objects dynamically.

    0 讨论(0)
提交回复
热议问题