I made a button script! This script is basically a function that lets you define buttons easily. Just import 3 different textures (one for normal state, one for hovered, and one for pressed states) and then call the function. All you have to do is add this to your custom scripts:

Modules You Need Installed!!  ⚠

  •  ct.mouse
var button = function button (button, normal, hovered, pressed, action) {
    var hover = ct.mouse.hovers(button);
    if (hover) {
        button.tex = hovered;
        if (ct.mouse.down) {
            button.tex = pressed;
            action();
        } 
    }
    else {
        button.tex = normal;
    }
};


And then in your on step code for the button type, add:

button(this, 'Normal Texture Name', 'Hovered Texture Name', 'Pressed Texutre Name', function nameOfFunction {
thingsToDoWhenPressedGoHere
})
StatusReleased
CategoryTool
PlatformsHTML5
AuthorZylops
Made withct.js
Tagsctjs, script

Comments

Log in with itch.io to leave a comment.

maybe instead of ct.mouse.down, it should be ct.mouse.pressed

🤷‍♂️ Maybe, I havent tried it, will do. Thanks!