SDL 方法,参数转换

SDL method , parameter convertion

本文关键字:转换 参数 方法 SDL      更新时间:2023-10-16

我对这种方法有一个小问题,这是我的代码(我有更多的代码,但这是给我错误的部分)

void ranCol( SDL_Surface sprite[], SDL_Rect paste)
{
        SDL_FillRect(sprite[y],NULL,temp);
        SDL_BlitSurface(sprite[y],&paste[y],rScreen(),NULL);
}

我收到 2 个错误

error C2664: 'SDL_FillRect' : cannot convert parameter 1 from 'SDL_Surface' to 'SDL_Surface *'
error C2664: 'randCol' : cannot convert parameter 2 from 'SDL_Surface *[50000]' to 'SDL_Surface []'

谁能帮我解决这个问题?

编辑:这是代码,以防有人想要复制它

    void randCol(int times, SDL_Surface* sprite[], SDL_Rect paste)
{
    int unsigned temp = 10101;//seed
    for(int y = 0;y < times;y++)
    {
        temp = temp*(y+y+1);
        temp = (temp^(0xffffff))>>2;
        //printf("%xn",temp);
        SDL_FillRect(sprite[y],NULL,temp);
        SDL_BlitSurface(sprite[y],&paste[y],rScreen(),NULL);
    }
}

您应该始终操作pointersSDL_Surface... 将函数更改为

void ranCol( SDL_Surface* sprite, SDL_Rect paste)

我不确定你的[y]从何而来! 如果它来自 SDL_Surface 数组,将单个SDL_Surface作为参数传递给函数,它会更清晰。

如果要传递项目数组,请使用以下签名:

void ranCol(SDL_Surface* sprite[], SDL_Rect paste[])

但是您仍然需要以某种方式传递y,无论是作为参数还是作为成员/全局。