Wordastic, CVC Words and Slydr Update #wpdev

Last few weeks have been busy. I finally finished 1.0 of Wordastic. I still have to improve the overall experience but its not too bad. The idea is simple. take a word and randomise the characters. Give users a certain amout of time to correct the sequence. the faster they do it, the more points they get.

CVC Words is based on my discussions with my wife about education in early years. CVC words are simple words that start and end with consonant and have a vowel in between. They are frequently used easy to learn works like Cat, Bat, Bad, Mad etc

Lastly i added support for Lithuanian in Slydr based on user request.

Advertisement

High Performance Touch Interface #wpdev #wp7dev

Every now and again i come across developer questions like why is manipulation delta slow etc. Let me tell you why.

UIElement Silverlight for #windowsphone exposes a few events like

http://msdn.microsoft.com/en-us/library/system.windows.uielement(v=vs.95).aspx

Public eventSupported by Silverlight for Windows Phone ManipulationCompleted Occurs when a manipulation and inertia on the UIElement is complete.
Public eventSupported by Silverlight for Windows Phone ManipulationDelta Occurs when the input device changes position during a manipulation.
Public eventSupported by Silverlight for Windows Phone ManipulationStarted Occurs when an input device begins a manipulation on the UIElement.

These are high level touch interfaces and there is a significant overhead in reporting (and hence delay etc).

If you are say drawing on a bitmap or canvas, you dont want a min delta change before event is fired. For that lets look at low-level interface exposed in Silverlight.

http://msdn.microsoft.com/en-us/library/system.windows.input.touch(v=vs.95).aspx

Public eventStatic memberSupported by Silverlight for Windows Phone FrameReported Occurs when the input system promotes a Windows 7 touch message for Silverlight.

Touh.FrameReported is a low level method and has little overhead and is very very precise. Let me give you a code sample

Touch.FrameReported += Touch_FrameReported;

you can do above in Loaded event. Here’s the implementation of the Touch_FrameReported handler. WorkArea is Canvas in this. I have also used this in conjugation with WritableBitmap

private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
{
    try
    {
        // Determine if finger / mouse is down
        point = e.GetPrimaryTouchPoint(this.workArea);
        
        if (point.Position.X < 0 || point.Position.Y < 0)
        return;
        
        if (point.Position.X > this.workArea.Width || point.Position.Y > this.workArea.Height)
            return;
        
        if (this.lbLetter.SelectedIndex == -1)
            return;
        
        switch (point.Action)
        {
            case TouchAction.Down:
                draw = true;
                old_point = point;
                goto default;
        
            case TouchAction.Up:
                draw = false;
                break;
        
            default:
                Draw();
                break;
        }
    }
    catch
    {
        MessageBox.Show("Application encountered error processing last request.");
    }
}

I hope this is useful to #windowsphone developers out there.

Images and Build Action settings in WP7

In this day and age.. we come across as images everyday – whether we are searching the net, reading news or books or using applications.

I am only discussing Silverlight part of WP7 development here. My knowledge of XNA is too little to do anything useful with it… let alone blog about it.

Lets open a Windows Phone Project. Most people tend to store their content in specific folders e.g. all pictures and images go in Images folder etc. Lets create Images folder and import our sample image.

Right click Images folder and click Add >> Existing Item
Browse to the correct location and find the file. Click okay and the file is imported in the project.

Lets look at the properties of the imported file. Default build action is set to Resource. Lets now add Image control and display the image.
<Image Source=”/PhoneApp1;component/Images/IMG_5710.jpg” />

As you can see its a slightly complicated path though there’s nothing wrong with it. It works just fine. Now lets try setting the image BuildAction to Content. When setting it to content, please remember to set “Copy to Output Folder to “Copy Always”. Now we need to modify the XAML
<Image Source=”/Images/IMG_5710.jpg” />

Please ensure that Copy to Output is set and that you use /Images to denote Images directory.
If we run the app, it runs exactly as it did before.

Now lets look at the contents of the XAP file. XAP file is just a zipped file containing various assemblies and resources.

Resource Content
Contents of XAP  
Contents of Assembly    

the screenshots make the difference obvious. When setting the picture as resource, it is included in the Assembly. When setting it as Content, it is included in the XAP but not in assembly. That makes all the difference. Imagine you had a number of pictures – if you chose them to be Resource, they would be loaded the same time as CLR loading your assembly. If each image was say 500k and you had 10 that would make your assembly 5 megs larger and slower to load. However if you set them to be Content, they are still there in the package just not in the Assembly and they are loaded as required.

The bottom line is: Unless you have a very good reason, set images, videos, files etc to build action – Content and “Copy to Output Folder to “Copy Always”.