Attract-Mode Support > Scripting

Need Help...display an image when you press a button

(1/5) > >>

malfacine:
Make a show image press a key
example press "H" show a image with instructions

Somebody helppp....

raygun:
Here you go:

- Save the code set out below as the file "PopUp.nut" in your attract mode /plugins directory.  Change "image.png" to whatever the filename of your image is.
- In Attract-Mode's plugin configuration enable the PopUp plugin.  In the controls configuration, map the "custom1" control to whatever you want to trigger the image.

Pushing the key should now flip the selected image on and off...


--- Code: ---class PopUpImage
{
        _my_image=null;

        constructor()
        {
                _my_image = fe.add_image( "image.png", 0, 0 );
                _my_image.visible=false;
                fe.add_signal_handler( this, "on_signal" )
        }

        function on_signal( signal )
        {
                if ( signal == "custom1" )
                {
                        _my_image.visible=!_my_image.visible;
                        return true;
                }
                return false;
        }
}

local blah = PopUpImage();

--- End code ---

malfacine:
Oh man thanks....  ;D

xbs:
Very useful, maybe someone could make a script with options for image path and button.
I tried but couldn't make it work.

liquid8d:
Here's a plugin version with a few changes... copy the code into plugins/PopupImage.nut

* I changed it to use get_input_state so you can use more than just a specific signal
* Added option to Hold key (default is toggle)
* Make sure to specify the full path to the image, otherwise it will look in the plugins folder


--- Code: ---class UserConfig </ help="This plugin will show a popup image when the specified key is pressed." /> {
</ label="Image", help="The full path to the image that will be displayed", order=1 />
image="";
</ label="Key", help="The key that will display the image", is_input="yes", order=2 />
key="";
</ label="Hold Key", help="If enabled, you must hold the key down", options="Yes,No", order=3 />
hold="No";
};

class PopUpImage
{
        _image = null;
_key = null;
_hold = false;
_showing = false;
_key_delay = 250;
_last_check = 0;

        constructor()
        {
local config = fe.get_config();
_image = fe.add_image( config["image"], 0, 0, fe.layout.width, fe.layout.height );
_image.visible=false;
_image.preserve_aspect_ratio = true;
_key = config["key"];
_hold = config["hold"];
fe.add_ticks_callback( this, "on_tick" );
        }

function on_tick( ttime )
{
local is_down = fe.get_input_state( _key );
if ( _hold == "Yes" )
{
_image.visible = is_down;
_showing = is_down;
} else
{
if ( is_down )
{
if ( ttime - _last_check > _key_delay )
{
_last_check = ttime;
_image.visible = !_showing;
_showing = !_showing;
}
}
}
}
}

fe.plugin[ "PopUpImage" ] <- PopUpImage();

--- End code ---

Let me know if you find any issues, then I will add this to my github... :)

Navigation

[0] Message Index

[#] Next page

Go to full version