How do I set the appearance of the cursor using a variable?

0 favourites
  • 7 posts
From the Asset Store
Mouse cursor is something that the player controls and sees all the time, that's why it is so important to make it cool!
  • I'd like to allow the player to "place" a given object at the mouse's X/Y coordinates. They'll select the object from a pulldown list, click somewhere on the screen, and the selected object will appear where they clicked.

    I've worked out how to allow the player to select an object from a pulldown list and set a global variable to the object's name, but I can't change the mouse cursor to the selected object.

    I can "Set cursor from sprite," but that forces me to pick a specific object, not a global variable.

    I've thought about creating the variable object programmatically and pinning it to the mouse X/Y every tick (setting the actual cursor to None), but *that* forces me to pick a specific pinnable object too, not a global variable.

    I suppose I could set up a vast if-then selection tree, where if the global variable = objectX, set cursor to objectX .. etc etc, but that seems ridiculous.

    Any suggestions?

    Tagged:

  • Set the mouse style to None and every tick, set the position of the sprite object to the mouse position.

  • you could have one sprite object and load all the different cursors as separate animations, or different frames of one animation, then set the animation or frame based on your global variable. (And set the cursor from the sprite of course).

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks for the suggestions. I can set the value of the cursor to a given sprite, but how do I set the cursor value to the *name* of a sprite? I will have 100 different sprites to choose from.

    The animation idea is interesting, but also seems like a lot of if-then work ("if selected option is X, use animation frame Y, and so on..."). I guess I could pre-load the ID of the animation frame and say "set animation frame to the value of selectedobject.cursoranimationframe".

  • if you use frames, you could set the sprite's frame to the index of the drop down - so only one action required.

    if you use animations and use the same names in the drop down you could set the sprite animation to the drop down text.

  • The idea by AllanR would work just fine but requires conversion back and forth between the object you click and the animation you show. Conversely, creating an object that follows the cursor from the clicked object uses very few events and doesn't require the addition of a cursor sprite object. Take a look at the example project.

    drive.google.com/file/d/1M6zdd0rbgjiJcGq0AkrEiarz6bJGw4-p/view

  • Thanks all. FWIW, I am now dedicating a frame of the "placement cursor" animation to each object. When an object is selected from the pulldown the ID of the frame is put in a global, which then lets me set the animation frame of the cursor. I just have to put a copy of each object into the placement cursor animation when I create it and keep track of which frame it's in when I do so. Not terribly tricky and seems to work fine. Thanks for your help.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)