【问题标题】:SDL method , parameter convertionSDL方法,参数转换
【发布时间】:2012-11-15 20:17:57
【问题描述】:

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

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("%x\n",temp);
        SDL_FillRect(sprite[y],NULL,temp);
        SDL_BlitSurface(sprite[y],&paste[y],rScreen(),NULL);
    }
}

【问题讨论】:

    标签: c++ methods sdl


    【解决方案1】:

    您应该始终将pointers 操作为SDL_Surfaces...将您的功能更改为

    void ranCol( SDL_Surface* sprite, SDL_Rect paste)
    

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

    如果您想传递一个 ARRAY 项,请使用以下签名:

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

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

    【讨论】:

    • SDL_Surface* 等于函数参数列表中的SDL_Surface[],作为数组切片到pinter。
    • 那个 [y] 是一个循环,但它不会干扰任何事情
    • @Laggy y 不在你的函数范围内,是全局的吗?
    • y 没问题,它用于for 循环
    • SDL_Surface* 工作但我仍然得到error C2664: 'randCol' : cannot convert parameter 3 from 'SDL_Rect [50000]' to 'SDL_Rect'
    猜你喜欢
    • 2014-06-21
    • 1970-01-01
    • 1970-01-01
    • 2011-08-07
    • 2013-08-25
    • 1970-01-01
    • 2012-05-10
    • 1970-01-01
    相关资源
    最近更新 更多