Note that there are some explanatory texts on larger screens.

plurals
  1. POWP7 tombstoning, saving sprite into Current state not working
    primarykey
    data
    text
    <p>I am working on a WP7 game. I am using Game state managment (http://create.msdn.com/en-US/education/catalog/sample/game_state_management , but I think its not important ) I have problem with saving data into Microsoft.Phone.Shell.PhoneApplicationService.Current.State</p> <p>if I put there sprite in this method</p> <pre><code> public override void Deactivate() { #if WINDOWS_PHONE Microsoft.Phone.Shell.PhoneApplicationService.Current.State["Score"] = Score; Microsoft.Phone.Shell.PhoneApplicationService.Current.State["cloudSprite"] = cloudSprite; #endif base.Deactivate(); } </code></pre> <p>there is nothing in </p> <pre><code> Microsoft.Phone.Shell.PhoneApplicationService.Current.State </code></pre> <p>in activate method. However if I remove cloudSprite and put there only Score which is int it works fine. I dont know whats wrong maybe it cant handle more complex objects. I tried also float doubel, it all works. But if I put there something more complex it doesnt work. What do you think ?</p> <p><b>EDIT</p> <p></b> This is my sprite class. I dont know how to make it serializable. I have added there [DataContractAttribute()] and [DataMember] but its not working</p> <pre><code> using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; using System.Runtime.Serialization; using System.IO; namespace GameStateManagementSample.GameObjects { [DataContractAttribute()] public class Sprite { [DataMember] public Vector2 Position; [DataMember] public Vector2 Size; [DataMember] public Texture2D Texture; [DataMember] public Rectangle Rect { get { return new Rectangle((int)Position.X, (int)Position.Y, (int)Size.X, (int)Size.Y); } } public Sprite(Vector2 position) { Position = position; } public Sprite(Vector2 position, Vector2 size) { Position = position; Size = size; } public Sprite(Vector2 position, Texture2D texture) { Position = position; Texture = texture; Size = new Vector2(Texture.Width, Texture.Height); } public void LoadContent(string assetName, ContentManager content) { Texture = content.Load&lt;Texture2D&gt;(assetName); if (Size == Vector2.Zero) Size = new Vector2(Texture.Width, Texture.Height); } public virtual void Draw(SpriteBatch spriteBatch) { //spriteBatch.Draw(Texture, Rect, Color.White); spriteBatch.Draw(Texture, Position, Color.White); } public virtual void Draw(SpriteBatch spriteBatch, Rectangle TexturePositionInSpriteSheet, Color color) { spriteBatch.Draw(Texture, Position, TexturePositionInSpriteSheet, color); } public bool Intersects(Vector2 point) { if (point.X &gt;= Position.X &amp;&amp; point.Y &gt;= Position.Y &amp;&amp; point.X &lt;= Position.X + Size.X &amp;&amp; point.Y &lt;= Position.Y + Size.Y) return true; else return false; } public bool Intersects(Rectangle rect) { return Rect.Intersects(rect); } public static void Serialize(Stream streamObject, object objForSerialization) { if (objForSerialization == null || streamObject == null) return; DataContractSerializer ser = new DataContractSerializer(objForSerialization.GetType()); ser.WriteObject(streamObject, objForSerialization); } public static object Deserialize(Stream streamObject, Type serializedObjectType) { if (serializedObjectType == null || streamObject == null) return null; DataContractSerializer ser = new DataContractSerializer(serializedObjectType); return ser.ReadObject(streamObject); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload