1
C / I want to make my cursor
« on: November 24, 2017, 11:20:55 am »int main ()
{
//Initialisation des variables
sfRenderWindow *window;
sfVideoMode video_mode;
sfTexture *texture;
sfSprite *sprite;
sfTexture *texture2;
sfSprite *cursor;
sfTexture *texture1;
sfSprite *sprite1;
sfIntRect rect;
sfEvent event;
sfVector2f duck_vector;
duck_vector.x = 0;
duck_vector.y = randnum();
sfVector2f invers_duck;
invers_duck.x = -1;
invers_duck.y = 1;
sfClock *clock; //Variable du temps
sfTime time;
float seconds;
clock = sfClock_create();
//Taille de la fenetre
video_mode.width = 1280;
video_mode.height = 769;
video_mode.bitsPerPixel = 32;
//Attribution des valeurs au rectangle
rect.top = 0;
rect.left = 0;
rect.width = 110;
rect.height = 769;
//Creation du background
texture = sfTexture_createFromFile("background.png", NULL);
sprite = sfSprite_create();
//Creation du canard
texture1 = sfTexture_createFromFile("spritesheet.png", NULL);
sprite1 = sfSprite_create();
sfSprite_setPosition(sprite1, duck_vector);
//Creation de la fenetr + curseur
window = sfRenderWindow_create(video_mode, "Duck Hunt", sfDefaultStyle, NULL);
sfWindow_setMouseCursorVisible(window, sfFalse);
texture2 = sfTexture_createFromFile("mire.png", NULL);
cursor = sfSprite_create();
sfSprite_setTexture(sprite, texture, sfTrue);
sfSprite_setTexture(sprite1, texture1, sfTrue);
sfSprite_setTexture(cursor, texture2, sfTrue);
sfSprite_setTextureRect(sprite1, rect);
sfVector2i cursor_coord;
cursor_coord.x = 1280;
cursor_coord.y = 769;
sfMouse_setPosition(cursor_coord, window);
//Affichage de la fenetre + sprites
while (sfRenderWindow_isOpen(window)) {
time = sfClock_getElapsedTime(clock);
seconds = time.microseconds / 2500000.0;
if (seconds > 0.10) {
if (rect.left == 220)
rect.left = 0;
else
rect.left += 110;
sfSprite_setTextureRect(sprite1, rect);
sfClock_restart(clock);
}
sfSprite_move(sprite1, duck_vector);
while (sfRenderWindow_pollEvent(window, &event)) {
if (event.type == sfEvtMouseMoved) {
}
if (event.type == sfEvtClosed)
sfRenderWindow_close(window);
}
sfSprite_setPosition(sprite1, duck_vector);
if (sfSprite_getPosition(sprite1).x >= 1200) {
invers_duck.x = -invers_duck.x;
sfSprite_scale(sprite1, invers_duck);
}
if (sfSprite_getPosition(sprite1).x < -10) {
invers_duck.x = -invers_duck.x;
sfSprite_scale(sprite1, invers_duck);
}
sfRenderWindow_drawSprite(window, sprite, NULL);
sfRenderWindow_drawSprite(window, sprite1, NULL);
sfRenderWindow_drawSprite(window, cursor, NULL);
sfRenderWindow_display(window);
}
sfRenderWindow_destroy(window);
return (0);
}
{
//Initialisation des variables
sfRenderWindow *window;
sfVideoMode video_mode;
sfTexture *texture;
sfSprite *sprite;
sfTexture *texture2;
sfSprite *cursor;
sfTexture *texture1;
sfSprite *sprite1;
sfIntRect rect;
sfEvent event;
sfVector2f duck_vector;
duck_vector.x = 0;
duck_vector.y = randnum();
sfVector2f invers_duck;
invers_duck.x = -1;
invers_duck.y = 1;
sfClock *clock; //Variable du temps
sfTime time;
float seconds;
clock = sfClock_create();
//Taille de la fenetre
video_mode.width = 1280;
video_mode.height = 769;
video_mode.bitsPerPixel = 32;
//Attribution des valeurs au rectangle
rect.top = 0;
rect.left = 0;
rect.width = 110;
rect.height = 769;
//Creation du background
texture = sfTexture_createFromFile("background.png", NULL);
sprite = sfSprite_create();
//Creation du canard
texture1 = sfTexture_createFromFile("spritesheet.png", NULL);
sprite1 = sfSprite_create();
sfSprite_setPosition(sprite1, duck_vector);
//Creation de la fenetr + curseur
window = sfRenderWindow_create(video_mode, "Duck Hunt", sfDefaultStyle, NULL);
sfWindow_setMouseCursorVisible(window, sfFalse);
texture2 = sfTexture_createFromFile("mire.png", NULL);
cursor = sfSprite_create();
sfSprite_setTexture(sprite, texture, sfTrue);
sfSprite_setTexture(sprite1, texture1, sfTrue);
sfSprite_setTexture(cursor, texture2, sfTrue);
sfSprite_setTextureRect(sprite1, rect);
sfVector2i cursor_coord;
cursor_coord.x = 1280;
cursor_coord.y = 769;
sfMouse_setPosition(cursor_coord, window);
//Affichage de la fenetre + sprites
while (sfRenderWindow_isOpen(window)) {
time = sfClock_getElapsedTime(clock);
seconds = time.microseconds / 2500000.0;
if (seconds > 0.10) {
if (rect.left == 220)
rect.left = 0;
else
rect.left += 110;
sfSprite_setTextureRect(sprite1, rect);
sfClock_restart(clock);
}
sfSprite_move(sprite1, duck_vector);
while (sfRenderWindow_pollEvent(window, &event)) {
if (event.type == sfEvtMouseMoved) {
}
if (event.type == sfEvtClosed)
sfRenderWindow_close(window);
}
sfSprite_setPosition(sprite1, duck_vector);
if (sfSprite_getPosition(sprite1).x >= 1200) {
invers_duck.x = -invers_duck.x;
sfSprite_scale(sprite1, invers_duck);
}
if (sfSprite_getPosition(sprite1).x < -10) {
invers_duck.x = -invers_duck.x;
sfSprite_scale(sprite1, invers_duck);
}
sfRenderWindow_drawSprite(window, sprite, NULL);
sfRenderWindow_drawSprite(window, sprite1, NULL);
sfRenderWindow_drawSprite(window, cursor, NULL);
sfRenderWindow_display(window);
}
sfRenderWindow_destroy(window);
return (0);
}
Hello everyone,
I would like to change the default cursor of my mouse, by a chart because I am doing the game duck hunt. I did some stuff but it does not work ...
Can you help me ?