I am trying to write a small game, it works pretty good for now, but I need something like a collision detection and for that detection it is important to know the excat size of that unicode character(may be converted to a graphic, to work better with it, instead of using a label ?!)
I thought it would be great, to get all the coordinates of that element where it is black and leave out where it is transparent.Maybe something based on this, but I am m not quite sure wether it is a good and fast approach. By the way it is important to get the coordinates based on that canvas.
What I have so far:
The unicode characters e.g.:
"\U0001F6B5"
The element for the canvas, I could also use a graphical object:
var customLabel = new Label
{
Uid= all[i].ToString().Equals("Biker")?"Biker":"",
TabIndex = i,
Margin = new Thickness(0),
Content = all[i].Icon,//"\U0001F6B5"
BorderThickness = new Thickness(2.0),
Name = controlName,
FontSize = 22,
Padding = new Thickness(0.0, 0.0, 0.0, 0.0),
ToolTip = tooltip, //may be tooltip with real pictures from that object in real life and a "Registerkare" with all its properties(armor, power,...)
//BorderBrush = Brushes.Red //to see the size of this element
Cursor = Cursors.Hand
// FlowDirection= //use if the object moves left, right, top, butoom ?
//IsHitTestVisible= //use for collision ?
};
//Setting the position on the canvas:
Canvas.SetLeft(customLabel, xRef); //X
Canvas.SetTop(customLabel, yRef); //Y
At the moment I came up with that solution(seeing an element as a rectangle), I use it only once, when I create a random map(later the player will check against those saved positions, via "INotifyPropertyChanged" if his position changed):
for (int xx = 1; xx <= customLabel.Width; xx++)//range for object
{
for (int yy = 1; yy <= customLabel.Height; yy++)//range for object
{
coordinatesInUse.Add(new KeyValuePair<int, int>((int)xRef+xx, (int)xRef+yy));
var lookup = coordinatesInUse.ToLookup(kvp => kvp.Key, kvp => kvp.Value);
foreach (int look in lookup[1])
{
//checking wether that element exist or not
}
}
}