如何为随机生成的每个矩形(区域)添加相同的图片 [英] how to add the same picture for every rectangle (area) generated randomly
本文介绍了如何为随机生成的每个矩形(区域)添加相同的图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是编码的初学者,我正在制作一个游戏,其中一个角色正在捕捉随机生成的一些点。
现在我需要每个点都是一个图像(相同的图像为所有),但我不知道该怎么做。
这是我所做的一件事:
Hi, i am a beginner at coding, and i am making a little game where a character is capturing some dots generated randomly.
Now i need each dot to be an image (same image for all), but i cant find out how to do it.
This is a piece of what I did:
Rectangle[] rects;
rects = new Rectangle[10];
Bitmap background;
Graphics scG;
public Rectangle[] makerect()
{
Random r = new Random();
for (int i = 0; i < rects.Length; i++)
{
rects[i] = new Rectangle(r.Next(0,this.Width),r.Next(0,this.Height),10,10);
}
return rects;
}
public Bitmap Draw()
{
scG.FillRectangles(Brushes.Gold, rects);
return background;
}
如果有人可以帮我处理一些代码行,我会很感激: )
If anyone can help me with some lines of code, I''d appreciate it :)
推荐答案
假设您的代码正常工作 - 只需将scG.FillRectangles更改为(循环)调用scg.DrawImage ...
assuming your code is working - just change the scG.FillRectangles to (a looped) call to scg.DrawImage ...
这篇关于如何为随机生成的每个矩形(区域)添加相同的图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文