Attached is a little thing I/we built as part of mucking around on the computer with my kids. Started veeery basic and grew a little from there (it still is very very basic).
In short, there's a bug sprite on the screen that you move around,
change its size, and can ask it to draw.
I had a little trouble understanding that to get it to draw you had to
set the _dirty flag (thanks, Lucio!), but having dealt with that, I
now seem to be stepping on someone's toes. Or a bug, maybe.
So I attach the code. On my computer, this happens: I start drawing
(press Enter), move forward, rotate, move forward *twice*, and it
crashes in code that isn't mine.
Weeeird.
Traceback (most recent call last):
File "main.py", line 85, in <module>
director.run(scene)
File
"/tmp/env/lib/python2.5/site-packages/cocos2d-0.3.0-py2.5.egg/cocos/director.py",
line 287, in run
event_loop.run()
File "build/bdist.linux-x86_64/egg/pyglet/app/xlib.py", line 94, in run
File "/usr/lib/python2.5/site-packages/PIL/__init__.py", line 193, in idle
File "/usr/lib/python2.5/site-packages/PIL/__init__.py", line 1217,
in dispatch_event
File "build/bdist.linux-x86_64/egg/pyglet/event.py", line 343, in
dispatch_event
File "build/bdist.linux-x86_64/egg/pyglet/event.py", line 340, in
dispatch_event
File
"/tmp/env/lib/python2.5/site-packages/cocos2d-0.3.0-py2.5.egg/cocos/director.py",
line 303, in on_draw
self.scene.visit()
File
"/tmp/env/lib/python2.5/site-packages/cocos2d-0.3.0-py2.5.egg/cocos/cocosnode.py",
line 577, in visit
c.visit()
File
"/tmp/env/lib/python2.5/site-packages/cocos2d-0.3.0-py2.5.egg/cocos/cocosnode.py",
line 577, in visit
c.visit()
File
"/tmp/env/lib/python2.5/site-packages/cocos2d-0.3.0-py2.5.egg/cocos/cocosnode.py",
line 570, in visit
self.draw()
File
"/tmp/env/lib/python2.5/site-packages/cocos2d-0.3.0-py2.5.egg/cocos/draw.py",
line 171, in draw
self.build_vbo()
File
"/tmp/env/lib/python2.5/site-packages/cocos2d-0.3.0-py2.5.egg/cocos/draw.py",
line 288, in build_vbo
list(bottom) + list(top) + list(far)
TypeError: 'NoneType' object is not iterable
any ideas?
PS: yes, the drawing code has bugs wrt moving off/around the screen,
but that's another issue, and it doesn't crash, and I know how and why
it's broken, and discussed the pedagogical implications of the current
moving-off-the-screen behavior (even without drawing) with the Best
Teacher in the World, and will either fix it (hard) or make moving off
the screen not an option (easy) (bets are 73:1 against me going for
the hard option).
--
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
The trouble with a lot of self-made men is that they worship their creator.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
import cocos
from cocos.director import director
from pyglet.window import key
from math import sin, cos, pi
class PoliLine(cocos.draw.Canvas):
def __init__(self):
super(PoliLine, self).__init__()
self.lines = []
self.color = (255,255,255,255)
self.stroke_width = 2
def add_point(self, point):
self.lines[-1].append(point)
self._dirty = True
def add_line(self, start):
self.lines.append([start])
self._dirty = True
def render(self):
self.set_color(self.color)
self.set_stroke_width(self.stroke_width)
for line in self.lines:
self.move_to(line[0])
for point in line[1:]:
self.line_to(point)
class Test(cocos.layer.Layer):
is_event_handler = True
def __init__(self):
super(Test, self).__init__()
self.sprite = cocos.sprite.Sprite('bug.png')
self.add(self.sprite)
wx, wy = director.get_window_size()
self.sprite.position = wx/2,wy/2
self.drawing = False
self.poliline = PoliLine()
self.add(self.poliline)
def on_key_press(self, k, m):
x, y = self.sprite.position
ang = self.sprite.rotation
d = 0
if k == key.ENTER:
self.drawing = not self.drawing
if self.drawing:
self.poliline.add_line((x,y))
if k == key.LEFT:
ang -= 15
if k == key.RIGHT:
ang += 15
if k == key.UP:
d = 20
if k == key.DOWN:
d = -20
if k == key.SPACE:
self.sprite.scale *= 2
if k == key.BACKSPACE:
self.sprite.scale *= 0.5
if d:
d *= self.sprite.scale
wx, wy = director.get_window_size()
sx, sy = self.sprite.width/4, self.sprite.height/4
x += d * sin(ang*pi/180)
y += d * cos(ang*pi/180)
if self.drawing:
self.poliline.add_point((x,y))
if x > wx + sx:
x = -sx
if x < -sx:
x = wx+sx
if y > wy + sy:
y = -sy
if y < -sy:
y = wy + sy
self.sprite.rotation = ang
self.sprite.position = x, y
if __name__ == '__main__':
director.init(fullscreen=1)
scene = cocos.scene.Scene()
scene.add(Test())
director.run(scene)
<<inline: bug.png>>
