I just tried to create a new UWP App referencing: MonoGame.Framework.WindowsUniversal 3.6.0.1625, and Targeting Windows 10 Creators Update (10.0; Build 15063).
I think I did everything right to "bootstrap" a : Game from the SwapChainPanel:
I put <SwapChainPanel x:Name="swapChainPanel" /> in my Page
I put this in codebehind:
public sealed partial class MainPage : Page
{
readonly Game1 _game;
public MainPage()
{
this.InitializeComponent();
// Create the game.
var launchArguments = string.Empty;
_game = MonoGame.Framework.XamlGame<Game1>.Create(launchArguments, Window.Current.CoreWindow, swapChainPanel);
_game.Run();
}
}
And my Game1 : Game is just the same as Monogame templates.
When I start the application, there are no exceptions and the whole window hangs on the "UWP SplashScreen" (when it shows you the icon of your app) and nothing happens. My Draw method just clears the screen with red, just to see it working, but it doesn't.
Am I missing something?
I attached a very simple project to show that.
Solved, the problem was calling: _game.Run();.
By reading the source code on Github, I saw that the method:
static public T Create(string launchParameters, CoreWindow window, SwapChainPanel swapChainPanel)
already called Run:
// Start running the game.
game.Run(GameRunBehavior.Asynchronous);
By removing my call to the Run method, everything worked.
Related
I'm heading to code a Login System for a game with my own costumization , I'm talking about buttons , image of the background and the login system itself .
Since I don't know how Login system personalization works I will ask here .
The Background of the Login Systems or the back page is a simple image that is resizeble with any resolution of the computer/options the user chose ?
Is it a simple image uploaded to it or it has anything else ?
And the costumized buttons is an image too , with functions ?
I'm scripting in Unity , so i will add code to an image(buttons) or it's something like windows form buttons ?
The Background of the Login Systems or the back page is a simple image
that is resizeble with any resolution of the computer/options the user
chose ?
Yes it's possible,but you cannot use Animated Gifs.But you can try this
Is it a simple image uploaded to it or it has anything else ? And the
costumized buttons is an image too , with functions ?
Just follow Unity Official Tutorial on GUI Image
Just simply
go to>hierarchy>create>UI>Image
Change source image>choose what you want
I'm scripting in Unity , so i will add code to an image(buttons) or
it's something like windows form buttons ?
Yes,just like that.for an example,this is a sample script for main menu.You have to use "using UnityEngine.UI;" namespace. Create this in main canvas And drag those(play and exit)buttons for those public button objects.Change "image component's" source image.Create separate Quit menu like this.
I referenced this tutorial,but you have to do minor changes though
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class menuScript : MonoBehaviour {
public Canvas quitMenu;
public Button startText;
public Button exitText;
// Use this for initialization
void Start () {
quitMenu=quitMenu.GetComponent<Canvas>();
startText=startText.GetComponent<Button>();
exitText=exitText.GetComponent<Button>();
quitMenu.enabled=false;
}
public void ExitPress()
{
quitMenu.enabled=true;
startText.enabled=false;
exitText.enabled=false;
}
public void NoPress()
{
quitMenu.enabled=false;
startText.enabled=true;
exitText.enabled=true;
}
public void StartLevel()
{
Application.LoadLevel(1);
}
public void ExitGame()
{
Application.Quit();
}
}
If you're working in Unity, then check out their GUI stuff. The UI tools they added in 4.6 will do everything you need in terms of the interface.
As for the actual login system, well that depends on what you're logging into...
I am a very newbie on WPF, C#, and Kinect. But I've found out how to initialize the kinect, and show two windows. My application is a toy one, have a full screen app with a button, when the user clicks, it should open a new window.
I've tried but two things won't work:
when the new window open the kinect user view won't show any body
when closing the window (going back to the main) the app crashes
The prototype window XAML is like this:
<Window ...>
<k:KinectRegion Name="region_">
<Grid>
<k:KinectUserView .../>
</Grid>
</k:KinectRegion>
</Window>
On the C# side, I have a prototype class like this:
public partial class MainWindow : Window
{
public KinectSensor sensor_ = KinectSensor.GetDefault();
public MainWindow()
{
//...
KinectRegion.SetKinectRegion(this, region_);
this.sensor_.Open();
}
}
The secondary page (with identical constructor as above) has a button that calls a function that basically says sensor_.Close() and this.Close().
Can I use a single kinect with multiple windows? In case not (please tell me I can!) how can I proceed in having two "views"? Pages AFAIK reading on the web, requite NavigationWindow, and VS complains I cannot add the kinect region to that.
Thanks!
It turns out you don't need to close the sensor. In order to make more windows work with one sensor:
pass the KinectSensor initialized in the main one to the "child" window
initialize the child's region
You just need to this.Close() without ever opening again the stream or closing it. The Kinect user view works flawlessly.
I finished to develop an XNA game, then I created the Monogame project, and tested it on my device. Now I made some other pages such as an "about" page. How can I go to that page considering I have a Monogame project and just an XNA code? In particular inside my game I made a Main Menu where you can click the "about" button and know if someone has clicked: how can I link that event to the "go to about.xaml" function?
Inside XNA, update method:
if (about_button.IsClicked())
{
// Go to about.xaml
}
I tried:
if (about_button.IsClicked())
{
((PhoneApplicationFrame)Application.Current.RootVisual).Navigate(new Uri("/About.xaml", UriKind.Relative));
}
But it throws: System.UnauthorizedAccessException
I haven't tried this myself, but the WP framework has the Window.Current.Content object which you can use to load different views.
For example:
// Create a Frame to act navigation context and navigate to the first page
var rootFrame = new Frame();
rootFrame.Navigate(typeof(BlankPage));
// Place the frame in the current Window and ensure that it is active
Window.Current.Content = rootFrame;
Window.Current.Activate();
So if you are using a windows phone 8 project template, with that object you can easily tell the application to load a xaml view or the game one.
You can also check how to do it with WinRT and monogame on this site (the Window.Current is part of the WP and WinRT framework). Here, you will find how to integrate both frameworks in order to create a monogame using the WinRT xaml views :)
For more information on the Window.Current, check this link.
EDIT
If you used a monogame for windows phone template, a XAML page should already exist in your project which is used to load the game itself, as well as a media element for video and sound playback.
The page is called "GamePage.xaml", which you could use for your navigational purposes.
This info was taken from the "Windows 8 and Windows Phone 8 Game Development" book written by Adam Dawes (chapter 13).
In the case of the Windows Phone projects, GamePage is implemented as
a normal page. [...]
Within the Windows Phone page is a full-page
Grid control, inside which is another full-screen control of type
DrawingSurface. This is a type of control that DirectX can use to
render graphics to a Windows Phone page. Our XAML content can also be
placed into the Grid. A MediaElement control is present within the
Grid, too. MonoGame uses this for some of its audio playback
functionality.
On both platforms, the way that XAML and DirectX have been designed to
interact is that the DirectX rendering is processed first. Once this
has been completed, the XAML renderer then takes control and adds its
content as a second step, prior to presenting the final rendered page
to the user. As a result, XAML content will always appear in front of
any graphics rendered by MonoGame. This ensures that any XAML controls
we use as our user interface (for control buttons, text displays, and
so on) will appear unobstructed in front of the game graphics.
The XAML rendering still takes any transparency within the controls
into account, so it is quite possible to have controls that are
partially transparent or that use alpha shading. These will blend in
front of the MonoGame graphics, as you would expect them to.
With this into account, you should be able to throw an event from your game class (monogame), the xaml page can suscribe itself to it and then, when captured, render your xaml page (maybe a user control would be wiser as you won't navigate away from the main game page).
Hopefully, this will help you with your problem.
Try to create a frame in your gamepage
public static Frame RootFrame { get; private set; }
then in your click event put these lines
RootFrame = new Frame();
RootFrame.Navigate(typeof(about));
did this work?
You receive that error because the call has to be made from the UI thread like this:
Deployment.Current.Dispatcher.BeginInvoke(() =>
(App.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/Pages/MenuPage.xaml", UriKind.Relative)));
Also, make sure you dispose of the game object when unloading the game xaml page. You to this by subscribing to the Unloaded event of the GamePage and calling Dispose on the game object. See below:
public partial class GamePage : PhoneApplicationPage
{
private LoonieGame _game;
public GamePage()
{
InitializeComponent();
_game = XamlGame<LoonieGame>.Create("", this);
this.Unloaded += GamePage_Unloaded;
}
void GamePage_Unloaded(object sender, RoutedEventArgs e)
{
Deployment.Current.Dispatcher.BeginInvoke(() => _game.Dispose());
}
}
I'm using Monotouch to develop an app for the iPhone.
In my iPhone only app, I have an InputAccessoryView appear whenever the user selects a textfield. The accessory view provides buttons which aid the user (undo/redo etc).
It works fantastically on the simulator and on iPhone devices.
However, out of the blue, the Input Accessory View is not appearing on the iPad. I've made no changes to the code regarding the views; I've even rolled back to a version that I know displayed the accessory view correctly.
I was wondering if anyone else has come across this behaviour before / would know why this is happening?
EDIT
I've seen this accross all of my iphone projects running on the ipad. I made a fresh project which only contains 1 view, a UITextField and override the Input Accessory View and I'm still seeing nothing.
Code I'm using to test the override of the input view is:
public override UIView InputAccessoryView
{
get
{
UIView view = new UIView(new RectangleF(0,0,320,30));
view.BackgroundColor = UIColor.Blue;
return view;
}
}
Nothing too complex, on the iPhone just returns a blue bar above the keyboard.
I've reinstalled Mono, MonoDevelop, Monotouch and the iOS SDK multiple times to no avail. Apps that I've downloaded from the store still show the Input Accessory View, so I'm beginning to wonder if it's an issue with my Monotouch/iOS SDK combo? I'm using Monotouch 3.1.3 personal and 4.1 iOS SDK - version 2.6 of Mono. I'm going to try updating to version 2.8 of Mono.
The thing I don't understand is why it would work previously then all of a sudden just stop working?
When I'm deploying the code on the iPad, I'm selecting "Rebuild all", then uploading to the device. It doesn't matter if I pick either Release/Debug as a build, both yield the same result.
EDIT 2
If I subclass a UITextField and override the InputAccessoryView within that subclass, then the view appears on the iPad. This means that the InputAccessoryView which is being overriden in the View class isn't being assigned to the Textfield on the ipad.
EDIT 3
It would appear this is fixed in iOS 4.2 with Monotouch 3.2 !
My first suggestion is to reset the device in iTunes. You may have done so already, but just in case you did not, please do it first (since it's quick and easy to do).
If that didn't help: To identify if it is a problem with Monotouch and/or the iOS SDK could you repeat what you did above using only Cocoa Touch?
I.e., start a View-based app in XCode, add one UITextField in Interface Builder and connect it to the controller. Here is a corresponding Objective-C code to do it:
Instance variables in your controller (add to the #interface section in the <controllername>.h file):
IBOutlet UITextField *text;
UIView *accessory;
Hook up the UITextField in Interface Builder with the text outlet and then add the following implementation of viewDidLoad to the controller (the #implementation section in the <controllername>.m file):
- (void)viewDidLoad {
accessory = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
[accessory setBackgroundColor:[UIColor blueColor]];
[text setInputAccessoryView:accessory];
[super viewDidLoad];
}
If this displays the blue bar correctly, the problem is with the setup of Monotouch. If it does not, it is an issue with your device.
I had the same issue where a UITextView contained within a UIView would show the accessory bar on the simulator but not on the iPhone or iPad.
I'm doing some strange things with BeginFirstResponder to allow tapping anywhere in the larger parent area (containing a label and the text field) and activating the contained field and suspected this was involved. I added code in the parent UIView to override the InputAccessoryView and have it return the the value from the child UITextView and this fixed.
I suspect that Monotouch has an issue routing the event to the wrong object and my fix resolved it.
pseudo code:
public class ParentView : UIView
{
UILabel Label;
MyTextView Text;
/*Magic line here that fixed the problem */
public override UIView InputAccessoryView {get{return Text.InputAccessoryView;}}
}
public class MyTextView : UITextView
{
UIView Accessory;
public override UIView InputAccessoryView {get{return Accessory;}}
}
How are you showing your accessory view?
Can you try keeping a reference to the view?
Try this, and let me know if this fails:
public class Foo {
static UIView track;
}
And then when you create your view, stick it in that global:
Foo.track = new MyAccessoryView ()
I'm having problems understanding how WPF app.xaml works. Is it like Main method in winforms programing?
What I want is a MainController class which keeps track of my Window object. For example:
public MainController()
{
_windowMain = new WindowMain(this);
}
public WindowMain GetWindowMain
{
get { _windowMain; }
}
And so on with all the windows I have in my project. But where should my MainController be initialized?
Check the StartupUri property of the App.xaml file. It links in a Window's XAML file within your project to be launched at startup.
If you want to avoid this, then I believe you can override a method in App.xaml.cs to launch the window explicitly via your controller.
You should understand that the compiler makes a class called 'App' that overrides System.Windows.Application by compiling your App.xaml and App.xaml.cs files. Check the documentation for that class to learn more about the lifecycle management of your WPF application.