From c16f16066f1943a8c2d4178583578705e71e7794 Mon Sep 17 00:00:00 2001 From: arngo <27396817+arngo@users.noreply.github.com> Date: Sun, 19 Dec 2021 16:51:50 -0500 Subject: make button change sprite when pressed/unpressed --- app/components/button.rb | 2 ++ app/systems/init_title_screen.rb | 4 ++-- app/systems/title_screen.rb | 12 ++++++------ sprites/title/start.png | Bin 530 -> 7665 bytes sprites/title/start_pressed.png | Bin 0 -> 7467 bytes 5 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 sprites/title/start_pressed.png diff --git a/app/components/button.rb b/app/components/button.rb index 8f9126f..097ca51 100644 --- a/app/components/button.rb +++ b/app/components/button.rb @@ -1,3 +1,5 @@ FF::Cmp.new('Button', :action, + :pressed_sprite_path, + :unpressed_sprite_path, clicked: false) diff --git a/app/systems/init_title_screen.rb b/app/systems/init_title_screen.rb index 66873df..04c4978 100644 --- a/app/systems/init_title_screen.rb +++ b/app/systems/init_title_screen.rb @@ -11,10 +11,10 @@ FF::Sys.new('InitTitleScreen', priority: 1) do sprite.props[:y] = btn_y sprite.props[:w] = btn_w sprite.props[:h] = btn_h - sprite.props[:path] = 'sprites/title/start.png' + #sprite.props[:path] = 'sprites/title/start.png' # start button FF::Ent.new( - FF::Cmp::Button.new(action: FF::Sys::StartGame), + FF::Cmp::Button.new(action: FF::Sys::StartGame, pressed_sprite_path: 'sprites/title/start_pressed.png', unpressed_sprite_path: 'sprites/title/start.png'), FF::Cmp::Hitbox.new(x: btn_x, y: btn_y, w: btn_w, h: btn_h), sprite, FF::Cmp::Title[0] diff --git a/app/systems/title_screen.rb b/app/systems/title_screen.rb index 0229720..0fa0a81 100644 --- a/app/systems/title_screen.rb +++ b/app/systems/title_screen.rb @@ -11,15 +11,15 @@ FF::Scn::TitleScreen.add( if mouse.x > hitbox.x and mouse.x < hitbox.x + hitbox.w and mouse.y > hitbox.y and mouse.y < hitbox.y + hitbox.h if $gtk.args.inputs.mouse.down btn.clicked = true - #sprite.props[:path] = '' - else + sprite.props[:path] = btn.pressed_sprite_path + elsif $gtk.args.inputs.mouse.up and btn.clicked btn.clicked = false - #sprite.props[:path] = '' - end - if $gtk.args.inputs.mouse.click + sprite.props[:path] = btn.unpressed_sprite_path btn.action.call - puts 'click' end + else + btn.clicked = false + sprite.props[:path] = btn.unpressed_sprite_path end end end diff --git a/sprites/title/start.png b/sprites/title/start.png index 835f3a7..b147375 100644 Binary files a/sprites/title/start.png and b/sprites/title/start.png differ diff --git a/sprites/title/start_pressed.png b/sprites/title/start_pressed.png new file mode 100644 index 0000000..751ba7d Binary files /dev/null and b/sprites/title/start_pressed.png differ -- cgit v1.2.3