Hello! I'm use SFML along C++ and i think it very pretty library to game dev. But i'm interested in use C binding, but i'm know C language not as good as C++ and i have few little questions. Sorry if it very stupid, but i want to understand.
So, first of all it is sfVector2f. For example, in SFML we have a choice - in sf::CircleShape of move method or setPosition method put only Vector2f:
sf::RectangleShape gun(sf::Vector2f(10.f, 50.f));
gun.setOrigin(sf::Vector2f(5.f, 45.f));
or 2 floats:
bullet.setPosition(x, y);
bullet.setOrigin(2,2);
In CSFML only sfVector2f in everywere? I forced to declared many vectors for size, for positions and other to setting my sprite or primitive:
sfVector2f vec = { 10, 10 };
sfVector2f vec2 = { 30, 30 };
// ...another many many definitions of vectors to other things in my program
sfRectangleShape_setSize(shape, vec);
sfRectangleShape_setPosition(shape, vec2);
Or exist any simple way to do it? I tryed coding like this:
sfRectangleShape_setSize(shape, (sfVector2f) {10, 10});
But i think this code is ugly.
Second question - is memory allocation to many objects in programm. For example. In C++ i use std::list array to store my objects:
std::list<Bullet *> bullet_list;
// ...
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
{
if (fireTimer.getElapsedTime().asMilliseconds() > 200)
{
Bullet *bullet = new Bullet(gun.getPosition().x,
gun.getPosition().y,
gun.getRotation());
bullet_list.push_back(bullet);
fireTimer.restart();
}
}
// ...
for (auto i=bullet_list.begin(); i != bullet_list.end();)
{
Bullet *b = *i;
// some actions with object
if (!b->life) {
i=bullet_list.erase(i);
delete b;
} else ++i;
}
So easy and no one problems. May be i bad know C, but i'm no have idea how to do some one like this in C
May be something wrong to design the program so and possible make it another? And it is possible to code applications and games in C and CSFML like a C++ and SFML? Thank you.