Hi,
I am trying to create a basic 'paginated' menu using cocs2d + python under
linux.
No matter what I try, I get a segmentation fault during the 'create_menu'
call when
it tries to instantiate page 2. Can anyone point out something that I'm
doing wrong here?
or is this a valid bug?
Note that this is only a slightly modified version of one of the samples
included with cocos,
all of which ran fine. Is it not possible to just dynamically create menu's
& scenes and push them
onto the director?
Thanks for any help
Andre
-----8<-------------
import sys
import os
import pyglet
from pyglet.gl import *
from cocos.director import *
from cocos.menu import *
from cocos.scene import *
from cocos.layer import *
from cocos.actions import *
from cocos.sprite import Sprite
PER_PAGE = 5
ALL_ITEMS = ["Item %s" % i for i in range(25)]
class PagedMenu(Menu):
def __init__(self, pagenum):
self.pagenum = pagenum
offset = (pagenum-1) * PER_PAGE
super( PagedMenu, self ).__init__("Items %s-%s" % (offset,
offset+PER_PAGE))
pyglet.font.add_directory('.')
self.font_title['font_name'] = 'You Are Loved'
self.font_title['font_size'] = 64
self.font_item['font_name'] = 'You Are Loved'
self.font_item_selected['font_name'] = 'You Are Loved'
self.menu_valign = CENTER
self.menu_halign = LEFT
items = ALL_ITEMS[offset:offset+PER_PAGE]
menuitems = []
for idx, i in enumerate(items):
menuitems.append(MenuItem("%s. %s" % (idx, i), lambda idx=idx:
self.on_choice(idx)))
menuitems.append(MenuItem(">>", lambda: self.nextpage()) )
self.create_menu( menuitems, zoom_in(), zoom_out() )
def nextpage(self):
scene = Scene(PagedMenu(self.pagenum + 1))
def init():
director.init( resizable=True )
def start():
director.set_depth_test()
firstpage = PagedMenu(1)
scene = Scene( firstpage )
return scene
def run(scene):
director.run( scene )
if __name__ == "__main__":
init()
s = start()
run(s)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"cocos2d discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cocos-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---