SFML community forums

Help => Graphics => Topic started by: darekg11 on September 26, 2010, 02:53:29 pm

Title: Trying to change cursor
Post by: darekg11 on September 26, 2010, 02:53:29 pm
My sprite don't want to move, I managed to get Mouse X and Y coordinates, I also turned off normal cursor but I can't get Sprite to move at screen.
Code:
http://wklej.org/id/393689/


I bet it's kind of stupid error somewhere in code.
Thanks in advance.
Title: Trying to change cursor
Post by: Quillraven on September 26, 2010, 03:03:33 pm
don't know what language you are using exactly but as far as i can tell:

first of all you are hiding the mousecursor in the mainloop which is a waste of "performance" since you only need to disable it once.

second:
instead of checking for the mousemoveevent you can use the following
Code: [Select]

while( app.isopened() )
{
 // your event handling stuff

 // after the event handling
 CursorSpr.SetPosition( App.GetInput().GetMouseX(), App.GetInput().GetMouseY() );
}


third: use the setposition method of the sprite and not the move method. i think move is sthg else.
Title: Trying to change cursor
Post by: darekg11 on September 26, 2010, 03:17:28 pm
I am using C but with C++ compilator.
Could You explain more carefully?
So in loop:

while (sfRenderWindow_IsOpened(aaa))

I need to use:
sfInput_GetMouseX
sfInput_GetMouseY
sfSprite_SetPosition
And then before:
sfRenderWindow_Display
Use:
sfRenderWindow_DrawSprite
?
Title: Trying to change cursor
Post by: Finn on September 26, 2010, 07:35:10 pm
Code: [Select]

while(App.IsOpened())
{
    //GetTheInput...
   
    Sprite.SetPosition(MouseX,MouseY);
   
    App.Clear();
    App.Draw(Sprite);
    App.Display();
}
Title: Trying to change cursor
Post by: darekg11 on September 26, 2010, 07:59:49 pm
Yeah, I made stupid mistake before I forget to use GetInput function now everything works fine.
Thank You guys for reply.
Title: Trying to change cursor
Post by: darekg11 on September 28, 2010, 03:33:17 pm
Sorry for double post but I want to refresh topic, because I have question about cursor. Everything works fine but cursor looks like:
(http://img408.imageshack.us/img408/9407/kursor.png)

I want to hide that white background of cursor's image.
I thought that using fucntion sfImage_GetPixel to get background color and then use: sfImage_SetPixel to set color of necessary pixels to background color.

Is it a good idea?
Is there any simpler way to do this?
Title: Trying to change cursor
Post by: PeterWelzien on September 28, 2010, 08:37:27 pm
The function you need is sf::Image::CreateMaskFromColor().
Title: Trying to change cursor
Post by: Quillraven on September 28, 2010, 08:50:59 pm
imo use a .png format for the spritegraphic and make the background transparent. should be better (including performance) then hardcode this in your sourcecode.
Title: Trying to change cursor
Post by: darekg11 on September 28, 2010, 09:38:42 pm
I used CreateMaskFromColor and it's almost perfect:
(http://img186.imageshack.us/img186/1733/mousel.png)
Title: Trying to change cursor
Post by: Finn on September 28, 2010, 09:56:13 pm
To do it perfect: Just use .png with a transparent background! Then you don't have to worry about it and even need some less codelines ;)
Title: Trying to change cursor
Post by: darekg11 on September 28, 2010, 10:08:51 pm
Fixed, thanks.