我正在創建一個名爲「ID1000」類型爲「地圖」的對象。該對象包含一個成員「Platforms [] []」。平臺[] []是一個二維數組。爲什麼這個會員的價值在變化?
class Maps{
int Platforms[][4]
} ID1000;
ID1000.Platforms[0][0] = 100;
這裏我設平臺[0] [0]到100 但是,當我執行這行代碼...
al_draw_textf(font18, al_map_rgb(255, 0, 255), 5, 5, 0, "TargetY: %f", 800 - TargetY);
OBJECT_NAME [0] [0]突然改變從100到1065353216.這一行僅僅是2d圖形庫Allegro的一個功能,它將文本繪製到窗口上。我不能爲了我的生活找出爲什麼它完全與我的成員的價值有關。
請,如果您有任何意見或建議,我將不勝感激。
以下是完整的程序...
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include <math.h>
#include <iostream>
const int WIDTH = 1000;
const int HEIGHT = 800;
class Maps {
public:
int NumPlat;
int MapWidth;
int Platforms[][4];
};
int main(int argc, char **argv)
{
Maps ID1000;
ID1000.Platforms[0][0] = 100;
ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_FONT *font18;
float TargetY = 0;
if(!al_init())
return -1;
display = al_create_display(WIDTH, HEIGHT);
if(!display)
return -1;
al_install_keyboard();
al_init_image_addon();
al_init_font_addon();
al_init_ttf_addon();
al_init_primitives_addon();
font18 = al_load_font("BALTH___.ttf", 18, 0);
std::cout << ID1000.Platforms[0][0];
al_draw_textf(font18, al_map_rgb(255, 0, 255), 5, 5, 0, "TargetY: %f", 800 - TargetY); //display horizontal position on screen
std::cout << ID1000.Platforms[0][0];
al_destroy_font(font18);
return 0;
}
非常感謝。這解決了它。問題是,我需要Platforms [] []來改變每個對象的大小。這就是爲什麼我留下一個未定義的維度,希望它能起作用。我想現在我會研究如何做到這一點。 –