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.


Messages - BIOS

Pages: [1]
1
C / Re: Create a double array of sfSprite
« on: February 27, 2018, 04:48:42 pm »
So you just want a classic 1D array.

sfSprite** sprites;

sprites = malloc(3 * sizeof(sfSprite*));
sprites[0] = ...;
sprites[1] = ...;
sprites[2] = ...;

Note that this is basic C stuff, so maybe you should spend more time learning C before trying to do more complicated things.

I know it just basic stuff in C. But in basic C we just use pointer of char, void and int and the sfSprite type do not exist. I know that the sfSprite is a structure create for sfml and I thought It would be different. And I already try that. Check my first message I show you what I have tried. I have try exactly the same thing but it don't work.

Sorry it's been a year that im learning c.

Found the solution thank you everyone. I just changed my malloc from:
malloc(sizeof(sfSprite) * n); to
malloc(sizeof(*sprite) * n)
And it work now


Envoyé de mon iPhone en utilisant Tapatalk

2
C / Create a double array of sfSprite
« on: February 27, 2018, 04:40:00 pm »
So you just want a classic 1D array.

sfSprite** sprites;

sprites = malloc(3 * sizeof(sfSprite*));
sprites[0] = ...;
sprites[1] = ...;
sprites[2] = ...;

Note that this is basic C stuff, so maybe you should spend more time learning C before trying to do more complicated things.

I know it just basic stuff in C. But in basic C we just use pointer of char, void and int and the sfSprite type do not exist. I know that the sfSprite is a structure create for sfml and I thought It would be different. And I already try that. Check my first message I show you what I have tried. I have try exactly the same thing but it don't work.

Sorry it's been a year that im learning c.

3
C / Re: Create a double array of sfSprite
« on: February 27, 2018, 12:53:15 pm »
A sfSprite* is usually one sprite (because CSFML internally allocates instances dynamically, and therefore returns/takes pointers). So sfSprite** would be a 1-dimensional array. A 2-dimensional array would be sfSprite***. Figure out this stuff an you'll have half of the problem solved. To solve the other half, you'll have to tell us what you want to do, not with C types but with real words, so that it is not ambiguous ;)

Thank you for replying me first. What i want to do is a burger maker gamer. Basically when the player press a button for example a steak appears on the screen. So when the player press the button i create a new sprite give it a texture and display it. But if he press the button again a new sprite is create on the top of the old one. So to store all those sprite I need to store them somewhere in a array of sprites. So i can access to my sprites


Envoyé de mon iPhone en utilisant Tapatalk

4
C / Re: Create a double array of sfSprite
« on: February 27, 2018, 11:45:16 am »
What's a double array?

I mean by a double array a sfSprite **
Same as char **
Inside a char ** you can store char *
I want to do the same store multiple sfSprite * in a sfSprite **. I would like to know if their is a way to store multiple sprite so i can access them more easly.


Envoyé de mon iPhone en utilisant Tapatalk

5
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.

6
C / Re: Texture how to load area image
« on: August 21, 2017, 10:48:11 am »
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);

 


 

7
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]