开发者

Using GDataXML to get a CGPoint from an xml?

开发者 https://www.devze.com 2023-02-19 11:47 出处:网络
I currently have an xml with the following code: <Level> <!--Loads the animals for the Level-->

I currently have an xml with the following code:

<Level>
    <!--Loads the animals for the Level-->
    <Animal>
        <Texture>panda.png</Texture>
        <PositionX>100</PositionX>
        <PositionY>50</PositionY>
        <Type>Panda</Type>
    </Animal>
    <Animal>
        <Texture>tiger.png</Texture>
        <PositionX>200</PositionX>
        <PositionY>150</PositionY>
        <Type>Tiger</Type>
    </Animal>
    <Animal>
        <Texture>monkey.png</Texture>
        <PositionX>300</PositionX>
        <PositionY>250</PositionY>
        <Type>Monkey</Type>
    </Animal>
</Level>

What I want is to get rid of positionX and positionY and replace it with a CGPoint variable. This will make it much easier for other items that I will add later down the line that will contain multiple positions.

I've searched the internet and not been able to find any documentation for GDataXML.

To get my strings and ints I'm using .stringValue and .intValue on my GDataXMLElement.

My question is, is it possible for开发者_开发问答 GDataXML to get a CGPoint value from an xml file or am I going to have to do it as separate ints like I currently have it?


Did you miss How to Read and Write XML Data with GDataXML?

As for CGPoint, I think you could encode it however you like. However, since a single point is made up of two separate values, it makes sense to encode those separately, perhaps inside another tag, like this:

<Point x:30 y:100 />
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号