Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C、 SDL:错误:无法转换';SDL#U表面*';至';SDL_表面*(*)[15]_C_Sdl - Fatal编程技术网

C、 SDL:错误:无法转换';SDL#U表面*';至';SDL_表面*(*)[15]

C、 SDL:错误:无法转换';SDL#U表面*';至';SDL_表面*(*)[15],c,sdl,C,Sdl,所以我正在编写一个代码,用一张曲面表填充屏幕;代码如下: main.c #ifdef __cplusplus #include <cstdlib> #else #include <stdlib.h> #endif #include <SDL/SDL.h> #include <SDL_image.h> #include "maploader.h" #define W 510 #define H 510 #define SIZE 34 void

所以我正在编写一个代码,用一张曲面表填充屏幕;代码如下:

main.c

#ifdef __cplusplus
#include <cstdlib>
#else
#include <stdlib.h>
#endif

#include <SDL/SDL.h>
#include <SDL_image.h>
#include "maploader.h"

#define W 510
#define H 510
#define SIZE 34

void pause();

int main ( int argc, char** argv )
{
    SDL_Surface *screen = NULL;
    SDL_Surface *surfaces[15][15];



    SDL_Init(SDL_INIT_VIDEO);
    screen = SDL_SetVideoMode(W, H, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
    SDL_WM_SetCaption("demon game", NULL);
    SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
    mapload(screen, surfaces[15][15], NULL);

    SDL_Flip(screen);
    pause();
    SDL_QUIT;
    return EXIT_SUCCESS;
}


void pause()
{
    int continuer = 1;
    SDL_Event event;

    while (continuer)
    {
        SDL_WaitEvent(&event);
        switch(event.type)
        {
            case SDL_QUIT:
            continuer = 0;
        }
    }
}
\ifdef\uuucplusplus
#包括
#否则
#包括
#恩迪夫
#包括
#包括
#包括“maploader.h”
#定义W510
#定义h510
#定义尺寸34
无效暂停();
int main(int argc,字符**argv)
{
SDL_表面*屏幕=空;
SDL_曲面*曲面[15][15];
SDL_Init(SDL_Init_视频);
屏幕=SDL_设置视频模式(W、H、32、SDL_表面| SDL_双BUF);
SDL_WM_SetCaption(“恶魔游戏”,空);
SDL_FillRect(屏幕,NULL,SDL_映射RGB(屏幕->格式,255,255));
mapload(屏幕,曲面[15][15],空);
SDL_翻转(屏幕);
暂停();
SDL_退出;
返回退出成功;
}
无效暂停()
{
int continuer=1;
SDL_事件;
while(continuer)
{
SDL_WaitEvent(&event);
开关(事件类型)
{
案例SDL_退出:
continuer=0;
}
}
}
maploader.c

#ifdef __cplusplus
#include <cstdlib>
#else
#include <stdlib.h>
#endif

#include <SDL/SDL.h>
#include <SDL_image.h>
#define W 510
#define H 510
#define SIZE 34



SDL_Surface *surfaces[15][15];


void mapload(SDL_Surface *screen, SDL_Surface *surfaces[][15], int lvl)
{
    FILE *level = NULL;
    char elements[125];
    int i, j, k = 0;
    SDL_Rect elementposition = {0,0};


    level = fopen("level.txt", "r");
    if (level == NULL)
    {
        exit(0);
    }
    fgets(elements, 125, level);
    SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
    for (i=0; i<15; i++)
    {
        for (j=0; j<15; j++)
        {
            if (elements[k] == "0")
            {
                surfaces[i][j] = IMG_Load("mur.jpg");
            }
            else if (elements[k] == "1")
            {
                surfaces[i][j] = IMG_Load("caisse.jpg");
            }
            else if (elements[k] == "2")
            {
                surfaces[i][j] = IMG_Load("objectif.png");
            }
            else
            {
                surfaces[i][j] = NULL;
            }
            k++;

        }

    }

    for (i=0; i<15; i++)
    {
        for (j=0; j<15; j++)
        {
            SDL_BlitSurface(surfaces[i][j], NULL, screen, &elementposition);
            elementposition.x += SIZE;
        }
        elementposition.y += SIZE;
    }




}
\ifdef\uuucplusplus
#包括
#否则
#包括
#恩迪夫
#包括
#包括
#定义W510
#定义h510
#定义尺寸34
SDL_曲面*曲面[15][15];
无效贴图加载(SDL_曲面*屏幕,SDL_曲面*曲面[][15],内部层)
{
文件*level=NULL;
字符元素[125];
int i,j,k=0;
SDL_Rect elementposition={0,0};
level=fopen(“level.txt”、“r”);
如果(级别==NULL)
{
出口(0);
}
fgets(元素,125,级别);
SDL_FillRect(屏幕,NULL,SDL_映射RGB(屏幕->格式,255,255));
对于(i=0;i

应该是

mapload(screen, surfaces, NULL);
但是现在你应该问问自己,如果你当时不知道的话

  • void mapload(SDL_Surface*屏幕,SDL_Surface*surfaces[][15],int lvl)的签名
    完全错误
  • 您需要研究什么是数组以及它们与指针的关系

请注意,
surfaces[15][15]
表示第16个指针数组的第16个元素,因为您只分配了其中的15个指针,所以这些指针都不存在。因此,您需要了解中的数组,它们是如何分配的,以及如何拥有动态数组

此外,您告诉编译器函数需要一个数组的事实在此类函数中并不十分相关,因此语法
SDL_Surface*surfaces[][15]
对于c程序员来说似乎很奇怪


最后,由于
surfaces
是一个全局变量,您不需要将其作为参数传递,但您应该问问自己,它应该是一个全局变量吗?

表达式
surfaces[15][15]<代码> >从<代码>表面<代码>中获取第十六个数组的第十六个元素。我建议您获取和重读指针和数组的章节。无关,但甚至不尝试编写有效的C和有效C++的源文件……这里没有什么可获得的,但很多都是松散的。<代码>以两种语言都可用的方式创建界面。
surfaces[15][15]
is 1.)超出范围2.)标量类型
mapload(screen, surfaces, NULL);