How to press a button to affect an object

Discussion in 'How Can I...?' started by sysads, Oct 31, 2015.

  1. sysads

    sysads Serious Boxer

    Joined:
    Oct 8, 2015
    Messages:
    885
    Likes Received:
    353
    Apologies for repeated question, I was hoping an expert could really help me with a simple step by step instruction.

    I want my xter to press a button so an object gets either destroyed or moved.

    upload_2015-10-31_22-39-52.png
     

    Attached Files:

  2. ajcoryat

    ajcoryat Avid Boxer

    Joined:
    Sep 25, 2015
    Messages:
    241
    Likes Received:
    111
    This might not be a perfect solution but certainly a creative one:
    Maybe the button and the obstacle might have to be part of the same .png file, (so a lot of invisible space in-between) and set it to "collide" on the right screen of BB, then have a "defeat" animation that includes the button being depressed (when the character touches it) in the early part of a animation sequence and the obstacle destroyed in the latter part of the sequence. You may need 20-25 frames depending on how fast you want the sequence to take place. You can create this in a simple program app like ArtText2 (available on the Mac AppStore).
     
  3. stevinz

    stevinz Avid Boxer

    Joined:
    Sep 25, 2015
    Messages:
    169
    Likes Received:
    142
    I believe the simplest solution I've come across yet is one I have told you about before:

    Have the object you wish to move out of the way linked to an action.
    • Create a lit button as a decoration and place it in the scene
    • Create an unlit button as an action, can just be type "None". Set duration low, like ".01". Carefully align the unlit button action on top of the lit button decoration to cover it up.
    • Place the spikey enemy platform in the scene
    • Link the button action as a PARENT to the spikey enemy. This way when the button action is collected the spikey enemy will disappear
    • In the "Action Animation" for the button, drag a new spikey enemy object into the first frame.
    • Set the object to spawn, give it a super high duration so it only spawns once. Something like "100000"
    • Offset the new spikey enemy object within the animation window to display properly where it should in the scene
    • Also give it some velocity so it will move out of the way and open up the new pathway

    same as we talked about before in other threads:
    https://www.buildbox.com/forum/index.php?threads/wake-up-an-animated-object.181/#post-1005
     
    sysads and Christoph like this.
  4. sysads

    sysads Serious Boxer

    Joined:
    Oct 8, 2015
    Messages:
    885
    Likes Received:
    353
    @stevinz you are such a super duper :D
    OK that steps works as expected but struggling to calculate the correct place where the enemy will be spawned. The spike in scene has the following position:
    upload_2015-11-1_4-58-15.png

    I also tried to use the same settings in Action Animation but when it spawns, it spawns it where the unlit button actually is :(
    upload_2015-11-1_5-1-4.png

    I have tried playing with the positions but can't get it to where it should be
     
  5. stevinz

    stevinz Avid Boxer

    Joined:
    Sep 25, 2015
    Messages:
    169
    Likes Received:
    142
    Yeah, so in the animation editor you should have the x and y positions relative to the distance between the objects in the scene. So if the spike in the scene is 74, 170 and the button is 274, 190 then in the animation editor the new spike would be at -200, -20. Does this make sense?
     
  6. sysads

    sysads Serious Boxer

    Joined:
    Oct 8, 2015
    Messages:
    885
    Likes Received:
    353
    I was actually playing with the negative values but that didn't work. Spike pos is 74x170 while unlit button pos is 294x148 so I did the calc and tried values as -220 x 22 but no show.
    It just brings it directly on top of the unlit button

    upload_2015-11-1_5-35-34.png
     
  7. stevinz

    stevinz Avid Boxer

    Joined:
    Sep 25, 2015
    Messages:
    169
    Likes Received:
    142
    I see you have some logic pieces in your game as well, could any of those be affecting the outcome? .. I've never had any problems getting it to work, hard to say without looking at it. Seems like you're really close.
     
  8. sysads

    sysads Serious Boxer

    Joined:
    Oct 8, 2015
    Messages:
    885
    Likes Received:
    353
    Please don't ask me how I got it to work :( but I did finally. Its like a mirage. So to understand how BB uses the values, I brought down the spike's Y-pos to same as the action button. So I now had 74 x 148 where 148 is same Y position as the unlit button.

    Mathematically BB's position boxes is calculated as X-axis by Y-axis, so to calc Y value, 148-148 leaves me with 0 so I would assume the Y value in the animation would be 0 but that was wrong. I had to use it as the X value so I am assuming this is because my game setting is 90 and not 0 :confused:

    So to get the Y pos now, all I did was minus the button X-pos from Spike's X-pos and multiplied it by 2 and that my friend spawned the spike in the exact same location :D:cool:
     
  9. stevinz

    stevinz Avid Boxer

    Joined:
    Sep 25, 2015
    Messages:
    169
    Likes Received:
    142
    Is it possible that your action button was turned 90 degrees? That would probably cause it to appear like that, I doubt the game direction was at fault...

    Glad you got it to work, though. :)
     
  10. sysads

    sysads Serious Boxer

    Joined:
    Oct 8, 2015
    Messages:
    885
    Likes Received:
    353
    Dem that's true ;) I turned it to 90 degrees, so meaning turning it reversed the X and Y position logically :D:D:D:D:D
     
  11. Phill Mason

    Phill Mason Serious Boxer

    Joined:
    Sep 25, 2015
    Messages:
    880
    Likes Received:
    721
    Great thread guys. @sysads and @stevinz, it's like watching a 'Crime Drama' unfold :) Great detective work you two.
     
    stevinz likes this.
  12. Rebel Studios

    Rebel Studios Avid Boxer

    Joined:
    Sep 25, 2015
    Messages:
    466
    Likes Received:
    280
    great tips... but but.... I don't know what this whole thing is all about... have taken down screenshots for reference though... @stevinz ... you totally nailed bbox with the hacks buddy :) TOTALLY AWESOME!!
     
  13. spoilt14

    spoilt14 Boxer

    Joined:
    Oct 23, 2015
    Messages:
    6
    Likes Received:
    1
    @stevinz @sysads This is a really informative thread and this concept is one I will have to remember.

    But what if you wanted to use this with multiple buttons?
    It seems to me that this "hack" is limited to a one time use. Being that the "Action Animation" is stored in the parent asset and not the instance, which means the relative offset of the spawner would always be the same. The only way I can think to work around it is to create multiple action assets (buttons) which isn't practical. Any ideas?
     
  14. stevinz

    stevinz Avid Boxer

    Joined:
    Sep 25, 2015
    Messages:
    169
    Likes Received:
    142
    @spoilt14 Yes, you would have to create multiple copies of the same action with different spawners. I'm not sure why you feel this is impractical. Images can be reused as to not take up additional atlas space. Creating a new button would take a couple minutes, maybe less if you've already made the graphics. Why would this be impractical?
     
  15. spoilt14

    spoilt14 Boxer

    Joined:
    Oct 23, 2015
    Messages:
    6
    Likes Received:
    1
    @stevinz You answered my question. It's not impractical assuming each action shares texture space on the atlas. But when I tested this, each action occupied its own texture space. I tried dragging textures on top one another, I also tried pressing the "Optimize" button, both to no avail.

    atlas.PNG

    I tried selecting the action in the asset panel and duplicating it in a variety of ways, right-clicking, pressing D (duplicate) on the keyboard, spacebar, shift-click etc. How is it done?
     
  16. stevinz

    stevinz Avid Boxer

    Joined:
    Sep 25, 2015
    Messages:
    169
    Likes Received:
    142
    @spoilt14 Its a little tricky to explain but its not too complicated. I'll do my best.
    • Select one of your additional "purple" actions in the left side menu
    • Click the "Edit" button for the Default Animation for that action, the Animation Editor window will open with that actions image already highlighted
    • Click the "Edit" button for the Image under Advanced Settings on the right side of the Animation Editor
    • Select the sprite you wish to use for this action (find the original "Purple" sprite) and click save. The action now uses the same sprite as the original action.
    • Now you can go into the Atlas viewer and click "Optimize" to remove any temporary image you may have used to create the new action in the first place.
     
    spoilt14 likes this.
  17. spoilt14

    spoilt14 Boxer

    Joined:
    Oct 23, 2015
    Messages:
    6
    Likes Received:
    1
    @stevinz Easy enough to do but I would never have thought of it on my own. Thanks!
     

Share This Page