Click here to Skip to main content
15,881,882 members
Articles / Programming Languages / C#

App template for speeding Ultra-book developmental

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
16 Jan 2013CPOL4 min read 13.1K   90   1   1
A template code to help starting ultra book development fast

Introduction

With the app-innovation contest we all learned so much. And now its our time to give back. 

In this article

  1. I am describing creating a simple app and problems "with solutions"
  2. Will talk about my entry
  3. 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

Image 1

By default you cant add wincore (WinRT API to window desktop apps )

So unload the project  

Image 2

Perform following steps:

  1. Edit the .csproj file .
  2. Add
    <TargetPlatformVersion>8.0</TargetPlatformVersion>
    

    just after start of <PropertyGroup>

  3. Reload Project

Image 3

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"

Image 4

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.

C#
 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";
                    }));
                // wait until invocation is completed
                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.

  1. 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
  2. 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 .

C#
Touchup(object sender, EventArgs e); 
Touchdown(object sender, EventArgs e); 
Touchmove(object sender, EventArgs e); 
//Dummy  function body to get touch data
{ 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.

  1. 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.
  2. 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.
  3. I used a time based invalidate but you can use it on last line of draw() to get fast drawing.

Content of Template

  1. Implementation of touch api
  2. Implementation of sensors
  3. Implementation of xna in win form with code to toggle to full screen

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer InductionLabs
India India
Currently I am an independent developer usually develops under brand name Induction games sometimes under Induction labs ,Can say that I am professionally developing apps for more than 4 years .

Some links to my apps in different apps stores are ..


Windows Phone
http://www.windowsphone.com/en-US/store/publishers?publisherId=InductionGames

Android
1. https://play.google.com/store/apps/developer?id=Induction+Labs&hl=en
2.https://play.google.com/store/apps/developer?id=Induction%20Games

Blackberry Store
http://appworld.blackberry.com/webstore/vendor/39848/?lang=en

Flash Games :
http://www.mochigames.com/developer/praveenojha/
*my flash portal is no longer active so the quiz game cant be played .

Perceptual computing phase 1 first prize Winner app (air piano)
http://software.intel.com/sites/campaigns/perceptualshowcase/air-piano.htm

My Blog
http://praveenojha.com

Comments and Discussions

 
QuestionTo get Touch on xna window Pin
PraveenOjha27-Sep-13 3:33
professionalPraveenOjha27-Sep-13 3:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.