
At this lesson we will create a 2D area for our application. But we will have a problem. If someone clicks this 2D area the 3D area will lost the "focus".
The solutions is to have 2 Canvas inside an StackPanel.
The events definitions: KeyDown="OnKeyDownHandler" MouseLeftButtonDown="buttonDownHandler" MouseMove="OnMouseMove" will be not anymore in the Window tag but in the second Canvas. We need to reduce the side of this Canvas and adjust some other positions.
We need also to create a TextBox at this area having dimensions 1x1 and having the name: Fake. And at the method to capture clicks we write:
...
private void buttonDownHandler(object Sender, MouseButtonEventArgs e){
Point p = e.GetPosition(VP);
if(p.Y>100){
Fake.Focus();
}
...
And all will be OK relative to the "focus thing".If the 2D area is clicked, the user needs to click the 3D area to have "focus" on it; to move the avatar etc.
But, at this lesson we will talk also about something more funny.
We will begin to talk about the creation of games. We will use a paradigma similar to that of the "Zelda" games (a "classic" by Nintendo). A character will have some level of "Health" and "Money" that can be increased when the player finds and clicks "money bags" or "magic medicine bottles". You will find the "definition" of these pieces at the next lessons.
The exercice of this lesson has the "moneybag". The "mouseover" is enabled to it. When the user clicks it, the variable : money is increased by 100 and its new value presented at a TextBlock. Sound included. Very easy. You know everything to do it!
TIP: Pay attention to the efect of lights.
...
<!-- Lights-->
<!-- Children[0]-->
<AmbientLight Color="White" />
<!-- Children[1]-->
<DirectionalLight Color="Gray" Direction="-0.612372,-0.5,-0.612372" />
<!-- Children[2]-->
<DirectionalLight Color="Gray" Direction="0.612372,-0.5,-0.612372" />
...
Unfortunately we don't have projected shadows...
We define a DirectionalLight using a vector, like you can see for a n = 10:
For the demo, create a folder having the name of the .ZIP file and download it - right-clicking the link - and unzip inside the folder :
Liberate the firewall and play this web3d application:
![]() |
We are doing our tests at a: Notebook DELL Latitude D600 - Intel Pentium M755 2.0 GHZ - Memory: 512 MB - VideoCard ATI Radeon 9000 32MB DDR 4xAGP - Resolution 1400x1050 - Communication: ADSL 256 kbps (Download: 45 kBps, Upload: 14 kBps)
PREVIOUS LESSON NEXT LESSON T.CONTENTS HOMEPAGE
