Posts Tagged ‘Hittest’
23
Sep

Driving Game with hit test

Post a comment » Popularity: 1%

Terence Tsang created a very basic game engine which demonstrated the followings

  1. how to change the frame of an animation
  2. keyboard interaction
  3. scrollable background
  4. hit test (interaction) on objects

Driving Game with hit test

View Demo: New Window
21
Sep

Hit Test (Get all objects in a specific point)

Post a comment » Popularity: 1%

Most of the time, when you are creating games, you will have to find out all the UIElemetn in a specific coordinate. (Or we can this hittest). In such circumstance, you will need to use the method VisualTreeHelper.FindElementsInHostCoordinates. Please view the C# coding for more details.

Hit-Test

Get all the UIElement in a specific coordinate:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;

namespace HitTest
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            App.Current.RootVisual.MouseLeftButtonDown += new MouseButtonEventHandler(RootVisual_MouseLeftButtonDown);
        }

        void RootVisual_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            List<uielement> list = VisualTreeHelper.FindElementsInHostCoordinates
            (e.GetPosition(null), LayoutRoot as UIElement) as List<uielement>;

            var selectedControls = from control in list
                                   where control is Rectangle
                                   select control as Rectangle;

            if (selectedControls.Count() &gt; 0)
            {
                foreach (var selectedControl in selectedControls)
                {
                    // do your opreation here
                }
            }
        }
    }
}
19
Sep

Explosive Bricks

Post a comment » Popularity: 1%

Nokola released a Explosive Bricks game. Bounce the ball and break all the bricks. Very simple game logic, but yet very well implemented with fancy graphics.

Explosive Bricks

14
Sep

Bouncing Elements using Render Transform

Post a comment » Popularity: 1%

Switchonthecode released a tutorial teaching you how to create bouncing animations using the combination of Render Transform (Translate Transform) and Dispatcher Timer.

Bouncing Elements using RenderTransform

View Demo: New Window