CSFML 意外的重复纹理行为

标签 c graphics sprite sfml

我正在开发一个 CSFML 2d 跑酷游戏项目,想要实现一些视差来给玩家一种速度感。为此,我希望通过 sfTexture_setRepeated 重复一些 Assets ,但可惜。它不会重复它们,而是将它的边界像素扩展到我出于某种我不知道的原因设置的 sprite 矩形的大小。

以下是关于我正在尝试做的事情的片段:

runner_objects.h

included in runner_objects.c

typedef enum {
    PLAYER      ,
    OBSTACLE    ,
    BACKGOUND1  ,
    BACKGOUND2  ,

    OBJ_COUNT
} objtype_t;

static const char *texture[OBJ_COUNT] = {
        "res/undefined.png"     ,
        "res/undefined.png"     ,
        "res/bg_clouds.png"     ,
        "res/bg_mountain.tga"   ,
};

static const sfIntRect rect[OBJ_COUNT] = {
        {0,         0,          0,          0}          ,
        {0,         0,          0,          0}          ,
        {0,         0,          1920*3,     1080}       ,
        {0,         0,          1920*2,     1080}       ,
};

typedef struct object {
    // Properties
    objtype_t       type;
    sfTexture       *texture;
    sfSprite        *sprite;
    sfIntRect       rect;
    sfVector2f      pos;

    // Linked listing
    struct object   *next;
} obj_t;

runner_objects.c

// Macros like TE_CREATE etc are simply CSFML functions made
// shorter to respect a strict 80 columns limit.
// TE_ = sfTexture, S_ = sfSprite

...
obj_t *object_create (objtype_t type, sfVector2f pos)
{
    obj_t *new_obj = malloc(sizeof(obj_t));

    if (!new_obj)
        return NULL;
    new_obj->texture        = TE_CREATE_WHOLE(texture[type]);
    new_obj->sprite         = S_CREATE;
    if (!new_obj->texture || !new_obj->sprite)
        return object_destroy(&new_obj); // Destroys existing parts and returns NULL
    new_obj->type           = type;
    new_obj->rect           = rect[type];
    new_obj->pos            = pos;
    S_SETTEXTURE(new_obj->sprite, new_obj->texture);
    if (type == BACKGOUND2 || type == BACKGOUND1)
        TE_SETREPREATED(new_obj->texture, true);
    S_SETINTRECT(new_obj->sprite, new_obj->rect);
    S_SETPOS(new_obj->sprite, new_obj->pos);
    new_obj->next           = NULL;
    return new_obj;
}
...

runner_env.c

Where I setup the game environment

...
// This function is called by int env_create(env_t **env) which is called
// from my main with the address of my env struct pointer.
int env_create_background(env_t **env)
{
    (*env)->objects = object_create(BACKGOUND2, (sfVector2f) {0 , 0});
    if (!(*env)->objects)
        return mr_puterr(ERR_CREABG); // Puts an error string on STDERR and returns corresponding error code
    (*env)->objects->speed = (sfVector2f) { 0, 0 };
    (*env)->objects->next = object_create(BACKGOUND1, (sfVector2f) {0 , 0});
    if (!(*env)->objects->next)
        return mr_puterr(ERR_CREABG);
    (*env)->objects->next->speed = (sfVector2f) { 0, 0 };
    return NO_ERR;
}
// I know it's very ugly and I'll make an actual linked
// list constructor later this is just for testing for now.
...

如果你好奇的话,我的 env_t 结构包含这些。

typedef struct environment {
    sfRenderWindow      *window;
    sfClock             *clock;
    sfEvent             *evt;
    obj_t               *objects;
} env_t;

现在对这个问题进行直观的解释。

这是我得到的屏幕截图。 Not the kind of clouds I expected.

那我做错了什么?我错过了什么 ?有没有我可能搞砸的设置方法或命令?

最佳答案

好吧,我只是个白痴,我让我的 TE_SETREPEATED 宏使用了 sfTexture_setSmooth。我觉得很蠢。

关于CSFML 意外的重复纹理行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53798242/

相关文章:

c# - .NET 中的动画效果?

opengl-es - OpenGL ES 2.0 中的纹理点?

CSS Sprite 背景不移动

c++ - atoi() 用于 int128_t 类型

c++ - 使用选项卡制作程序

c - 如何在 printf 中处理 '\0'?

r - 绘制由 R 中的方程给出的曲线

c - 将指针传递给嵌套函数

java - 用 Java 制作动画的最佳方式?

javascript - Crafty.js 无法识别与其他实体的碰撞