代码之家  ›  专栏  ›  技术社区  ›  lewiguez

如何用XML表示tile?

  •  1
  • lewiguez  · 技术社区  · 15 年前

    所以,我在写一个AS3程序,用瓷砖铺地板。我希望用户能够创建自己的楼层示意图表示不同的矩形。它将是拖放式的。他们将布置他们的示意图(由不同尺寸的矩形瓷砖组成),并在其上添加颜色/图案。

    然后,这个示意图将平铺在一个三维平面上,以表示实际楼层的外观。

    我已经有了三维部分的工作,拖放工作,等等。我缺少的是地板示意图的东西。我花了很多时间想找出最好的解决办法,但我还没找到。

    alt text

    alt text

    alt text

    alt text

    示意图中的不同分幅是可拖放区域。我的问题是: 如何用XML表示这些示意图

    4 回复  |  直到 15 年前
        1
  •  3
  •   Wade Mueller    15 年前

    在我看来,你的瓷砖真的可以归结为网格上的布局。既然如此,我会让tile的xml由元素列表组成,每个元素都有元素左上角正方形的行/列的属性,该元素的行跨度和列跨度,以及该元素的填充。像这样:

    <Tile>
        <Cell row="0" col="0" rowSpan="1" colSpan="4" fill="#a0a0a0"/>
        <Cell row="1" col="0" rowSpan="1" colSpan="4" fill="#b0b0b0"/>
        <Cell row="0" col="4" rowSpan="2" colSpan="2" fill="#c0c0c0"/>
        <Cell row="2" col="2" rowSpan="1" colSpan="4" fill="#a0a0a0"/>
        <Cell row="3" col="2" rowSpan="1" colSpan="4" fill="#b0b0b0"/>
        <Cell row="2" col="0" rowSpan="2" colSpan="2" fill="#c0c0c0"/>
    </Tile> 
    

        2
  •  0
  •   timrwood    15 年前

    为了简单起见,您可能需要考虑使用x、y、width和height值。这就是 flash.geom.Rectangle flash.display.Graphics.drawRect()

    <tile x="20" y="20" width="400" height="200" pattern="1" />
    <tile x="20" y="220" width="100" height="100" pattern="2" />
    
        3
  •  0
  •   Hamish Grubijan    15 年前

    免责声明:我不是编写XML的最佳人选。例如, <Cell x="0" y="1" tile="no"/> <RgbColor>LightGrey</RgbColor> . 还要注意的是,我不知道元素和属性之间的最佳权衡是什么。还要注意的是,我不喜欢 <Cells> 以及 <Cell> -打字机会。不过,我不知道更好的办法,但想知道那可能是什么。而且,也许这种格式太冗长了。另外,我没有包含xsd模式,但您可以从这里开始: http://www.google.com/search?hl=en&q=xsd+schema+generator&aq=f&aqi=&aql=&oq=&gs_rfai=

    同样受到另一个答案的启发,您可能希望分别定义图案颜色,然后引用它们。。。可能容易出错。

    <?xml version="1.0" encoding="utf-8"?>
    <TileSchematics name="Blah" comment="This starts to describe second one.">
      <BoundingBox>
        <Width>8</Width>
        <Height>3</Height>
        <StackHorizontally>yes</StackHorizontally>
        <StackVertically>no</StackVertically>
      </BoundingBox>
      <Cells>
        <Cell x="0" y="0" tile="yes">
          <RgbColor>LightGrey</RgbColor>
          <Border>
            <Right>yes</Right>
            <Left>yes</Left>
            <Top>yes</Top>
            <Bottom>yes</Bottom>
          </Border>
        </Cell>
        ...
        <Cell x="0" y="1" tile="no"/>
        ...
      </Cells>
    </TileSchematics>
    
        4
  •  -1
  •   back2dos    15 年前

    为什么选择XML?为什么不直接用AMF3序列化呢?或者如果你需要可读的东西, JSON

    将第一个示意图表示为对象结构:

    [
        {"x":0, "y":0, "width":100, "height":25, "pattern":0 },
        {"x":0, "y":25, "width":100, "height":25, "pattern":1 },
        {"x":100, "y":0, "width": 50, "height":50, "pattern":2 },
        {"x":50, "y":50, "width":100, "height":25, "pattern":0 },
        {"x":50, "y":75, "width":100, "height":25, "pattern":1 },   
        {"x":0, "y":50, "width": 50, "height":50, "pattern":2 }
    ]
    //this is both valid JSON and ActionScript, although in ActionScript, you would
    //typically use identifiers instead of strings for property names
    

    你可以用 as3corelib 对于 serialization .

    尔兹
    背景2度