1
\$\begingroup\$

I have XML sheet that I use in my game. In my unity(C#) game, a game's monster can spawn at predetermined position or random position.

<monster delay="0.2" isRed = "true" position ="random"/>
<monster delay="0.3" isRed = "true" position ="10 20"/>

Right now I read value of position and if it is "random" then I assign random position for the monster.

If it is not "random" then I parse the value, separate them by a space bar then use the two numbers I obtain from the "position" as position of my monster.

I get this gut feeling what I am doing is probably really ugly and inefficient that there is probably better way to do this, but I am not sure.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

It's hard to avoid "ugly and inefficient" when serializing data as XML, but space- or comma- separated strings for coordinate data is okay. Alternatively, you can use two attributes or make position a child element, but I'm not sure these are better than what you already have.

<monster delay="0.3" isRed="true" position-x="10" position-y="20" />

<monster delay="0.3" isRed="true">
   <position x="10" y="20" />
</monster>
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .