graphics - 绘制的正方形在指定颜色之间不断闪烁
问题描述
我对 GameMaker 1.4 非常陌生,但我对 Python 和 C++ 有一些经验。我创建了一个介于 1 到 5 之间的随机整数矩阵,以表示地图上每个建筑物的楼层数。我想用它来绘制一组 10x10 的正方形,其中较浅的灰色正方形代表较高的建筑物。不幸的是,我无法让方块保持相同的颜色。它们不断在颜色之间闪烁。
我怎样才能让它们停止闪烁并适当地表示它们的相关值?
这是我的脚本:
// Random 2D Map Height Generator
/*
Generates a matrix which is used for determining
the amount of stories per building in the game.
Then draws squares of different colors to represent
the number of stories of each building.
*/
ct = irandom(1);
// create array
for (i = 0; i <= global.height; i += 1) {
for (j = 0; j <= global.width; j += 1) {
mapArray[i, j] = irandom_range(1, 5);
if (ct % 2 != 0 && mapArray[i, j] < 5) {
mapArray[i, j] += 1;
}
ct += 1;
}
}
// make colors
one = make_color_rgb(0, 0, 0);
two = make_color_rgb(51, 51, 51);
three = make_color_rgb(102, 102, 102);
four = make_color_rgb(153, 153, 153);
five = make_color_rgb(204, 204, 204);
// initialize coordinates
ex = 300;
wy = 100;
// count columns
// draw map
for (i = 0; i <= global.height; i += 1) {
for (j = 0; j <= global.width; j += 1) {
ex2 = ex + 30;
wy2 = wy + 30;
switch (mapArray[i, j])
{
case 1:
draw_set_color(one);
break;
case 2:
draw_set_color(two);
break;
case 3:
draw_set_color(three);
break;
case 4:
draw_set_color(four);
break;
case 5:
draw_set_color(five);
break;
default:
draw_text(200, 200,
"ERROR: scr_mapGeneration, case not met");
break;
}
draw_rectangle(ex, wy, ex2, wy2, false);
ex += 33;
if (j == global.width) {
wy += 33;
ex = 300;
}
}
}
我用draw事件在一个对象中调用它并用它执行这段代码:
script_execute(scr_mapGeneration);
我调用randomize();
了我的初始房间的创建代码。问题发生在另一个房间。
如果您需要更多信息,请告诉我。
解决方案
问题是我已将所有文本作为抽奖事件的一部分包含在内。所以阵列不断被重新制作。解决办法是把数组制作代码分开,在不同的事件下执行。我为此使用了创建事件。
我会提供一个详细的示例,但考虑到 GameMaker 程序的性质,这很困难,而且解决方案应该是不言自明的。
推荐阅读
- solr - Solr 为每个字母更改返回不同的结果
- tfs - 如何将 WIT 从一个集合迁移到另一个集合?
- android - 如何从 datepickerdialog 中获取值
- sql - SQL:从第一次出现到接下来的五分钟计算某个值的出现次数,并为下一次出现重复相同的值
- c++ - 用空白填充二维数组(来自文件的输入)
- c# - 将图像转换为二进制以存储在 asp.net 的数据库中
- java - 有什么方法可以屏蔽在运行时进入 jText 区域的值
- python - Tornado RequestHandler 参数化
- python - 使用请求使 Raspberry Pi 自动将文件上传到服务器
- list - 尝试在 Future 上使用数组方法“折叠”
- 获取商品的总价