How do I dynamically change the cursor icon?
by Flybynight Studios · in Torque Game Engine · 08/04/2008 (1:58 pm) · 9 replies
In this case I want to toss a copy of the item icon as the cursor when someone "picks up" said item. I've got the pickup code all working great but I need some kind of visual indicater that the item is in your hand. So I figured simple right? change the defaultcursor.bitmapname="myicon";
Wrongo :)
I tried doing this in various ways and even set up a new custom cursor profile for testing, called it itemcursor and set a static icon image for bitmapname= .. I then called teh cursor change with canvas.setcursor(itemcursor); .. No success..
seems to me this is a relatively simple request and I would suspect it may have somethign to do with teh cavas refresh but I'll differ to soemone else's experience on this one.
Thanks in advance.
Wrongo :)
I tried doing this in various ways and even set up a new custom cursor profile for testing, called it itemcursor and set a static icon image for bitmapname= .. I then called teh cursor change with canvas.setcursor(itemcursor); .. No success..
seems to me this is a relatively simple request and I would suspect it may have somethign to do with teh cavas refresh but I'll differ to soemone else's experience on this one.
Thanks in advance.
#2
Basically the default cursor uses a cur_3dmouse img and I simply want to assign that graphic a new pointer dynamically when a player grabs an item. Basicalyl change the pointer into the icon image for whatever the player just grabbed. it seems like it owuld be a simple matter of defaultcursor.bitmapname="blah" but it isnt.
As I said I also tried changing the cursor to a diff cursor but no avail. I think there is something wrong with my methodology in how I am attempting to change the cursor. canvas.setcursor should work but seems to not.. I'll dig more. thanks for trying to help.
08/04/2008 (4:15 pm)
No James TGE. Seems like a simple thing but Im not finding any resources on it.Basically the default cursor uses a cur_3dmouse img and I simply want to assign that graphic a new pointer dynamically when a player grabs an item. Basicalyl change the pointer into the icon image for whatever the player just grabbed. it seems like it owuld be a simple matter of defaultcursor.bitmapname="blah" but it isnt.
As I said I also tried changing the cursor to a diff cursor but no avail. I think there is something wrong with my methodology in how I am attempting to change the cursor. canvas.setcursor should work but seems to not.. I'll dig more. thanks for trying to help.
#3
I can make the cursor change from the console typing canvas.setcursor(itemcursor);
The intresting thing is that I can NOT make it do that from script. I tried canvas.setcursor(itemcursor) I tried doing it in an eval etc..
What is concerning me now is that I have a pretty heavily modded source and I think my object selection code is possibly hitting me over the head here.
2 reasons I think this.. first and formost is that when I click the mouse in the playGUI area it changes the icon to a triangular pointer. It does this with either the right or left buttons.. Second reason is that if I pop open the console and do a quick setcursor as soon as I close the console, the first mouse movement will change the cursor back to the default.. If I keep the console open after changing to the item cursor the cursor moves around fine with the changed icon..
Sew... I really hate to do this but I think it's back into the source for me. bleah
Any other thoughts?
08/04/2008 (4:42 pm)
Ok some followup...I can make the cursor change from the console typing canvas.setcursor(itemcursor);
The intresting thing is that I can NOT make it do that from script. I tried canvas.setcursor(itemcursor) I tried doing it in an eval etc..
What is concerning me now is that I have a pretty heavily modded source and I think my object selection code is possibly hitting me over the head here.
2 reasons I think this.. first and formost is that when I click the mouse in the playGUI area it changes the icon to a triangular pointer. It does this with either the right or left buttons.. Second reason is that if I pop open the console and do a quick setcursor as soon as I close the console, the first mouse movement will change the cursor back to the default.. If I keep the console open after changing to the item cursor the cursor moves around fine with the changed icon..
Sew... I really hate to do this but I think it's back into the source for me. bleah
Any other thoughts?
#4
If I could figure out how to change the bitmapname portion of the cursor control I could just mod the default cursor bitmap with the grabbed item and be done with it for now. I don't have the programming skills to get into the object selection code and sort this out.
So what I need to figure out now is how to change the bitmapname= of the defaultcursor control..
08/04/2008 (7:24 pm)
Ok did a little mroe digging. Part of the problem IS the item selection code. It started out as the wow selection code from the resources but got pretty heavily modified. It looks like even the base wow selection code overwrites the pointer icon willy nilly with zero regard for potential cursor customizations.. Something that people should note if they utilize that resource.If I could figure out how to change the bitmapname portion of the cursor control I could just mod the default cursor bitmap with the grabbed item and be done with it for now. I don't have the programming skills to get into the object selection code and sort this out.
So what I need to figure out now is how to change the bitmapname= of the defaultcursor control..
#5
I have tried turning it off, repointing it, then turning it back on.. I've tried changing cursors then updating the old cursor then changing back.. again no go..
I even tried scheduling the changes incase it was a cycle thing.. no go.
Anyone ever done this?
Thanks
Edit: Just a bit more info..
Just incase anyone thought it was syntax for hwo I am updating the field, it's not..
If I do an 'echo(itemcursor.bitmapname);' it gives me the exact file I want to see but that file is not represented by the icon on the screen. So when I change to Itemcursor it shows the runtime icon which is "ic000001" and when I click on an item it actually updates the itemcursor.bitmapname to whatever item the client clicked on like "ic002391". So when I get an echo of the itemcursor.bitmapname field it comes back ic002391 but the icon is still the runtime icon of ic000001...
Hope that makes sense.
Basically at runtime:
itemcursor.bitmapname="ic000001";
I can change the value during the game but it is not reflected by the visual representation of the itemIcon which remains as ic000001.
08/04/2008 (9:05 pm)
Ok more digging.. I am having a heck of a time getting the bitmapname field of any cursor object to update on the screen.. It seems that whatever the cursor bitmap is at runtime is what it must be throughout the game.. Now I am not going to define 40k cursors for each particular item I have in my game.. :) There must be some way to get the cursor to update it's bitmap pointer.I have tried turning it off, repointing it, then turning it back on.. I've tried changing cursors then updating the old cursor then changing back.. again no go..
I even tried scheduling the changes incase it was a cycle thing.. no go.
Anyone ever done this?
Thanks
Edit: Just a bit more info..
Just incase anyone thought it was syntax for hwo I am updating the field, it's not..
If I do an 'echo(itemcursor.bitmapname);' it gives me the exact file I want to see but that file is not represented by the icon on the screen. So when I change to Itemcursor it shows the runtime icon which is "ic000001" and when I click on an item it actually updates the itemcursor.bitmapname to whatever item the client clicked on like "ic002391". So when I get an echo of the itemcursor.bitmapname field it comes back ic002391 but the icon is still the runtime icon of ic000001...
Hope that makes sense.
Basically at runtime:
itemcursor.bitmapname="ic000001";
I can change the value during the game but it is not reflected by the visual representation of the itemIcon which remains as ic000001.
#6
http://www.garagegames.com/mg/forums/result.thread.php?qt=11014
He fixed that control (and dynamic bitmap changes work on bitmapbuttoncontrols) but I wonder if so few people actually tried to do dynamic pointers this may have got overlooked. Hoping someone with more expertise than myself looks at it :)
08/04/2008 (9:44 pm)
More digging... I wonder if this is related to the problem that Ron was having back in 2003 with the GuiBitmapButton control..http://www.garagegames.com/mg/forums/result.thread.php?qt=11014
He fixed that control (and dynamic bitmap changes work on bitmapbuttoncontrols) but I wonder if so few people actually tried to do dynamic pointers this may have got overlooked. Hoping someone with more expertise than myself looks at it :)
#7
Alternatively, just keep your current GuiCursor object in a variable like $GuiCursor, then when you want to change it, allocate a new one with the bitmap you want, set it on the canvas, delete the old one, and assign the new one to $GuiCursor.
Don't be afraid to look at the source code '-)
08/04/2008 (9:56 pm)
It looks like GuiCursor is just not setup to handle switching the bitmap on the fly. I just looked at the code, it wouldn't be hard at all to add a setBitmap that sets the texture handle at that point. Since currently it only allocates a texturehandle from the filename if it doesn't already have one, and there is currently no way to null out the texturehandle from script.Alternatively, just keep your current GuiCursor object in a variable like $GuiCursor, then when you want to change it, allocate a new one with the bitmap you want, set it on the canvas, delete the old one, and assign the new one to $GuiCursor.
Don't be afraid to look at the source code '-)
#8
I think I know what you are saying about $guiCursor. I think I understand what could be done there. I'll try that now. Seems like a setbitmap would really be a cool addition though.
Thanks for confirming this for me. I had been in the source in gui/core/guitypes.cc and thats where it appears to me that the name is read once. I am not comfortable going in and monkeying though. All my codebase changes have been done by people who actually know what they are doing heh.
Thanks again for your time. I'll keep plugging away and try that GUICursor suggestion of yours.
08/04/2008 (10:22 pm)
Thanks James. My coding/C++ is really terrible. I can script like no tomorrow but I just dont understand C++.I think I know what you are saying about $guiCursor. I think I understand what could be done there. I'll try that now. Seems like a setbitmap would really be a cool addition though.
Thanks for confirming this for me. I had been in the source in gui/core/guitypes.cc and thats where it appears to me that the name is read once. I am not comfortable going in and monkeying though. All my codebase changes have been done by people who actually know what they are doing heh.
Thanks again for your time. I'll keep plugging away and try that GUICursor suggestion of yours.
#9
Using a variable to store the itemcursor works in that the bitmap does change but the second the cursor is moved it is overwritten by the engine as it monitors what is below the mouse in the playgui for object selection and reverts back to the 3dcursor. I tried an instance of assigning the defaultcursor to a variable but it still reverts.. Going to try that again as Im not sure my logic was correct.
An intresting thing to note is that if I set the defaultcursor.bitmapname="ic000001" at runtime that icon is used throught the game as the default cursor even by the engine calling from the object selection monitoring.. So it sounds to me like the real answer for me is a setbitmap procedure for the guicursor control.
Still doing more funky playing around. It's all about the learning process right :)
08/05/2008 (8:10 am)
So after much further testing:Using a variable to store the itemcursor works in that the bitmap does change but the second the cursor is moved it is overwritten by the engine as it monitors what is below the mouse in the playgui for object selection and reverts back to the 3dcursor. I tried an instance of assigning the defaultcursor to a variable but it still reverts.. Going to try that again as Im not sure my logic was correct.
An intresting thing to note is that if I set the defaultcursor.bitmapname="ic000001" at runtime that icon is used throught the game as the default cursor even by the engine calling from the object selection monitoring.. So it sounds to me like the real answer for me is a setbitmap procedure for the guicursor control.
Still doing more funky playing around. It's all about the learning process right :)
Associate James Ford
Sickhead Games