如何在 XML 中表示图块?

发布于 2024-09-07 11:59:02 字数 641 浏览 10 评论 0 原文

所以,我正在编写一个 AS3 程序来铺瓷砖。我希望用户能够创建自己的由不同矩形表示的楼层示意图。这将是拖放操作。他们将布置原理图(由不同大小的矩形图块组成)并在其上放置颜色/图案。

然后,该示意图将平铺在 3D 平面上,以表示实际地板的外观。

我已经完成了 3D 部件的工作、拖放工作等。我缺少的是楼层原理图的东西。我花了很多时间试图找出最佳解决方案,但我无法完全实现。

以下是地板原理图外观的一些示例(从一大堆可能的组合中选出):

alt text

替代文字

替代文字

alt text

原理图中的不同图块是可放置区域。我的问题:如何用 XML 表示这些原理图?不用担心瓷砖、尺寸等问题。我已经把这些都弄清楚了。我只是不知道如何用 XML 表示图块原理图并使用 AS3 正确绘制它。有什么想法吗?

So, I'm writing an AS3 program that tiles floor tiles. I want the user to be to be able to create their own floor schematic represented by different rectangles. It'll be drag-and-drop. They will lay out their schematic (which is composed of different size rectangular tiles) and drop colors/patterns onto them.

This schematic will then be tiled on a 3D plane to represent what the actual floor would look like.

I've got the 3D part working, drag-and-drop working, etc. What I'm missing is the floor schematic stuff. I've spent a lot of time trying to figure out the best solution, but I can't QUITE get there.

Here are some examples (out of a WHOLE bunch of possible combinations) of how the floor schematics could look:

alt text

alt text

alt text

alt text

The different tiles within the schematic are the droppable regions. My problem: How can represent these schematics in XML? Don't worry about tiling, sizing, etc. I've got that all figured out already. I just literally do not know how I can represent a tile schematic in XML and draw it correctly with AS3. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

岁月静好 2024-09-14 11:59:02

在我看来,你的图块实际上可以归结为网格上的布局。鉴于此,我会让图块的 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> 

上面代表了你的第一个例子(不过我编了颜色)。希望有帮助。

It looks to me like your tiles really boil down to layouts on a grid. Given that, I would have the xml for the tile be comprised of a list of elements, each element would have properties for the row/column of the upper left square of the element, the row span and column span for that element, and the fill for that element. Something like this:

<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> 

The above would represent your first example (I made up the colors though). Hope that helps.

﹏半生如梦愿梦如真 2024-09-14 11:59:02

为了简单起见,您可能需要考虑使用 x、y、宽度、高度值。这就是 flash.geom.Rectangleflash.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" />

For the sake of simplicity, you might want to consider using the x, y, width, height values. That is the format that flash.geom.Rectangle and flash.display.Graphics.drawRect() use.

<tile x="20" y="20" width="400" height="200" pattern="1" />
<tile x="20" y="220" width="100" height="100" pattern="2" />
姐不稀罕 2024-09-14 11:59:02

免责声明:我不是编写 XML 的最佳人选。例如, 可能会很痛苦,因为它使 xsd 模式变得更加复杂 - 即: iftile =不,它不应该有孩子。如果tile = yes,那么它必须有孩子。另请注意,您需要重新处理LightGrey。另请注意,我不知道元素和属性之间的最佳权衡是什么。另请注意,我不喜欢 以及 - 拼写错误的机会。但是,我不知道更好的方法,但想找出可能是什么。另外,也许这种格式太冗长了。另外,我没有包含 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>

Disclaimer: I am not the best person at writing XML. For instance, <Cell x="0" y="1" tile="no"/> can be a pain, for it makes xsd schema more complicated - which is: if tile = no, it should not have children. If tile = yes, then it must have children. Also note that you need to rework <RgbColor>LightGrey</RgbColor>. Also note that I do not know what is the best trade-off between elements and attributes. Also note that I do not like having <Cells> as well as <Cell> - typo opportunity. However, I do not know a better way, but would like to find out what that might be. Also, perhaps this format is too verbose. Also, I did not include an xsd schema, but you can get started with it here: http://www.google.com/search?hl=en&q=xsd+schema+generator&aq=f&aqi=&aql=&oq=&gs_rfai=

Also inspired by another answer, you might want to define pattern colors separately and then refer to them ... can be error-prone.

<?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>
抹茶夏天i‖ 2024-09-14 11:59:02

为什么选择 XML?为什么不直接使用 AMF3 对其进行序列化呢?或者如果您需要人类可读的内容, JSON 应该可以做到。 JSON 具有与 ECMA 脚本完全相同的对象语义,是 ECMA 脚本的子集,而 XML 则不然,这使得使用 XML 变得非常烦人。

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

[
    {"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序列化

问候
后退2dos

why XML? why not just serialize it using AMF3? or if you need something human readable, JSON should do it. JSON has exactly the same object semantics as ECMA-script, being a subset of ECMA-script, while XML doesn't, which makes working with XML quite annoying.

representation of the first schematic as object structure:

[
    {"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

You can use the as3corelib for serialization.

greetz
back2dos

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文