cocos.menu module¶
A Layer that implements a simple menu
Menu¶
This module provides a Menu class. Menus can contain regular items (which trigger a function when selected), toggle items (which toggle a flag when selected), or entry items (which lets you enter alphanumeric data).
To use a menu in your code, just subclass Menu and add the menu to an Scene or another Layer.
-
class
Menu
(title=u'')¶ Bases:
cocos.layer.base_layers.Layer
Abstract base class for menu layers.
Normal usage is:
- create a subclass
- override __init__ to set all style attributes, and then call create_menu()
- Finally you shall add the menu to an Scene or another Layer
-
create_menu
(items, selected_effect=None, unselected_effect=None, activated_effect=None, layout_strategy=<function verticalMenuLayout at 0x058D62B0>)¶ Creates the menu
The order of the list important since the first one will be shown first.
Example:
l = [] l.append( MenuItem('Options', self.on_new_game ) ) l.append( MenuItem('Quit', self.on_quit ) ) self.create_menu( l, zoom_in(), zoom_out() )
Parameters: - items : list
list of BaseMenuItem that will be part of the Menu
- selected_effect : function
This action will be executed when the BaseMenuItem is selected
- unselected_effect : function
This action will be executed when the BaseMenuItem is unselected
- activated_effect : function
this action will executed when the BaseMenuItem is activated (pressing Enter or by clicking on it)
-
draw
()¶
-
on_key_press
(symbol, modifiers)¶
-
on_mouse_motion
(x, y, dx, dy)¶
-
on_mouse_release
(x, y, buttons, modifiers)¶
-
on_text
(text)¶
-
activate_sound
= None¶
-
is_event_handler
= True¶ Receives pyglet events
-
select_sound
= None¶
-
class
MenuItem
(label, callback_func, *args, **kwargs)¶ Bases:
cocos.menu.BaseMenuItem
A menu item that shows a label.
-
draw
()¶
-
generateWidgets
(pos_x, pos_y, font_item, font_item_selected)¶
-
get_item_height
()¶
-
get_item_width
()¶
-
-
class
ToggleMenuItem
(label, callback_func, value=False)¶ Bases:
cocos.menu.MultipleMenuItem
A menu item for a boolean toggle option.
Example:
items.append( ToggleMenuItem('Show FPS:', self.on_show_fps, director.show_FPS) )
-
on_key_press
(symbol, mod)¶
-
-
class
MultipleMenuItem
(label, callback_func, items, default_item=0)¶ Bases:
cocos.menu.MenuItem
A menu item for switching between multiple values.
Example:
self.volumes = ['Mute','10','20','30','40','50','60','70','80','90','100'] items.append( MultipleMenuItem( 'SFX volume: ', self.on_sfx_volume, self.volumes, 8 ) )
-
on_key_press
(symbol, modifiers)¶
-
-
class
EntryMenuItem
(label, callback_func, value, max_length=0)¶ Bases:
cocos.menu.MenuItem
A menu item for entering a value.
When selected,
self.value
is toggled, the callback function is called withself.value
as argument.-
on_key_press
(symbol, modifiers)¶
-
on_text
(text)¶
-
value
¶
-
-
class
ImageMenuItem
(image, callback_func, *args, **kwargs)¶ Bases:
cocos.menu.BaseMenuItem
A menu item that shows a selectable Image
-
draw
()¶
-
generateWidgets
(pos_x, pos_y, font_item, font_item_selected)¶
-
-
class
ColorMenuItem
(label, callback_func, items, default_item=0)¶ Bases:
cocos.menu.MenuItem
A menu item for selecting a color.
Example:
colors = [(255, 255, 255), (100, 200, 100), (200, 50, 50)] items.append( ColorMenuItem( 'Jacket:', self.on_jacket_color, colors ))
-
draw
(*args, **kwargs)¶
-
generateWidgets
(pos_x, pos_y, font_item, font_item_selected)¶
-
on_key_press
(symbol, modifiers)¶
-
-
verticalMenuLayout
(menu)¶
-
fixedPositionMenuLayout
(positions)¶
-
shake
()¶ Predefined action that performs a slight rotation and then goes back to the original rotation position.
-
shake_back
()¶ Predefined action that rotates to 0 degrees in 0.1 seconds
-
zoom_in
()¶ Predefined action that scales to 1.5 factor in 0.2 seconds
-
zoom_out
()¶ Predefined action that scales to 1.0 factor in 0.2 seconds