@mcriley821 if you look above, i have a function there that has the code. What I’m really struggling with is getting a button to run it. I’m not sure if I am just putting it in the wrong place or what. I took the code that was in the game_menu.py example included with the app and used it as the skeleton to build my code. It works great and pulls up a very good looking menu, I was able to rename the buttons to what I wanted, they click and change to yellow when they are clicked but I haven’t yet been able to attach a function call to it yet. Here is a good portion of it:
#class from game menu example
class ButtonNode (SpriteNode):
def __init__(self, title, *args, **kwargs):
SpriteNode.__init__(self, 'pzl:Button1', *args, **kwargs)
button_font = ('Avenir Next', 20)
self.title_label = LabelNode(title, font=button_font, color='black', position=(0, 1), parent=self)
self.title = title
#class from game menu example
class MenuScene (Scene):
def __init__(self, title, subtitle, button_titles):
Scene.__init__(self)
self.title = title
self.subtitle = subtitle
self.button_titles = button_titles
def setup(self):
button_font = ('Avenir Next', 20)
title_font = ('Avenir Next', 36)
num_buttons = len(self.button_titles)
self.bg = SpriteNode(color='black', parent=self)
bg_shape = ui.Path.rounded_rect(0, 0, 340, num_buttons * 64 + 140, 8)
bg_shape.line_width = 4
shadow = ((0, 0, 0, 0.35), 0, 0, 24)
self.menu_bg = ShapeNode(bg_shape, (1,1,1,0.9), '#15a4ff', shadow=shadow, parent=self)
self.title_label = LabelNode(self.title, font=title_font, color='black', position=(0, self.menu_bg.size.h/2 - 40), parent=self.menu_bg)
self.title_label.anchor_point = (0.5, 1)
self.subtitle_label = LabelNode(self.subtitle, font=button_font, position=(0, self.menu_bg.size.h/2 - 100), color='black', parent=self.menu_bg)
self.subtitle_label.anchor_point = (0.5, 1)
self.buttons = []
for i, title in enumerate(reversed(self.button_titles)):
btn = ButtonNode(title, parent=self.menu_bg)
btn.position = 0, i * 64 - (num_buttons-1) * 32 - 50
self.buttons.append(btn)
self.did_change_size()
self.menu_bg.scale = 0
self.bg.alpha = 0
self.bg.run_action(A.fade_to(0.4))
self.menu_bg.run_action(A.scale_to(1, 0.3, TIMING_EASE_OUT_2))
self.background_color = 'white'
def norm_attack(self, sender):
self.Timboslice.normal_attack()
This is the main portion of the ui portion that I am trying to learn. I got the rest of my code, that includes the classes and functions in the last 2 lines, to work in a normal python environment so I know that those should not be the issue. It’s learning how to incorporate the ui module to get the buttons to run the methods.