- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
`int[,] board = new int[6, 7]; PictureBox boardpb = new PictureBox(); PictureBox[] pb = new PictureBox[42]; 图像表,红色,蓝色; int c = 0;
public Form1()
{
InitializeComponent();
red = Properties.Resources.red; red = (Image)(new Bitmap(red, new Size(110, 110)));
blue = Properties.Resources.blue; blue = (Image)(new Bitmap(blue, new Size(110, 110)));
table = Properties.Resources.Board; table = (Image)(new Bitmap(table, new Size(700, 700)));
boardpb.Location = new Point(0, 0);
boardpb.Image = table;
boardpb.Size = table.Size;
boardpb.BackColor = Color.Transparent;
boardpb.MouseClick += new MouseEventHandler(Human_Play);
this.Controls.Add(boardpb);
}
void PlayCircle(int x, int y, Image im) //plays a red/blue circle in the corresponding (y,x) position
{
pb[c] = new PictureBox();
pb[c].Location = new Point((int)(-2 + 98.8 * x), (int)(83 + 94.4 * y));
pb[c].Image = im;
pb[c].Size = im.Size - new Size(10, 10);
pb[c].BackColor = Color.Transparent;
pb[c].MouseClick += new MouseEventHandler(Human_Play);
boardpb.Controls.Add(pb[c]);
c++;
}
int Y(int x) // gives the lowest empty space in the column, or -1 if the column is full.
{
for (int y = 5; y >= 0; y--)
if (board[y, x] == 0) return y;
return -1;
}
void Human_Play(object sender, MouseEventArgs e)
{
int x, y;
x = (Cursor.Position.X) / 99;
if ((x <= 6) && (x >= 0))
{
y = Y(x);
if (y != -1)
{
PlayCircle(x, y, red);
board[y, x] = -1;
}
}
}`
我正在使用 WinForms C# 为我的 uni 项目制作一个 connect 4 游戏。在试图让棋子落入棋盘时,它们就像在棋盘图像下方移动,将棋盘线隐藏在它们后面。知道如何使棋子图像移动到板后,但仍然可以通过板孔看到(如以下链接中的图片)吗?PS:棋盘和2张图片确实有透明背景。提前致谢^^ http://mathworld.wolfram.com/images/gifs/connect4.gif更新:我添加了代码。 (表格、红色、蓝色是我资源中的 3 张图片)如何编辑此代码,使棋子落在棋盘后面而不是突然出现?
最佳答案
你有两个选择:
FillRectangle
和 FillEllipse
绘制所有图形。我猜你正在尝试选择第二个选项。
然而,在 Winforms 中,只有嵌套 控件才支持透明度。然而,直接方法会与控件重叠,因此不起作用。
相反,您需要将底部控件嵌套在运动场中,并将上面的每一层都嵌套在下面的层中。由于您只需要在棋子上方一层,即网格,因此您必须将网格嵌套在棋子中。
这是可能的,但不是很自然,要实现这一点,您必须使该 block 足够大以容纳整个网格以及它在动画期间将占据的每个位置。因此,如果您在每次移动开始时设置它,它必须是棋盘高度及其全宽的两倍。
然后在 Timer.Tick
中将棋子向下移动并将嵌套在其中的网格向上移动,直到棋子找到它的位置。
最后将棋子绘制到棋盘PictureBox
的Image
中。使 BackgroundImage
显示相同的网格,这样您就可以在为下一步设置它之前简单地隐藏它..
因此,您可以通过在大小为 (board.width, board .height*2
) 并将其分配给 PictureBox movingPiece
。
您已经准备了一张包含网格的位图并将其指定为 PictureBox 网格
的图像。现在嵌套三个控件:
movingPiece.Parent = board;
grid.Parent = movingPiece;
在 Tick 中,你将 pice doen 和它包含的网格向上移动:
void timer1_Tick(object sender, EventArgs e)
{
movingPiece.Top++;
grid.Top--;
// if finalposition etc..
}
BackgroundImage
中创建网格。将设置好的棋子绘制到 Image
中。并在 Tick&Paint
事件中通过在重叠位置填充一个 Circle 和一个 Rectangle 来制作动画。 我愿意这样做;理解起来不是很自然,移动的像素也少得多,所以它可能也更快..
关于c# - 在另一个带有透明孔的图像后面移动图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34528440/
我的 FAB 将显示在 android studio 的设计窗口中,但在我实际运行应用程序时不会显示。 此外,我有一个 ListView 项目,我指定它应该位于工具栏下方,但当我运行该应用程序时,它部
我的Nginx服务器位于haproxy之后,后者位于Varnish之后: 请求网页=> Varnish => HaProxy => Nginx 我的问题是我无法检索客户端的IP地址,在Nginx日志中
我正在尝试在用户点击的图像上显示一些上下文信息。 我正在为此使用 vtkTextActor。我正在使用 python 绑定(bind)。 问题是因为它在图像上很难阅读,所以我想在它后面画一些背景。 (
我创建了一个 flutter 小部件,它由几个组成应用栏和选项卡的条子组成,在其下方,我有 TabBarView。 1) 选项卡和主体 ScrollView 之间有过多的填充,但我不确定是什么元素导致
当我在 Xcode 4.3.3 上运行我的 cocoa 应用程序时。使用 Lion 10.7.4。应用程序启动并出现在 Xcode 后面。前面几次出现,不知道发生了什么。有人遇到过这样的问题吗?我的主
我需要将一些文本相对于“dropzone”(div)水平和垂直居中放置。它适用于以下解决方案:Inject a text above a div centered horizontally and v
我正在尝试在列表上使用匹配的几何效果,并且至少对于详细 View 的动画来说,它的工作方式与预期的一样。问题是从详细 View 返回列表单元格的动画似乎在列表后面。 我怎样才能让它正常工作,以便详细
我正在尝试在列表上使用匹配的几何效果,并且至少对于详细 View 的动画来说,它的工作方式与预期的一样。问题是从详细 View 返回列表单元格的动画似乎在列表后面。 我怎样才能让它正常工作,以便详细
我对此有点挣扎。在对 Google 进行研究后,我创建了以下计时器例程,该例程在调用时效果良好 // play move method public static void playMove() {
我正在编写一款Android游戏,用户可以购买在购买后动态创建的建筑物。创建它们后,用户可以将它们拖放到任何想要的地方,只要它们在地面上即可。我将天空和地面作为两种不同的框架布局,但天空占据顶部的 2
我有一个包装 div,在那个 div 里面有一些带有下拉按钮的按钮,包装应该有一个最大高度和一个自动滚动。 问题是如果我点击一个按钮,现在下拉菜单总是放在包装器后面,有没有办法让下拉菜单放在包装器的顶
我在 Bootstrap 3 中有一个网站 http://213.239.217.181/carboot/ 我可能会被否决,因为人们会说你试过什么或向我们展示你试过的代码 但我已经为这个问题苦苦挣扎了
我似乎无法解决这个问题,我将标签栏高度从 viewWillLayoutSubviews() 调整为 60,但覆盖 View 似乎不承认调整后的高度并效仿. 我发现的其他类似问题实际上并不相似(请参见此
我在相对布局中有两个线性布局。每个线性布局中有三张图片。从而形成一个图片网格,其中三张图片水平放置在第一个线性布局中,三张在上面的第二个中。如下所示 我的网格 xml 代码是:
我一直试图在我的页面上获取多个背景图片,但我无法获取超过 2 个,所以我开始考虑我可以使用 div 代替。但是当我使用 div 时,我在屏幕的顶部和两侧留下了大约 5 个白色像素,直到我将位置更改为绝
我有一些关于 CSS 的问题。您可以查看以下链接: http://lookdemo.biz/webs/chirag/mickes_figurer/ 在那里,您会在文本“NYFÖDDA FIGURER”
我有一个问题,我有一个绝对定位的 div,它充当背景图像顶部的颜色叠加层。 我遇到的问题是这个绝对定位的 div 之后的所有内容都放在它后面而不是在它上面。我不太明白发生了什么事。我知道它必须简单。
我知道这是一个热门话题,但我浏览了很多论坛,但没有一个修复对我有用。我有一个下拉菜单,隐藏在我正在显示的 pdf 后面。我尝试将 pdf 设置为嵌入并将其设置为 iframe。我尝试更改 css 中的
我不确定我是否在这里遗漏了什么,但似乎我无法将图像映射放在其他所有内容之上(就 z-index 而言)。我尝试改变 HTML 元素定义的顺序,我尝试使用 CSS 来定义适当的 z-index 值,但这
我有一个使用来自 slideful.com 的 iframe 的幻灯片。 slideful 的幻灯片使用 jquery。将幻灯片放在主页上后,我在导航中添加了一个下拉菜单,它位于“slideful.c
我是一名优秀的程序员,十分优秀!