Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - BIOS

Pages: [1]
1
C / Create a double array of sfSprite
« on: February 26, 2018, 09:51:15 pm »
Hello, Im wondering if we could create a double array of sprite.

I tried something like this:
sfSprite *sprite[3];
sprite = malloc(sizeof (sfSprite *) * 3);
sprite[0] = my_sprite create("Document/image/image.png");
sprite[1] = my_sprite create("Document/image/image.png");
sprite[2] = my_sprite create("Document/image/image.png");
sfRenderWindow_drawSprite(window, sprite[0], NULL);

I tried a lot of otherways but it don't work. I would like to know if it's possible.

2
C / Texture how to load area image
« on: August 20, 2017, 02:57:02 pm »
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.

Pages: [1]
anything