首页 > 解决方案 > 绘制的正方形在指定颜色之间不断闪烁

问题描述

我对 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();了我的初始房间的创建代码。问题发生在另一个房间。

这是生成的图片,显然这张图片没有闪烁的方块。 在此处输入图像描述

如果您需要更多信息,请告诉我。

标签: graphicsgame-makergmlgame-maker-languagegame-maker-studio-1.4

解决方案


问题是我已将所有文本作为抽奖事件的一部分包含在内。所以阵列不断被重新制作。解决办法是把数组制作代码分开,在不同的事件下执行。我为此使用了创建事件。

我会提供一个详细的示例,但考虑到 GameMaker 程序的性质,这很困难,而且解决方案应该是不言自明的。


推荐阅读