So I’ve read all the documentation, and even gone through a tutorial or two, and I feel as if I’m still missing something essential in the whole adding a behaviour/function to a global object thing.
Basically I have a Button object (Global) with two animations. One is just the button, the second is displayed when the mouse is over it. Unpressed and Pressed respectively. I created a behavior, added a function which I set to a condition. I then added two events Cursor/touch on Button → changes animation to Pressed, cursor/touch is NOT on button (using invert condition) → changes animation to Unpressed. I then added this behavior to the object. My expectation being that now when I add a Button to a scene that it will behave this way automatically. It does not. I’ve tried adding Parameter (Button) Type (Mouse button text) - I was seriously trying anything at this point - I also tried adding the behavior to the event sheet, but while I see the behavior in the conditions selection, I can’t seem to select it. I also tried setting it to an action… Which sort of gets rid of the whole reason I wanted to add this behavior to the button… But again I was at a point where I was trying anything… Nothing seems to be working… I’m certain I’m missing something - probably obvious.
Hi,
If you’re starting, I recommend that you first get working events in the standard events sheet, and when it works, you can try converting that to a function.
We can’t give accurate help without seeing your events.
And next time, please use line breaks so your message is easier to read.
So I did already get the events working in the standard events sheet.
Specifically:
I have this condition:
The cursor/touch is on “Button”
With this action:
Set the animation of “Button” to "Pressed
Then this condition:
!The cursor/touch is on “Button”
With this action:
Set the animation of "Button to “Unpressed”
These events work as expected on this page. But not wanting to have to repeat these on every scene - I have a lot of scenes, many of which have many buttons - I had hoped to modularize this behavior/function.
I’ve attached a screenshot of at least the first screen of my attempt to make the behavior.
If there’s anything else I need to reiterate in a more understandable/readable, manner please just let me know. And many thanks!
So I’ve continued to troubleshoot this on my own.
I realized I was entering my conditions/actions under the “Functions” which is different than “Behavior Functions” So I tried entering my conditions/actions under “Behavior Functions” instead.
I believe this means I’m closer, since now when I go under Parameters it now is reading Parameter #0: Object, Object Type: Sprite.
And Parameter #1: Behavior, Behavior Type: DepressButton (what I named the Behavior)
I’ve double checked that the Object is showing this Behavior in that tab (Edit Object → Behaviors)
But I’m still not seeing the expected behavior…
OH! And I also added this to my events sheet:
Condition: Beginning of scene
Action: Change the animation of “Button”
The action reads how I wrote it in the Configuration (Change animation of PARAM0)
I figured it out! I was so close after my last post…
I just removed the condition (Beginning of scene).
So blank condition. And the action the same - and now all the buttons are behaving as expected! Hope this helps someone else - and if anyone needs clarification on any of my steps, please don’t hesitate to ask!
That’s not how behaviors work. What you want to do is from inside the behavior add a behavior function that checks if it is pressed or not. You can use a lifecycle function to determine every frame what animation it should be using and set some properties like if it is pressed and use a normal behavior function (not a regular one) to get the property stating if it is pressed or not.
Behavior functions are on the right tab when you open a behavior