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.
Thank you for your answer. I am using C binding because I am new to programming and the first language that I am learning is C.
I did initialize the structure like below but I'm not sure how to use it in the function sfTexture_createFromFile().
And the documentation doesn't say much about it.
My example:
#include <SFML/Audio.h>
#include <SFML/Graphics.h>
#include <SFML/Config.h>
#include <stdlib.h>
#include "my.h"
struct sfIntRect {
int left;
int top;
int width;
int height;
};
int map_creation(sfRenderWindow* window)
{
sfTexture* ptexture;
sfSprite* player;
sfEvent event;
#This line
ptexture = sfTexture_createFromFile("sprite.png", 10, 10, 32, 32);
if (!ptexture)
return EXIT_FAILURE;
player = sfSprite_create();
sfSprite_setTexture(player, ptexture, sfTrue);