Hi there,
i have a problem with SaveAsPng, which works on Android, Windows Phone, Windows but not on iOS. As soon as I call it, update and draw will still be called but the screen doesn´t refresh anymore.
I wrote a testproject to show the error. All it does is to change the color of the screen and as soon as you hit the screen (or click the mouse on the emulator) it writes the png-file and doesn´t refresh the screen anymore. What´s interesting is that the file is written correctly:
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Random rand;
Texture2D mSpritePNGTest;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
graphics.IsFullScreen = true;
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
rand = new Random();
base.Initialize();
mSpritePNGTest = new Texture2D(GraphicsDevice, 10, 10, false, SurfaceFormat.Color);
mSpritePNGTest.SetData(new[] { Color.White });
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
//TODO: Use Content to load your game content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// For Mobile devices, this logic will close the Game when the Back button is pressed.
// Exit() is obsolete on iOS
TouchCollection touches = TouchPanel.GetState();
foreach (TouchLocation location in touches)
{
if (location.State== TouchLocationState.Pressed) writeTextureAsync();
}
// TODO: Add your update logic here
base.Update(gameTime);
}
async void writeTextureAsync()
{
IFolder rootFolder = FileSystem.Current.LocalStorage;
await rootFolder.CreateFileAsync("test.png", CreationCollisionOption.ReplaceExisting);
IFile file = await rootFolder.GetFileAsync("test.png");
using (Stream stream = await file.OpenAsync(PCLStorage.FileAccess.ReadAndWrite))
{
mSpritePNGTest.SaveAsPng(stream, mSpritePNGTest.Width, mSpritePNGTest.Height);
stream.Dispose();
}
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
if (rand.Next(2) <1) graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
else graphics.GraphicsDevice.Clear(Color.Red);
//TODO: Add your drawing code here
base.Draw(gameTime);
}
}
Does anybody know if that´s a bug in Monogame?
Thank you,
Harry