locked
Sprite Animation With Xaml and C# RRS feed

  • Question

  • Hi, I trying to fallow this tutorial http://www.edumobile.org/windowsphone/windows-phone-programming-tutorials/animation-using-bitmap-image/

    But cant seem to figure out what i'm doing wrong as I don't completely understand the code. can some one please point out what i was doing wrong and my be if you have some spare time please explain what it means. Thanks 

            

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media;
    using System.Windows.Navigation;
    using Microsoft.Phone.Controls;
    using Microsoft.Phone.Shell;
    using PhoneApp1.Resources;

    namespace PhoneApp1
    {
        public partial class MainPage : PhoneApplicationPage
        {
            // Constructor
            public MainPage()
            {
                InitializeComponent();
                CompositionTarget.Rendering += new EventHandler(this.CompositionTarget_Rendering);

            }

            private void CompositionTarget_Rendering(object sender, EventArgs e)
            {
                int counter=0;
                var frame_num=0;
                int xOffset;
                int yOffset;

                if (counter > 500)
                    counter = 0;
                else
                counter++;

                if (counter % 15 == 0)
                    {
                        if (frame_num <= 2)
                            frame_num++;
                        else
                            frame_num = 0;
                    }

                   RectangleGeometry r = new RectangleGeometry();
                    xOffset = (frame_num) * 100;
                    yOffset = 0;// (frame_num / 5) * 168;
                    r.Rect = new Rect(xOffset, yOffset, 61, 168);
                    spr.Clip = r;

                        //We have to compensate for the clipping region offset so the sprite stays in place.
                  //  transpos.X = -xOffset; transpos.Y = -yOffset;
            }

        }
    }

    <Grid x:Name="LayoutRoot">

            <Image x:Name="spr" Source="Assets/Aarro Sprite.png" Stretch="None" Margin="10,195,68,303">

                <Image.CacheMode>
                    <BitmapCache/>

                </Image.CacheMode>
                <Image.RenderTransform>
                    <TransformGroup>
                     <TranslateTransform x:Name="transpos" X="61" Y="119" />
                    </TransformGroup>

                </Image.RenderTransform>

            </Image>

        </Grid>


    </phone:PhoneApplicationPage>

    Thursday, October 3, 2013 9:43 PM

All replies

  • Are you trying to write a Windows Store app or a Windows Phone app?

    The Windows Store apps forums are specific to Windows Store apps, but the code you list is specific to Windows Phone and isn't expected to work in a Windows Store app.

    Thursday, October 3, 2013 10:09 PM
    Moderator
  • Its for windows store, but i'm just learning to implement it on windows phone. i thought i could use similar method for windows store later. Would the code be so different?, Thanks for any feedback you might have in this matter.  
    Friday, October 4, 2013 2:03 AM