XNA to MONOGAME
Hey allll...
Hope you all are doing some cool works....
Today I am gonna show you features of MONOGAME.
As a net develeoper I specifically prefer monogame
to convert my XNA games into android and ios games,
though we can develop games through in same format
as we are develping for XNA..
Ok..Lets Cut these things..time to have some action-
Here I have converted my sample XNA game to Android game)
Steps-
1.Install Visual Studio
2.Install monogame framework for visual studio here-
http://www.monogame.net/downloads/
3.Now open Visual Studio..Go to FILE->NEW->PROJECT
It will pop up to select template..Select like as below-
You will see a solution Explorer view-
First you need to delete Game1.cs file.
An activity file will be there ..That is the file you need to play on specifically.
Open that file(Activity1.cs)
Ok now go to your XNA game folder.Copy this Game1.cs(copy other .cs files as well if you have any)
file under your project(in my case Game7)
Now copy your XNA game's content files(sounds,textures etc. except spritefont files ) into this Game7 project's Content folder like shown below-
Now its time for spritefont files.In monogame you need to copy
.xnb files which is generated automatically during the build of your XNA game.
Go to your XNA game project folder and go to bin folder,Exactly like below-
F:\newCars\DemoGAme\DemoGAme\DemoGAme\bin\Windows Phone\Debug\Content
(in my case its F drive and newCars folder ,So dont be confused.)
So copy your .xnb files in your monogame project's(Game7) content folder.
Now its time to edit in Activity1.cs file.DO same way like below
Another I thing I forgot to tell.Right Click your all files in "Content"
Folder (by right clicking every single file) and change their property like side picture-
Its DOne..............Build the solution and deploy it to emulator or device.....You will see your game
Windows Phone
Android
Now here You will see one problem that is scaling of images,fo that -
Declare valiables like below-
Vector2 baseScreenSize = new Vector2(800,480);
private Matrix globalTransformation;
Now in your Loadcontent method of Game1.cs file,below spritebatch
declaration right below code-
spriteBatch = new SpriteBatch(GraphicsDevice);
float horScaling = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width / baseScreenSize.X;
float verScaling = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height / baseScreenSize.Y;
Vector3 screenScalingFactor = new Vector3(horScaling, verScaling, 1);
globalTransformation = Matrix.CreateScale(
screenScalingFactor);
Now in your Draw Method of your Game1.cs file,Replace spriteBatch.begin()
to-
spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, null, null, globalTransformation);
SCALING is done....
Now as you have scaled images,you need to scale touch input also,
in my case ,I have investigated and written code like below-
TouchCollection touches = TouchPanel.GetState();
foreach (TouchLocation touch in touches)
{
float horScaling = Window.ClientBounds.Width / baseScreenSize.X;
float verScaling = Window.ClientBounds.Height / baseScreenSize.Y;
var screenScalingFactor = Matrix.CreateScale(horScaling, verScaling, 1);
var touchPos = new Vector2((int)touch.Position.X, (int)touch.Position.Y);
var scaleTouchPos = Vector2.Transform(touchPos, Matrix.Invert(screenScalingFactor));
TouchLocation t = new TouchLocation(touch.Id, touch.State, scaleTouchPos);
bool touchHandled = false;
This "t" is your scaled touch input.
OK Guys here is how you need to convert XNA to monogame,If I have written something wrong Please forgive me.
And if you are facing any problem regarding this article,You can mail me(go to contact).
Also please download my Apps and Games(details you can see in my Blogs)