COOKIES

This site may be using cookies to melk you with your own data. I, ben0bi, am not the owner of this web service and I also do not maintain their servers. But the EU and the owner of this service think, that the user (me) has the responsibility to inform the consumer (you), that this website uses cookies. Again: I, ben0bi, NEVER use cookies. I am not responsible for the setup of this web service. I just present some information here and do not intend to spy on you for whatever reason ever. But (also again), I do not host this website nor do I maintain any servers related to this website nor do I benefit from using the cookies maintained from this service. I hereby give the responsibility for using cookies on blogspot back to the owners of blogspot.

Montag, 9. März 2015

Part 2: Basic Winphone Setup

This is part 2 in my tutorial series about writing an emulator.
I am doing this with WinPhone 8.1 and MonoGame.

If you don't know what I'm talking about, here is Part 1.

In this section, we will install the right development environment and create a basic game-app.

I take this part first because you and I want to see at least something, not? You can skip that part if you use another engine/platform.

OK, I will use MonoGame, the (open source) successor of XNA.
If you want to use DirectX, you have to use C++ and that's none of my business anymore.

At least now, you should have downloaded and installed MS Visual Studio 2013 Express Update 4 or something similar.

After that, you should install MonoGame.

You can download MonoGame from here:
http://www.monogame.net/downloads/
Use at least V. 3.2 which has templates for MS VS 2013.

With the install also comes OpenAL, which I decided to install because, as mentioned, I don't know nothing about sound programming and if there is an "Open Source Audio Library", why not use that?

Start up Visual Studio and create a new Application using the C#->"MonoGame Windows Phone 8 Project"-Template.

There you have three "main" files:
GamePage.xaml, which is your WinPhone-Layout-file for that page.
GamePage.xaml.cs, which is the source-file corresponding to the layout (file) - where your button-clicks and other UI-stuff will be handled.
Game1.cs, which is the game itself. It runs in it's own thread - you cannot simply use WP-UI-button-clicks and stuff here because that will maybe throw an Asyncronous-Exception. More about that later, when I know how to handle that myself.

The project should compile without errors.

If you get a blank screen, don't worry - that's a common issue with the MonoGame v3.2 template.
Follow this discussion to solve it:
http://community.monogame.net/t/3-2-on-windows-phone-8-just-shows-black-screen/278/12

I just uncommented the alternate grid on the bottom of GamePage.xaml and commented out the main one. Even if it should run now in portrait mode, it seems to be in landscape mode, though.

Some Static Functions

There are some methods which will be used through the whole app. Create a new class called Static.cs and put this methods in it:

using System.Windows;
using System.Windows.Controls;
...

// shows a standard text message.
public static void ShowMsg(string txt)
{
     MessageBox.Show(txt);
}

// go back to the last page or to the main page.
public static void GoBackOrMain(Frame frm)
{
     if(frm.CanGoBack)
          frm.GoBack();
    else
         frm.Navigate(new Uri("/GamePage.xaml", UriKind.Relative);
}


The first method, ShowMsg, is just here to get some info on the screen. You can use that for infos like "Loading failed, please try another ROM" or such stuff which only needs an OK-button.

The second method GoBackOrMain, tries to go back to the last opened page. If it cannot go back, it tries to open the main page. This method is for use with the back button and/or cancel buttons.

In WP 8.1 that works a little bit other but on WP 8.0 that's all you have to do.
That code is not tested yet (navigating).

The Back Button

The back button does not work like in other apps. You cannot use HardwareButtons.BackbuttonPressed += myFunc (WP 8.1?).

Open GamePage.xaml. Click on the events button in the properties window. Search for the event BackbuttonPressed or OnBackbuttonPressed and double click it.

You have now a method for your back button, use it like you want. I want to open a CommandBar with it, but first you should just exit the app with _game.Exit();

Other Stuff

There are other problems which I could not solve until now. I will post it here when I find a solution.
+ Cannot switch tasks, the game just shows the cleared screen after resuming.
+ Cannot even press the switch-task-button and then resume game directly.

Download

Download the Source for this Part:
Emu_01_WP_Setup.zip from Mirror 1 (OneDrive)
Emu_01_WP_Setup.zip from Mirror 2 (homeserver) (direct download)

It has some more static methods and draws a texture to the screen for testing.



In Part 2A we will set up the graphics for our emulators to have a "render device".

Part 2A: The Graphics Engine

You can skip the whole Part 2x stuff and just go to Part 3 if you do that on another Platform/Engine.

Keine Kommentare:

Kommentar veröffentlichen