python - How to use cocos2d's collision_model -


recently, used cocos2d python make game. had trouble collision_model. read documentation still can't use collisionmanager add collidablesprite in example.

in fact, had change actorsprite collidablesprite avoid error. problem be?

import cocos.euclid eu import cocos.collision_model cm  class collidablesprite(cocos.sprite.sprite):     def __init__(self, image, center_x, center_y, radius):         super(actorsprite, self).__init__(image)         self.position = (center_x, center_y)         self.cshape = cm.circleshape(eu.vector2(center_x, center_y), radius)  class actormodel(object):     def __init__(self, cx, cy, radius):         self.cshape = cm.circleshape(eu.vector2(center_x, center_y), radius) 

the documentation showed example initialising collidable sprite. actorsprite come from? have change collidablesprite make class work. , state collision manager add sprites. returns none when call function collisionmaneger.known_objs().

 def __init__(self):     super(page,self).__init__()     self.collision_manager = collisionmanager()     self.collision_manager.add(self.sprite1)     self.collision_manager.add(self.sprite2)     print self.collision_manager.known_objs() 

so, there wrong documentation? or have misunderstood somehow?

it looks example should indeed initialize collidablesprite instead of actorsprite.

collisionmanager class interface. doesn't anything. there 2 implementations in collision_model: collisionmanagerbruteforce , collisionmanagergrid. can use example:

self.collision_manager = collisionmanagerbruteforce() 

but note collisionmanagergrid is more efficient.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -