Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7634509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:11:44+00:00 2026-05-31T07:11:44+00:00

I’m trying to use an xml file for spritesheet data; I have a frame

  • 0

I’m trying to use an xml file for spritesheet data; I have a frame class that either holds a rectangle or another list of frames (it can be a frame itself, or a holder for more frames). The xml holds all rectangles for the frames.
I’ve added the xml to the content project and use Content.load(“xmlname”) to load it.

This all works perfectly fine when using it once. But when I create 2 objects that share the same spritesheet (and thus the same xml data fle) they dissapear when these 2 objects are on the same frame. After a lot of frustration I figured out that the xml file always returns the same object, thus shares frames so it can only draw the frame one place at a time.

Here’s a short part of the xml file:

<?xml version="1.0" encoding="utf-8"?>

<rect>0 0 0 0</rect>

<frames>

  <Item>
    <rect>0 0 0 0</rect>
    <frames>

      <Item>
        <rect>19 27 15 22</rect>
        <frames></frames>
        <label>DOWN</label>
      </Item>

      <Item>
        <rect>2 27 15 23</rect>
        <frames></frames>
        <label>DOWN</label>
      </Item>

      <Item>
        <rect>19 27 15 22</rect>
        <frames></frames>
        <label>DOWN</label>
      </Item>

      <Item>
        <rect>36 27 15 23</rect>
        <frames></frames>
        <label>DOWN</label>
      </Item>

    </frames>
    <label>DOWN</label>
  </Item>

Stripped down version of the class:

    public class Frame
{
    public Rectangle rect; //means this is an image

    private Renderable renderable = null;

    private List<Frame> frames;

    private Texture2D texture;
    private int currentFrame = 0;

example usage:

    Sprite sprite1 = new Sprite();
    sprite1.frame = Content.load<Frame>("xml");
    sprite1.frame.getFrame(0).alpha = 0.5f; 

    Sprite sprite1 = new Sprite();
    sprite2.frame = Content.load<Frame>("xml"); //<--- doesn't return a new object, returns the same object as sprite 1 uses
     //frame  0 in sprite 2 has an alpha of 0.5 aswell, without having modified it

I tried to manually deserialize the xml, but deserializing lists is a nightmare.
Am I doing something wrong here? Seems so strange that it returns the same object

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:11:45+00:00Added an answer on May 31, 2026 at 7:11 am

    This is by design. In most situations you only want to load an asset once, and then reuse it. Loading it multiple times would be a waste of time and memory.

    Ideally any assets you load from disk should be immutable objects, so you should change your design so you don’t need to modify their fields.

    But sometimes that’s not possible. The next best solution would be to implement ICloneable on the class you want to make multiple copies of.

    The harder-to-implement-correctly and kind of ugly alternative would be to inherit from ContentManager and override its methods such that it loads the asset each time, as described in this blog post.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.