I want to display an image on the entire screen when the user starts my application because I get a black screen for 2 seconds after my launch screen(launchscreen.storyboard) disappears and until Draw(GameTime gameTime) is executed. The image needs to be displayed until I execute LogoView.RemoveFromSuperview(); and the image needs to be above the images that will get drawn later in void Draw(GameTime gameTime).
Is it possible to use the image from Assets.xcassets-->Image? Will iOS automatically chose the appropriate image size for the current device from Assets.xcassets-->Image?
I found the following answer on stackoverflow but I don't know what "View" is.
I get an error message in Program.cs if I use "View":
Error CS0103: The name 'View' does not exist in the current context
How can I display an image when my application launches and remove it later at a certain point in Game1.cs?
Program.cs:
using System;
using Foundation;
using UIKit;
namespace MyProject
{
[Register("AppDelegate")]
class Program : UIApplicationDelegate
{
private static Game1 game;
private UIImageView LogoImage;
public override void FinishedLaunching(UIApplication app)
{
global::Xamarin.Forms.Forms.Init();
LogoImage = new UIImageView(UIImage.FromFile("Launchscreenlogo.png"));
LogoImage.Tag = 1234;
LogoImage.Frame = View.Frame;
View.AddSubview(LogoImage);
View.BringSubviewToFront(LogoImage);
RunGame();
}
private void G_RemoveLogo(object sender, System.EventArgs e)
{
//remove image
var LogoView = View.ViewWithTag(1234);
if (null != LogoView)
LogoView.RemoveFromSuperview();
}
}
}
Game1.cs:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
namespace MyProject
{
public class Game1 : Game
{
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
public event EventHandler RemoveLogo;
public Game1()
{
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
RemoveLogo?.Invoke(this, new EventArgs());
}
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
base.Draw(gameTime);
}
}
}
View
belongs to Controller, we can get a current View
easily in a ViewController,in AppDelegate
try to use Window.RootViewController.View
instead.
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
LoadApplication(new App());
LogoImage = new UIImageView(UIImage.FromFile("Launchscreenlogo.png"));
LogoImage.Frame = UIScreen.MainScreen.Bounds;
Window.RootViewController.View.AddSubview(LogoImage);
Window.RootViewController.View.BringSubviewToFront(LogoImage);
return base.FinishedLaunching(app, options);
}
public void G_RemoveLogo()
{
//remove image
LogoImage.RemoveFromSuperview();
}
And call the following method to remove the image in Game class.
(UIApplication.SharedApplication.Delegate as AppDelegate).G_RemoveLogo();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.