How do I fix this "use item" feature?

Not favoritedFavorited Favorited 0 favourites
  • 8 posts
From the Asset Store
Cartoon Funny Item Interface Sound Pack comes with 426 high-quality sound effects
  • I am making a point-and-click style adventure game where the player can put items in their inventory, and then double-click on those items in order to use them. It does this by changing the mouse style to match the sprite of whatever item they clicked on. However, as the scale of my game has increased, a delay has grown between double-clicking the item and the mouse sprite changing.

    Right now, it there is a full two second delay, which is not only noticeable, but is also causing bugs. But, weirdly, after the first time an item has been used, the next time the player uses that item, the mouse sprite changes immediately. With this in mind, I tried creating a function that looped through every item sprite at the start of the game, and set the mouse sprite to each object. While this loop has gotten rid of the delay, there are now two new problems: one, there is a brief moment at the start of the game where the mouse cursor somewhat noticeably flickers between all the items, and two, there is a low chance that, after the mouse has looped through all the item sprites, the mouse sprite doesn't return to the regular mouse cursor sprite.

    All this to say, is there a simpler way for me to fix this delay problem that doesn't result in more issues? I appreciate any help.

    Link to video showing gameplay without the mouse sprite loop.

    youtu.be/_iLWGeGyhMo

    Link to video showing gameplay with mouse sprite loop working "properly".

    youtu.be/9hfSWYfX0Uw

    All items that can be picked up by the player are a part of the "InvItems" family.

    Image of the code used for the mouse sprite loop. I am aware that it is extremely brute force-y. I originally just had a single for-each member of the InvItems family loop, but I was experiencing the previously mentioned issue (where the mouse sprite would not return to the regular cursor sprite) much more compared to after I changed it to the code pictured.

    If you need any more information, feel free to let me know!

  • Image of the alternative cursor sprite loop using a single for-each loop.

    While using this method though, the calls to "Set cursor from sprite CursorArt" are almost always ignored, resulting in the player's cursor looking like a screwdriver or lump of coal (at least until they try using an item, in which case the cursor sprites function properly)

  • How big are these images? 2s to load them seems way too long.

    You can try placing them all on the layout, they can be off-screen and you can destroy them after the layout has started. This should pre-load their textures into memory, which may help to reduce the delay.

    Another option is to add all cursor images into a single sprite as animations. Keep the sprite on the layout. Set the required animation, then set the mouse cursor from the sprite.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you for the suggestions! The original sprite is 50x50, though I resized them in-game to 100x100. They are already in the game, just outside the layout, though I can't delete them as they are needed for code later in the game. I'll try doing the single object with all sprites thing though.

  • I tried doing what you suggested (using a single object that changes animations), but even though they are all on the same object, it still takes close to 2 seconds when trying to use a new item.

  • I moved the cursor sprite loop code to it's own event sheet to see if that might make it faster. It was originally a subgroup in a large event sheet, so I'm hoping that by making it it's own thing, it'll be able to run faster without having to run a lot of unnecessary code.

    Edit: Nevermind, I'm still getting the same problem where the cursor art doesn't go back to normal.

  • This is strange. We have a sprite with multiple animations for mouse cursor and changing between them is instant.

    Maybe 100px is too big for cursor? As an experiment, try resizing them to something like 20x20 px.

    Also, try disabling the Worker in project properties. If it helps, this might be a browser bug:

    github.com/Scirra/Construct-bugs/issues/3652

  • Thank you for the help. Worker is already disabled, and I tried making the sprite smaller, and while it did seem like it made the delay shorter, it's still too large a gap. I could try making it even smaller, but it's getting to the point were any smaller and it would be hard to tell what you're looking at. I'll keep futzing with it to see if I can get it faster, but if not, I'll stick to the sprite loop.

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