Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Trying to change cursor  (Read 4291 times)

0 Members and 1 Guest are viewing this topic.

darekg11

  • Full Member
  • ***
  • Posts: 127
    • View Profile
Trying to change cursor
« 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.

Quillraven

  • Newbie
  • *
  • Posts: 11
    • View Profile
Trying to change cursor
« Reply #1 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.

darekg11

  • Full Member
  • ***
  • Posts: 127
    • View Profile
Trying to change cursor
« Reply #2 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
?

Finn

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
Trying to change cursor
« Reply #3 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();
}

darekg11

  • Full Member
  • ***
  • Posts: 127
    • View Profile
Trying to change cursor
« Reply #4 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.

darekg11

  • Full Member
  • ***
  • Posts: 127
    • View Profile
Trying to change cursor
« Reply #5 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:


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?

PeterWelzien

  • Newbie
  • *
  • Posts: 38
    • View Profile
Trying to change cursor
« Reply #6 on: September 28, 2010, 08:37:27 pm »
The function you need is sf::Image::CreateMaskFromColor().
/Peter Welzien

Quillraven

  • Newbie
  • *
  • Posts: 11
    • View Profile
Trying to change cursor
« Reply #7 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.

darekg11

  • Full Member
  • ***
  • Posts: 127
    • View Profile
Trying to change cursor
« Reply #8 on: September 28, 2010, 09:38:42 pm »
I used CreateMaskFromColor and it's almost perfect:

Finn

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
Trying to change cursor
« Reply #9 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 ;)

darekg11

  • Full Member
  • ***
  • Posts: 127
    • View Profile
Trying to change cursor
« Reply #10 on: September 28, 2010, 10:08:51 pm »
Fixed, thanks.