Skip to main content
deleted 135 characters in body; edited title
Source Link
user1430
user1430

Why Texture2D is not serializable and In an XNA game object, what should I use to serialize while savingrepresent a game objecttexture for serialization?

While trying to save to a file a list of objects, needed to run my game, I noticed that Texture2D is not serializableTexture2D is not serializable. Why? What was the purpose?

The object I want to serialize looks like this:

[Serializable] public class GameObject { private Vector2 position_ = Vector2.Zero; private float rotation_ = 0.0f; private Vector2 scale_ = Vector2.One; private float depth_ = 0.0f; private Texture2D texture_; private bool is_passable_ = true; private GameObject( Vector2 starting_position, string filepath, ContentManager content) { this.position_ = starting_position; this.texture_ = Content.Load<Texture2D>(filepath); } //Properties //Update/Draw } 

So, the second question: while saving/loading in a game or in a level editor, both composed of a lot of this "GameObject" and derivates, what is correct to serialize? It seems thatwhat should I serialized since Texture2D isn't made to be serialized.used that way?

Why Texture2D is not serializable and what to serialize while saving a game object

While trying to save to a file a list of objects, needed to run my game, I noticed that Texture2D is not serializable. Why? What was the purpose?

The object I want to serialize:

[Serializable] public class GameObject { private Vector2 position_ = Vector2.Zero; private float rotation_ = 0.0f; private Vector2 scale_ = Vector2.One; private float depth_ = 0.0f; private Texture2D texture_; private bool is_passable_ = true; private GameObject( Vector2 starting_position, string filepath, ContentManager content) { this.position_ = starting_position; this.texture_ = Content.Load<Texture2D>(filepath); } //Properties //Update/Draw } 

So, the second question: while saving/loading in a game or in a level editor, both composed of a lot of this "GameObject" and derivates, what is correct to serialize? It seems that Texture2D isn't made to be serialized.

In an XNA game object, what should I use to represent a texture for serialization?

While trying to save to a file a list of objects needed to run my game, I noticed that Texture2D is not serializable. Why? What was the purpose?

The object I want to serialize looks like this:

[Serializable] public class GameObject { private Vector2 position_ = Vector2.Zero; private float rotation_ = 0.0f; private Vector2 scale_ = Vector2.One; private float depth_ = 0.0f; private Texture2D texture_; private bool is_passable_ = true; private GameObject( Vector2 starting_position, string filepath, ContentManager content) { this.position_ = starting_position; this.texture_ = Content.Load<Texture2D>(filepath); } //Properties //Update/Draw } 

So, what should I serialized since Texture2D isn't made to be used that way?

Source Link
user31021
user31021

Why Texture2D is not serializable and what to serialize while saving a game object

While trying to save to a file a list of objects, needed to run my game, I noticed that Texture2D is not serializable. Why? What was the purpose?

The object I want to serialize:

[Serializable] public class GameObject { private Vector2 position_ = Vector2.Zero; private float rotation_ = 0.0f; private Vector2 scale_ = Vector2.One; private float depth_ = 0.0f; private Texture2D texture_; private bool is_passable_ = true; private GameObject( Vector2 starting_position, string filepath, ContentManager content) { this.position_ = starting_position; this.texture_ = Content.Load<Texture2D>(filepath); } //Properties //Update/Draw } 

So, the second question: while saving/loading in a game or in a level editor, both composed of a lot of this "GameObject" and derivates, what is correct to serialize? It seems that Texture2D isn't made to be serialized.