Introduction
With the app-innovation contest we all learned so much. And now its our time to give back.
In this article
- I am describing creating a simple app and problems "with solutions"
- Will talk about my entry
- Provide a template for speeding your app why reinvent the wheel when you can use one available and modify it.
Starting a win 8 desktop app
Just start a new project a console or window form app is good to go it is all same and depends what you are planning to start.
Here we have chosen a windows form app. As we are going to use Windows RT sensors API we are choosing .NET Framework 4.5
By default you cant add wincore (WinRT API to window desktop apps )
So unload the project
Perform following steps:
- Edit the .csproj file .
- Add
<TargetPlatformVersion>8.0</TargetPlatformVersion>
just after start of <PropertyGroup>
- Reload Project
Now add the reference to windows inside core which is now available. It is not available if you don't follow above steps and try directly.
Add reference to system.runtime
, system.runtime.interopservices
etc. they are all are inside program files or program files x86 sub folder "\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5"
Now your app is ready to use sensors.
If you are planning to use XNA like my entry terminal velocity you will need to add references of XNA DLL too.
Using a sensor in your app.
private Accelerometer acel;
private SimpleOrientationSensor orientationSensor;
public form1() {
acel = Accelerometer.GetDefault();
if (this.acel != null)
{ acel.ReadingChanged += Aceloro;
}
orientationSensor = SimpleOrientationSensor.GetDefault();
if (this.orientationSensor != null)
{
orientation = this.orientationSensor.GetCurrentOrientation();
this.orientationSensor.OrientationChanged += OrientationChange;
}
}
private void OrientationChange(SimpleOrientationSensor sender, SimpleOrientationSensorOrientationChangedEventArgs args)
{
if (this.InvokeRequired)
{
IAsyncResult result = BeginInvoke(new MethodInvoker(delegate()
{
Data1.Text = "Orientation " + args.Orientation + "\n";
}));
EndInvoke(result);
}
else if (this.IsHandleCreated)
{
Data1.Text = "Orientation " + args.Orientation + "\n";
}
}
private void Aceloro(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
{
if (this.InvokeRequired)
{
IAsyncResult result = BeginInvoke(new MethodInvoker(delegate()
{
DATA.Text = "x= " + args.Reading.AccelerationX + ". Y= " + args.Reading.AccelerationY + ".Z= " + args.Reading.AccelerationZ + "\n";
}));
EndInvoke(result);
}
else if (this.IsHandleCreated)
{
DATA.Text = "x= " + args.Reading.AccelerationX + ". Y= " + args.Reading.AccelerationY + ".Z= " + args.Reading.AccelerationZ + "\n";
}
Problems
As Win 8 devices can be tablet and have changing orientation so it is necessary to make that in consideration and change your game code to support many different configurations.
Solution
We can know about rotation using the orientation listener. Now we need to use this and width and height difference to make our app work in other orientation too.
My app is a game using accelerometer so using x axis when in portrait is not what a user expect from my app. Using orientation listener I can know which side orientation my app is and use that to change the axis of accelerometer in use for moving plane. Like x for normal use -x for 180 degree rotation -y for 90 degree rotation and y for 270 degree rotation.
After Finishing Your App
When your game is ready you can use code signer tool to sign the exe and pack using wix or install-shield, sign the packed MSI or EXE and then you can submit to Intel AppUp store.
If you are submitting an app as an MSI package make sure your app stores its install directory in reg and read it from there to open files etc. (not doing so will crash your app from Intel appup client).
If you are planning to use XNA ensure your workstation has Visual Studio 2010 with latest Windows Phone SDK thus you can get the compile the XNA resources for using with your project.
Background
This article is linked and a spin of terminal velocity article series.
- The Android version of the same game, all code is opensource. Nearly most code is commented and article explains jni and many other, http://www.codeproject.com/Articles/487074/Terminal-Velocity-Android
- The original app-innovation article,
http://www.codeproject.com/Articles/473333/TerminalVelocity-an-action-game-for-windows8
Story Of Terminal Velocity
Terminal velocity was a game specially planned for app innovation contest.
But due to delay in having my device on time I was unable to tune accelerometer on time and even had not implemented touch as I was sure Win 8 converting mouse input to touch and my game use accelerometer was not a touch based game. But now all of them is implemented and this game will release soon on inlet app up .
Mean while the game had got chance to get ported to Windows Phone and Android.
Android users can download it form here
Source code form here
Windows phone app will be live soon.
Using the Code
This article provide a template app for speeding up ultra book development. The main interesting part would be using multi touch with your app and that is already implemented here.
All touch related data is polled to variable e
in these functions use it .
Touchup(object sender, EventArgs e);
Touchdown(object sender, EventArgs e);
Touchmove(object sender, EventArgs e);
{ if (e.IsPrimaryContact)
{
idc = e.Id - 1;
}
Id=e.Id-idc;
POSX=e.LocationX;
POSY=e.LocationY;
}
Points of Interest
Interesting thing I learned while writing terminal velocity.
- I used XNA and finished whole game that was old work, then I came to know that my app is not using single touch functions as it took 2 clicks to get a touch register.
- I used XNA with winform and implemented touch by searching and reading old touch related code in various example on msdn and finally found this method.
- I used a time based invalidate but you can use it on last line of draw() to get fast drawing.
Content of Template
- Implementation of touch api
- Implementation of sensors
- Implementation of xna in win form with code to toggle to full screen