SFML community forums
Help => Graphics => Topic started 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.
-
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
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.
-
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
?
-
while(App.IsOpened())
{
//GetTheInput...
Sprite.SetPosition(MouseX,MouseY);
App.Clear();
App.Draw(Sprite);
App.Display();
}
-
Yeah, I made stupid mistake before I forget to use GetInput function now everything works fine.
Thank You guys for reply.
-
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?
-
The function you need is sf::Image::CreateMaskFromColor().
-
imo use a .png format for the spritegraphic and make the background transparent. should be better (including performance) then hardcode this in your sourcecode.
-
I used CreateMaskFromColor and it's almost perfect:
(http://img186.imageshack.us/img186/1733/mousel.png)
-
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 ;)
-
Fixed, thanks.