gpt4 book ai didi

c# - 获取所有黑色像素及其在我的 Canvas 上的位置?

转载 作者:太空宇宙 更新时间:2023-11-03 15:35:45 25 4
gpt4 key购买 nike

我正在尝试编写一个小游戏,它目前运行良好,但我需要类似碰撞检测的东西,对于该检测,知道该 unicode 字符的 excat 大小很重要(可以转换为图形, 更好地使用它,而不是使用标签 ?!)

我认为如果能够获取该元素的所有黑色坐标并忽略其透明部分会很棒。也许基于 this 的东西,但我不太确定这是否是一种快速有效的方法。顺便说一下,根据 Canvas 获取坐标很重要。

我目前拥有的:

Unicode 字符例如:

"\U0001F6B5"

Canvas 的元素,我也可以使用图形对象:

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

目前我想到了那个解决方案(将元素视为矩形),我只使用它一次,当我创建随机 map 时(稍后玩家将通过“INotifyPropertyChanged”检查那些保存的位置,如果他的位置改变了):

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
}
}
}

最佳答案

创建一个由多边形(矩形)、x 坐标和 y 坐标组成的自定义类。然后 List 将是您的元素集合,x 和 y 坐标放在一起。不必每次都创建一个新的键值对,您可以使用相同的集合并根据需要更改值。

关于c# - 获取所有黑色像素及其在我的 Canvas 上的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31933161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com