Collect Item Interface

  • #1, by theoSunday, 28. March 2021, 01:05 3 years ago
    Hi Forum,

    thanks for many helpful tips that have already been posted here. You have already helped me in many concerns without knowing it! Now I have a question to which I have not yet found an answer...

    It's about an interface that is displayed a few seconds after the character has collected an item, with a small image of the collected object. 
    Unfortunately I'm not a good programmer to write a script quickly.... was there already a thread here that deals with this? Or does anyone have an idea how I approach this? 

    Thanks in advance!  


    Newbie

    2 Posts


  • #2, by afrlmeThursday, 01. April 2021, 00:47 3 years ago
    A'llo, this is a working script shared by Simon on our discord server a little while ago. It's supposed to popup the item sprite at a specific position temporarily after adding a new item to the inventory.

    Add this as a definition type script to the script section of the Visionaire Studio. You will need to tweak the position values to wherever you want the popup item sprite to be displayed.

    local ADD_REMOVE_ITEM = 150
    
    system.registerActionPartHook(ADD_REMOVE_ITEM, "addRemoveItem")
    
    function addRemoveItem(actionPart)
    
      if actionPart.Int == 0 then
    
        local path = actionPart.Link.Sprite.Sprite:getPath()
    
        local sprite = graphics.loadFromFile(path)
    
        sprite.position = graphics.getCharacterTextPosition(game.CurrentCharacter)
    
        
    
        local t = getTime()
    
        graphics.addDrawFunc("draw()", 0)
    
        function draw()
    
          local ct = getTime() - t
    
          local alpha = 0
    
          if ct > 3000 then
    
            graphics.removeDrawFunc("draw()")
    
          elseif ct > 2000 then
    
            alpha = graphics.evalTween(1, 0, ct/1000-2,easeQuadOut)
    
          elseif ct > 1000 then
    
            alpha = 1
    
          else
    
            alpha = graphics.evalTween(0, 1, ct/1000,easeQuadOut)
    
          end
    
          graphics.drawSprite(sprite, alpha, 0xffffff)
    
        end
    
      end
    
      return false
    
    end


    Imperator

    7278 Posts

  • #3, by afrlmeThursday, 01. April 2021, 00:52 3 years ago
    Ah, I just read through the code, it seems that it fades in/out the item sprite above the playable characters head. If you want to change the position, then just edit line 7.
    
    sprite.position = graphics.getCharacterTextPosition(game.CurrentCharacter)

    to something like this...

    sprite.position = {x = game.ScrollPosition.x + 100, y = game.ScrollPosition.y + 100}


    Which would offset the item popup 100 pixels from the top-left of the current camera viewport.

    Imperator

    7278 Posts

  • #4, by theoThursday, 01. April 2021, 14:46 3 years ago
    Many thanks AFRLme & Simon!

    Works perfectly... I'll create a standardized animation soon, which then plays in the lower left corner, the item appears briefly, both disappear shortly after... should look great!



    Newbie

    2 Posts