|
|
Newest Topics |
|
| |
Trigonometry is very useful when programming games. This has to do with the fact that most of the time you're calculating angles in degrees or radians, and distance between 2 points on the screen. Below I've given you a few good functions to calculate the angle of 2 points and their distance. This will help in making several kinds of game tools.
Public Class Trig Public Shared Function CalculatePointAngle(ByVal pointStart As Point, ByVal pointEnd As Point) As Double Dim dy As Double = -(pointEnd.Y - pointStart.Y) Dim dx As Double = (pointEnd.X - pointStart.X) Dim angleRadians As Double = Math.Atan2(dy, dx) If (angleRadians < 0) Then angleRadians += 2 * Math.PI End If Dim angleDegrees As Double = RadiansToDegrees(angleRadians) Return angleDegrees End Function Public Shared Function CalculatePointDistance(ByVal pointStart... Read More
|
Collision checking in programming is important especially with a Framework for a system like Silverlight where you can dynamically create, drag, & drop canvases or usercontrols randomly. You will want to be able to check to see if the canvas you dropped is overlapping the other canvas.
Here's a quick and dirty function to determine if they're overlapping in VB.Net:
Private Function Collision(ByVal oCtrl1 As UserControl, ByVal oCtrl2 As UserControl) As Boolean Dim left1 As Double = CType(oCtrl1.GetValue(Canvas.LeftProperty), Double) Dim left2 As Double = CType(oCtrl2.GetValue(Canvas.LeftProperty), Double) Dim top1 As Double = CType(oCtrl1.GetValue(Canvas.TopProperty), Double) Dim top2 As Double = CType(oCtrl2.GetValue(Canvas.TopProperty), Double) Dim collided As Boolean = Not (left1 > left2 + oCtrl2.ActualWidth Or left1 + oCtrl1.ActualWidth < left2 Or top1 > top2 + oCtrl2.ActualHeight Or top1 + oCtrl1.ActualHeight < top2) Return collided End Function
This function will return True if they overlap and False if they don't. A good practice to avoid checking all objects completely...
Read More
|
Early in the days of Silverlight, the people informing you how to do game loops were using the DispatcherTimer and the .Tick event to call the main loop of your Silverlight application. I have a previous article that showed how to convert all the available C# versions of this to VB.Net. That DispatcherTimer class is part of the System.Threading library and it does work, but a better way to do constant looping (primarily for gaming) is to use CompositionTarget.Rendering
Public Sub New() InitializeComponent()
AddHandler CompositionTarget.Rendering, AddressOf MainGameLoop
End Sub
Private Sub MainGameLoop(ByVal sender As Object, ByVal e As EventArgs)
End Sub
When you place this in your XAML page's New Sub, you are pointing to a Sub (MainGameLoop) that you want to call every time you render your composition from the last loop. The nice thing about doing this is that if you want to do a separate looping system to handle different events, you can still use the DispatcherTimer. I noticed that since Silverlight wasn't designed specifically for game programming that it can get slow in your main game loop if you've...
Read More
|
Within Silverlight, it's useful to be able to change or swap the image source of an image already set on your XAML page for multiple purposes. I for one needed to accomplish this because I'm doing some game programming that involves me putting a different armor set on a fighting warrior depending on which armor is equipped. To do this, you can go ahead and set a XAML image within your page:
<Image x:Name="myHead" Source="images/Head1.png"></Image>
From this point, within the backend code, you would think that you could simply change the Source property of that object, but you can't. The Source property is actually a System.Windows.Media element that is being pre-rendered in your XAML build for you automatically. To change the source of your file, you actually need to do it like this:
Dim myUri As New Uri("images/Head2.png", UriKind.Relative) Dim img As ImageSource = New System.Windows.Media.Imaging.BitmapImage(myUri) myHead.SetValue(Image.SourceProperty, img)
In this, we're using the URI object to tell the system where to get this resource from, setting it as a new image source and then using the SetValue property to apply the image SourceProperty to the...
Read More
|
Fixing Error: Unhandled Error in Silverlight 2 Application Code: 2104 Category: Initializer Error Message: Could not download the Silverlight application. Check web server settings.
When you're hosting Silverlight, you have to tweak your IIS6 or Appache settings to allow the server to know how to handle the extensions that it's not familiar with. I'm sure in the future, Microsoft will encode this directly into new releases of IIS, but for now, you have to add these MIME types yourself.
.xaml application/xaml+xml .xap application/x-silverlight-app .xbap application/x-ms-xbap
To add the MIME types to IIS6:
1. Choose the Virtual Directory or Default Web Site in IIS 2. Open the context menu and choose "Properties" 3. Select the "HTTP-Headers" tab 4. Click the button labeled "File Types..." in MIME Map section 5. Choose "New Type" and type the extension from above into the extension field and the application type into the MIME type field. 6. After adding all 3, click "OK" then click "Apply" on the main menu. You're done. No restart needed.
To do this in Apache 2.2: Using mod_rewite or mod_mime with AddType
1. Open httpf.conf in your favorite text editor 2. Search for <IFModule mime_module> 3. Add AddType application/xaml+xml .xaml + all the other...
Read More
|
Recently I have had to do some Javascript date manipulation and ran into the issue of formatting my results correctly. You aren't granted the diverse and flexible tools for working with dates in Javascript as you are in the .NET environment, however Javascript does expose alot of functionality for manipulating dates.
getYear()
My initial look into solving my problem naturally brought me to the GetYear() function, which was supposed to return the year in the two digit format that I needed. This posed a few problems:
1) It only returns two digit dates for dates between 1900 and 2000, which leads to the larger issue...
2)The whole Y2K doomsday scenario is illustrated by this function! Two digits by default is a bad idea, as one can see now.
The new and correct way to handle this involes using...
getFullYear()
This function completely eliminates the Y2K problem by returning 4-digit years. What if we need to have a 2 digit year? To accomplish this, we can utilize some of JavaScript's string manipulation functionality.
First, we need to grab an instance of a date:
var curDate = new Date();
Once we have this instance, we can extract a variety of information from it by invoking methods of the date object.
For...
Read More
|
When attempting to step through an application, you may receive an error message such as -
The following module was built with optimizations enabled or without debug information:
{Path to DLL}
To debug this module, change its project build configuration to Debug mode. To supress this message, disable the 'Warn if no user code on launch' debugger option.
At this point you may confirm the prompt and your application will continue to load as normal. It will, however, ignore any debugging instructions you have givin it, such as breakpoints. This is the result of the way the code was built, and there are two approaches to solve it:
1 - Ignore the message...
To simply make this prompt no longer appear, you can do the following:
Go to Tools --> Options --> Debugging --> General
At this point, unselect 'Enable Just My Code (Managed Only)'.
This should now rid you of the prompt.
2 - Allow Debugging...
Due to the nature in which one of the assemblies has been built in your application, you will need to change a few settings to allow the code to be handled by the Visual Studio Debugger.
Right click on any project in question from the solution explorer and select 'Properties'. This will open up...
Read More
|
When you first load Visual Studio on your computer, you are given an environment selection by default to choose from. If you're a VB programmer, the likelyhood is that you chose Visual Basic on the environment list rather than just choosing default. This causes the interface to revert to the way Undo & Redo were handled in VB6 which ironically was not Ctrl+Z and Ctrl+Y. Ctrl+Z certainly does undo, but it looks for Shift+Alt+Backspace for the Redo command. For those of us who are familiar with all other Windows programs like Office, we automatically hit Ctrl+Y to Redo when we undid too much. This poses a problem in Visual Studio under the VB environment because when you accidently try to Redo with Ctrl+Y, it deletes the current line entirely (formerly called Yank Line). Unfortunately, once you've done that, you've lost your entire Redo sequence and will have to retype everything.
To fix this, you simply go to Tools -> Options -> Environment -> Keyboard and set the keyboard mapping scheme to (Default) instead of Visual Basic. Click the Reset button and it takes effect immediately. You can then use Ctrl+Z and Ctrl+Y...
Read More
|
How to fix "Application attempted to perform an operation not allowed by the security policy. To grant this application the required permission, contact your system administrator, or use the Microsoft .Net Framework Configuration tool." error.
This error usually occurs on a network when you have an executable application that you're trying to run from your local computer across the network. The security settings for your local computer are to blame, and not the server.
To fix this error, you will need to do exactly as the error says and go to the .Net Framework Configuration tool in Control Panel > Administrative Tools > .Net Framework X.X Configuration > Runtime Security Policy > Adjust Zone Security.
From here, you will make changes to the computer or the user depending on your desire for security, click on the Local Intranet and adjust the slider bar to Full Trust. By default, it's one notch off that. After changing it, hit next, verify, and then Finish. Now try running your application across the network again, and it should work fine.
The only stipulation for this process is that the local computer will have to have the .Net Framework version installed. This can...
Read More
|
In one of my current projects I am faced with very long running web service calls to a third party service. In the ASP.NET web environment in which I am working in, this raises some questions and issues with performance, timeouts, and the general user experience. Each of these are major topics in their own right, but one thing that can really help you drill down and debug your long running processes and calls is to time their execution. There are many sophisticated methods to do this (including commericial products). To get a general idea this is unnecessary - we can simply use the built in .NET capabilities to build a basic code execution timer.
Timing Code
For our simple timer, we will not worry about the fidelity and resolution of time. To start, lets make use of the common .NET classes DateTime and Timespan. DateTime exposes a structure that represents time, while Timespan exposes a structure for working with time intervals. This is an important disctintion because you cannot simply do calculations on DateTime objects.
First, lets store the exact moment we begin our execution time:
dim startTime as DateTime = DateTime.Now
At this point, we have the starting point; lets now begin...
Read More
|
|
|
|
|
|
|
|
About StellarPC.com |
|
| |
StellarPC.com is a new, free, tech community where we encourage intelligent
discussion of programming techniques, website development, troubleshooting, and
many other areas of I.T. functions.
More about us...
Donate to help us out
|
|
|
|
|
|
|