Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

native_cursor_set_frame() not working?

A topic by wronchi created Sep 27, 2023 Views: 201 Replies: 4
Viewing posts 1 to 2

Thanks for this extension. I'm having an issue with [native_cursor_set_frame] not setting the frame correctly of a cursor created with [native_cursor_create_from_sprite]. No matter if I call the [native_cursor_set_frame] function, it always stays on the frame that is set in the initial [native_cursor_create_from_sprite]. Some additional context, spr_cursor is a sprite with 4 frames. 


Just wanted to confirm as a bug or I'm doing something wrong. Thanks again!

Developer

There are two things here:

  • native_cursor_get_frame is like image_index in GM - it can only be between 0 and count-1. And your cursor has a single frame.
  • I did not foresee that people would try to get frame of a non-current cursor so that’s not working right.

Thanks for the response, I'll try to clarify my intent and some other things:

My goal was to have my cursor's 'image index' change based on certain ingame conditions. (mouse overing something, etc.). I had been previously accomplishing this with several different 1-frame cursors and then setting them to current. I wanted to rework how I did it and started trying to use native_cursor_set_frame and native_cursor_get_frame

  • "native_cursor_get_frame is like image_index in GM - it can only be between 0 and count-1. And your cursor has a single frame."
    Yes, I operated under that assumption and my cursor (or at least the sprite it is created from) doesn't have a single frame, it has multiple, unless I misunderstand what native_cursor_create_from_sprite does.
    When I use native_cursor_create_from_sprite and set its frame argument to... 2, let's say, then it correctly displays the '3rd' image in the sprite.
    It then does NOT change when I then use native_cursor_set_frame and native_cursor_get_frame after creating it and setting it as current.
     
  • I did not foresee that people would try to get frame of a non-current cursor so that’s not working right.
    Even if current (which I assume you mean after using native_cursor_set?) native_cursor_set_frame and native_cursor_get_frame do not behave correctly from what I can tell. get_frame is always zero for me, and set_frame doesn't change which frame is shown.

    Am I misunderstanding what any of these functions do? Hopefully I was clearer this time so if I misunderstood them you could at least see what I was thinking.
    I can easily go back to my original method and get the results I wanted I think, but I just wanted to make sure I didn't misunderstand these functions and let you know if it were the case that these weren't working properly.
Developer

Per documentation:

If frame is not specified or is undefined, all frames will be added. Otherwise a single frame is used.

If you pass 2 for frame, the cursor will only contain that frame. That’s not a starting frame or anything, that’s the frame that will be used for the cursor.

Conveniently, it is probably what you have to do here - if your frames represent multiple cursors that you want to swap between, make multiple cursors out of those (and if the cursor contains several frames, there’s native_cursor_add_from_sprite_ext), and swap between those - swapping between already-created cursors is pretty cheap.

Roger that - yeah swapping already created cursors will be my plan, then. Thanks.

I did try not defining the frame and still had the same issue but maybe I was still not using it correctly,  but just bringing it up just in case. Thanks for the swift responses as well.