Hello the community, I have a little problem. I don't know the structure to load a specific area in a texture.
Look at my code:
#include <SFML/Audio.h>
#include <SFML/Graphics.h>
#include <SFML/Config.h>
#include <stdlib.h>
#include "my.h"
int map_creation(sfRenderWindow* window)
{
sfTexture* mtexture;
sfTexture* ptexture;
sfSprite* map;
sfSprite* player;
sfEvent event;
mtexture = sfTexture_createFromFile("map1.png", NULL);
if(!mtexture)
return EXIT_FAILURE;
map = sfSprite_create();
sfSprite_setTexture(map, mtexture, sfTrue);
//In here im not sure about the stIntRect(10, 10, 32, 32)
ptexture = sfTexture_createFromFile("sprite.png", sfIntRect(10, 10, 32, 32));
if (!ptexture)
return EXIT_FAILURE;
player = sfSprite_create();
sfSprite_setTexture(player, ptexture, sfTrue);
while (sfRenderWindow_isOpen(window))
{
sfRenderWindow_clear(window, sfBlack);
sfRenderWindow_drawSprite(window, map, NULL);
sfRenderWindow_display(window);
while (sfRenderWindow_pollEvent(window, &event))
{
if (event.type == sfEvtClosed)
sfRenderWindow_close(window);
}
}
return (0);
}
The console says :
gcc -o tekadventure main.c tekadventure.c -W -Wall -Werror -lcsfml-graphics -lcsfml-audio -lm libmy.a
tekadventure.c: In function ‘map_creation’:
tekadventure.c:30:53: error: expected expression before ‘sfIntRect’
ptexture = sfTexture_createFromFile("sprite.png", sfIntRect(10, 10, 32, 32));
^
Makefile:26: recipe for target 'tekadventure' failed
make: *** [tekadventure] Error 1
I know I did not write it the right way, I tried to look at SFML c++ and adapt it to the CSFML API but is not working.
Thank you in advance.