• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Using namespaces and time dispatcher for images animation (WPF C#)

MrSeanKon

New Member
Joined
Nov 14, 2006
Messages
267 (0.07/day)
Likes
73
Location
Athens in love with Anna :)
#1
The first attachment includes a non ultimate code; imagine that you have to animate 10 cards => 10 different time dispatchers??? => this sucks! :laugh:
But I uploaded it just to show you how we can bypass this problem by reusing code.
Yeap the solution is an extra namespace. Someone may say why don't you write an extra class inside the major (main) namespace?
Well it is possible but I prefer to avoid it. Cos we must use static functions and variables and this is an extra headache.
Download the files and let's discuss :)
 

Attachments

Joined
Dec 2, 2009
Messages
3,257 (1.10/day)
Likes
315
System Name Mercury KM-81
Processor Phenom II x4 B50
Motherboard ASUS M4A89GTD PRO
Cooling Cooler Master Hyper TX3
Memory 6GB Ram (4GBx1 Corsair 2GBx1 Nanya)
Video Card(s) PowerColor AX6770 V2.0
Storage 2TB WD Black, 1TB Hitachi, 500 GB WD Blue
Display(s) Philips 247E-LPH 24" 1920x1080
Case Mercury
Audio Device(s) Integrated Realtek
Power Supply Corsair 750TX
Software Windows 7 64-bit
Benchmark Scores Maybe it is time to benchmark :D
#2
Ok, you mean adding namespaces will add animation to the cards?
And you had only 4 card animations, which means 4 namespaces?
Nice work though

Why don't you add a function for the namespaces?
Or make a single namespace for 10 namespaces :)
 

MrSeanKon

New Member
Joined
Nov 14, 2006
Messages
267 (0.07/day)
Likes
73
Location
Athens in love with Anna :)
#3
No, total namespaces are two. The main (its name is Game) and the secondary (its name is paixnidi => παιχνίδι = means game and pronounced paixnidi).
Try to download the files first. Have you got Visual Studio?
If not, it is not a problem => open with Notepad MainWindow.xaml.cs files.
 
Joined
Dec 2, 2009
Messages
3,257 (1.10/day)
Likes
315
System Name Mercury KM-81
Processor Phenom II x4 B50
Motherboard ASUS M4A89GTD PRO
Cooling Cooler Master Hyper TX3
Memory 6GB Ram (4GBx1 Corsair 2GBx1 Nanya)
Video Card(s) PowerColor AX6770 V2.0
Storage 2TB WD Black, 1TB Hitachi, 500 GB WD Blue
Display(s) Philips 247E-LPH 24" 1920x1080
Case Mercury
Audio Device(s) Integrated Realtek
Power Supply Corsair 750TX
Software Windows 7 64-bit
Benchmark Scores Maybe it is time to benchmark :D
#4
I have already downloaded
This is why i said 4 card animations
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
21,058 (6.22/day)
Likes
10,183
Location
IA, USA
System Name BY-2015
Processor Intel Core i7-6700K (4 x 4.00 GHz) w/ HT and Turbo on
Motherboard MSI Z170A GAMING M7
Cooling Scythe Kotetsu
Memory 2 x Kingston HyperX DDR4-2133 8 GiB
Video Card(s) PowerColor PCS+ 390 8 GiB DVI + HDMI
Storage Crucial MX300 275 GB, Seagate 6 TB 7200 RPM
Display(s) Samsung SyncMaster T240 24" LCD (1920x1200 HDMI) + Samsung SyncMaster 906BW 19" LCD (1440x900 DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay
Audio Device(s) Realtek Onboard, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse SteelSeries Sensei RAW
Keyboard Tesoro Excalibur
Software Windows 10 Pro 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
#5
Uh...there's absolutely no reason to use two namespaces in your case. I moved "attempt" class into the "Game" namespace, removed all references to "paixnidi" and it works fine:
Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Windows.Threading;


namespace Game
{
    class attempt
    {
        int delay;
        double x, y, X, Y;
        Image card;
        DispatcherTimer Timer;

        public void move(int lag, double startX, double startY, double endX, double endY, Image karta)
        {
            delay = lag;
            x = startX;
            y = startY;
            X = endX;
            Y = endY;
            card = karta;
            Timer = new DispatcherTimer();
            Timer.Tick += new EventHandler(tick);
            Timer.Interval = new TimeSpan(0, 0, delay);
            Timer.Start();
        }
        void animation()
        {
            if (delay == 0)
                delay = 1;
            ThicknessAnimation myanimation = new ThicknessAnimation(new Thickness(x, y, 0, 0), new Thickness(X, Y, 0, 0),
                  TimeSpan.FromSeconds(delay));
            card.BeginAnimation(Image.MarginProperty, myanimation);
        }
        void tick(object sender, EventArgs e)
        {
            Timer.Stop();
            Timer = null;
            if (delay > 1)
                delay = 1;
            animation();
        }
    }
  public partial class MainWindow:Window
  {
      public MainWindow()
      {
         InitializeComponent();         
      }      
      private void button1_Click(object sender, RoutedEventArgs e)
      {
         attempt card1=new attempt();
         attempt card2=new attempt();
         attempt card3=new attempt();
         attempt card4=new attempt();
         
         card1.move(0,image1.Margin.Left,image1.Margin.Top,image5.Margin.Left,image5.Margin.Top,image1);
         card2.move(1,image2.Margin.Left,image2.Margin.Top,image6.Margin.Left,image6.Margin.Top,image2);
         card3.move(2,image3.Margin.Left,image3.Margin.Top,image7.Margin.Left,image7.Margin.Top,image3);
         card4.move(3,image4.Margin.Left,image4.Margin.Top,image8.Margin.Left,image8.Margin.Top,image4); 
         button1.Visibility=Visibility.Hidden;
      }      
   }
}
Namespaces are only to avoid collisions of same-named classes. For example, you might have zero-terminated String class under a network namespace while having a standard String class under a text namespace:
Text.String
Network.String

Different classes, same name.


You should only have one dispatcher handle all animations. If more than one animation needs to be done, they need to be done in order. Use a System.Collections.Generic.Queue<> for example.
 

MrSeanKon

New Member
Joined
Nov 14, 2006
Messages
267 (0.07/day)
Likes
73
Location
Athens in love with Anna :)
#6
Uh...there's absolutely no reason to use two namespaces in your case. I moved "attempt" class into the "Game" namespace, removed all references to "paixnidi" and it works fine.
Readers download the new attachment.

Namespaces are only to avoid collisions of same-named classes. For example, you might have zero-terminated String class under a network namespace while having a standard String class under a text namespace:
Text.String
Network.String

Different classes, same name.
Although I am new to OOP (object orient programming) I knew that. But I was too nervous and hurried for almost 2 days :confused: and I would to solve my issue as soon as possible. That's why I searched to many pages and this one confused me enough, because it says about static functions...
I should not hurry :D

You should only have one dispatcher handle all animations. If more than one animation needs to be done, they need to be done in order. Use a System.Collections.Generic.Queue<> for example.
Why?
What's the problem?
 

Attachments