Okay, I'm trying to convert that but I can't, first I will show You my translated code. Oryginal code is here:
http://www.sfml-dev.org/wiki/en/sources/anispriteAniSprite.C:
extern "C"
{
#include "AniSprite.h" //PAMIETAC O NAPISNIU sf_Destroyi na koncu!!!
int ZerujDane(AniSprite pedal);
int SetFrameSize(int frameW, int frameH, AniSprite pedal);
int GetFrameCount(AniSprite pedal);
sfIntRect GetFramePosition(int frame, AniSprite pedal);
int SetFrame(int frame, AniSprite pedal);
int SetLoopSpeed(float newfps, AniSprite pedal);
int PlayUstalone(int start, int end, AniSprite pedal);
int PlayZwykle(AniSprite pedal);
int Stop(AniSprite pedal);
int Update(AniSprite pedal);
//int Laduj(AniSprite pedal, int frameW, int frameH);
//int Laduj(AniSprite pedal);
}
int ZerujDane(AniSprite pedal)
{
pedal.duszek = NULL;
pedal.zdjecie = NULL;
pedal.clock = NULL;
pedal.fps = 1;
pedal.currentFrame=0;
pedal.isPlaying=false;
pedal.loopStart=0;
pedal.loopEnd=0;
pedal.frameHeight=0;
pedal.frameWidth=0;
return 1;
}
//int Laduj(AniSprite pedal, int frameW, int frameH)
//{
//pedal.zdjecie = sfImage_CreateFromFile("Character.png"); //SPRAWDZIC JESZCZE POTEm
//pedal.duszek = sfSprite_Create();
//sfSprite_SetImage(pedal.duszek, pedal.zdjecie);
//SetFrameSize(frameW, frameH, pedal);
//return 1;
//}
int SetFrameSize(int frameW, int frameH, AniSprite pedal)
{
pedal.frameWidth = frameW;
pedal.frameHeight = frameH;
sfIntRect pedal2;
pedal2.Left = 0;
pedal2.Top = 0;
pedal2.Right = frameW;
pedal2.Bottom = frameH;
sfSprite_SetSubRect(pedal.duszek,pedal2);
return 1;
}
int GetFrameCount(AniSprite pedal)
{
unsigned int across = (sfImage_GetWidth(pedal.zdjecie) / pedal.frameWidth);
unsigned int down = (sfImage_GetHeight(pedal.zdjecie) / pedal.frameHeight);
return across*down;
}
sfIntRect GetFramePosition(int frame, AniSprite pedal)
{
unsigned int across = (sfImage_GetWidth(pedal.zdjecie) / pedal.frameWidth);
unsigned int down = (sfImage_GetHeight(pedal.zdjecie) / pedal.frameHeight);
int tileY = frame / across;
int tileX = frame % across;
sfIntRect result; // MOZE ZMIENIC NA GLOBALNA ZMIENNA;
result.Left = tileX*pedal.frameWidth;
result.Top = tileY*pedal.frameHeight;
result.Right = tileX*pedal.frameWidth + pedal.frameWidth;
result.Bottom = tileY*pedal.frameHeight + pedal.frameHeight;
return result;
}
int SetFrame(int frame, AniSprite pedal)
{
pedal.currentFrame = frame;
return 1;
}
int SetLoopSpeed(float newfps, AniSprite pedal)
{
pedal.fps = newfps;
return 1;
}
int PlayUstalone(int start, int end, AniSprite pedal)
{
pedal.loopStart = start;
pedal.loopEnd = end;
pedal.currentFrame = start;
pedal.isPlaying = true;
sfClock_Reset(pedal.clock);
return 1;
}
int PlayZwykle(AniSprite pedal)
{
PlayUstalone(0, GetFrameCount(pedal), pedal); //ALBO TRZECI ARGUMENT NULL
return 1;
}
int Stop(AniSprite pedal)
{
pedal.isPlaying = false;
return 1;
}
int Update(AniSprite pedal)
{
if(pedal.isPlaying)
{
int frameCount = pedal.loopEnd - pedal.loopStart;
float timePosition = (sfClock_GetTime(pedal.clock) * pedal.fps);
pedal.currentFrame = pedal.loopStart + (int) timePosition % frameCount;
sfSprite_SetSubRect(pedal.duszek, GetFramePosition(pedal.currentFrame, pedal)); //ALBO TRZECI ARGUMENT NULL
}
return 1;
}
AniSprite.h:
#pragma once
extern "C"
{
#include <SFML/Graphics.h>
#include <SFML/Config.h>
#include <SFML/System.h>
typedef struct
{
sfImage* zdjecie;
sfSprite* duszek;
sfClock* clock;
float fps;
bool isPlaying;
int loopStart;
int loopEnd;
int currentFrame;
int frameWidth;
int frameHeight;
} AniSprite;
//int Laduj(AniSprite pedal, int frameW, int frameH);
//int Laduj(AniSprite pedal);
int ZerujDane(AniSprite pedal);
int SetFrameSize(int frameW, int frameH, AniSprite pedal);
int GetFrameCount(AniSprite pedal);
sfIntRect GetFramePosition(int frame, AniSprite pedal);
int SetFrame(int frame, AniSprite pedal);
int SetLoopSpeed(float newfps, AniSprite pedal);
int PlayUstalone(int start, int end, AniSprite pedal);
int PlayZwykle(AniSprite pedal);
int Stop(AniSprite pedal);
int Update(AniSprite pedal);
}
I'm trying to use it like that:
extern "C"
{
#include <SFML/System.h>
#include <SFML/Graphics.h>
#include <SFML/Window.h>
#include "AniSprite.h"
AniSprite test;
}
#include <iostream>
void Instaluj(sfSprite* duszek, sfImage* zdjecie, char* sciezka);
char* tabela[4] = {"natesty.jpg", "natesty2.jpg", "natesty3.jpg"};
int main()
{
ZerujDane(test);
test.clock = sfClock_Create();
test.duszek = sfSprite_Create();
test.zdjecie = sfImage_CreateFromFile("character.png");
sfSprite_SetImage(test.duszek, test.zdjecie);
//SetFrameSize(47, 64, test);
int a;
a = SetFrameSize(47, 64, test);
if (a == 1)
{
std::cout << "Nie Spierdala sie" << std::endl;
}
//Laduj(test, 47, 64);
SetLoopSpeed(60, test);
//PlayZwykle(test);
PlayUstalone(4, 7, test);
sfWindowSettings Settings = {24, 8, 0};
sfVideoMode Mode = {800, 600, 32};
sfRenderWindow* App;
sfImage* Image = NULL;
sfSprite* Sprite = NULL;
sfEvent Event;
Sprite = sfSprite_Create();
/* Create the main window */
App = sfRenderWindow_Create(Mode, "SFML Testy", sfClose, Settings);
if (!App)
return EXIT_FAILURE;
Instaluj(Sprite, Image, tabela[0]);
sfRenderWindow_SetFramerateLimit(App, 60);
/* Start the game loop */
while (sfRenderWindow_IsOpened(App))
{
//std::cout << test.frameHeight << std::endl;
//std::cout << test.frameWidth << std::endl;
/* Process events */
while (sfRenderWindow_GetEvent(App, &Event))
{
/* Close window : exit */
if (Event.Type == sfEvtClosed)
sfRenderWindow_Close(App);
}
/* Clear the screen */
sfRenderWindow_Clear(App, sfBlack);
Update(test);
/* Draw the sprite */
sfRenderWindow_DrawSprite(App, Sprite);
sfRenderWindow_DrawSprite(App, test.duszek);
/* Update the window */
sfRenderWindow_Display(App);
}
/* Cleanup resources */
sfSprite_Destroy(Sprite);
sfImage_Destroy(Image);
sfRenderWindow_Destroy(App);
return EXIT_SUCCESS;
}
Some weird problems:
It shows that
test.frameHeight and test.frameWidth == 0 but why? I called function: SetFrameSize(47, 64, test);
But it shows that SetFrameSize return 1 so it should work...
Anyway when I launch app it runs without crash(woooo before I was crashing like shit) but I can only see:

and it doesn't animate itself.
Other weird shitty problems:
If I use PlayZwykle(test) it crash and shows You devining by 0:
int GetFrameCount(AniSprite pedal)
{
unsigned int across = (sfImage_GetWidth(pedal.zdjecie) / pedal.frameWidth); HERE
unsigned int down = (sfImage_GetHeight(pedal.zdjecie) / pedal.frameHeight); HERE
return across*down;
}
I bet it's because test.frameWidth and test.frameHeight are 0 but still can't figure out why....
I know that probably noone of You give shit about C version of SFML but I really do care about it and can't figure it out, if someone could help I would be grateful.
EDIT: THE SAME HAPPENS WITH FPS SETTING NO METTER WHAT I TRY TO SET THROUGHT FUNCTION IT ALWAYS IS 0 AND COMPILER IN COME CASES SAY THAT test structure is not inicialized.
God damn it help people please.