您的位置:首页 > 移动开发 > Cocos引擎

cocos2d python sprite 响应mouse 事件

2012-07-09 21:18 429 查看
记录下关键代码

不多说明,一看就明白

class card_sprite(Sprite):
is_event_handler=True;
def __init__(self,image):
super(card_sprite,self).__init__(image);
self.is_mouse=False;
self.is_end=False;
def on_enter(self):
super(card_sprite,self).on_enter();
director.window.push_handlers(self.on_mouse_press);
def on_exit(self):
director.window.pop_handlers();
super(card_sprite,self).on_exit();

def on_mouse_press(self,x,y,buttons,modifiers):
if self.is_mouse==True:
if buttons== 1 and x>(self.x-self.width/2) and x<=(self.x-self.width/2+20) and y>=(self.y-self.height/2) and y<=(self.y +self.height/2):
print "click!!!!11";
return;
if self.is_end==True:
if buttons== 1 and x>(self.x-self.width/2) and x<=(self.x-self.width/2+90) and y>=(self.y-self.height/2) and y<=(self.y +self.height/2):
print 'is end click()';
return ;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: