0
我在一個小部件上有兩個移動小部件(橢圓)和一個函數,它們可以在碰撞時定義如何處理,但它們之間相互碰撞時會留下很多空間。如何使兩個小部件碰撞更近kivy
我不認爲所有的代碼很重要,因爲它相當多。
的小部件構造方式基本是這樣的:
class Snake(Widget):
velocity_x = NumericProperty(0)
velocity_y = NumericProperty(0)
velocity = ReferenceListProperty(velocity_x, velocity_y)
def move(self):
self.pos = Vector(*self.velocity) + self.pos
class EvilSnake(Widget):
velocity_x = NumericProperty(0)
velocity_y = NumericProperty(0)
velocity = ReferenceListProperty(velocity_x, velocity_y)
class SnakeGame(Widget):
evil_snaky = ObjectProperty(None)
snaky = ObjectProperty(None)
def __init__(self, *args, **kwargs):
super(SnakeGame, self).__init__(*args, **kwargs)
Clock.schedule_interval(self.update, 1/60.)
def begin(self, vel=(1, 0), *args):
#begin method
def game_over(self, *args):
# game over method
def update(self, dt, *args):
#methodes for movement
#snakes collide:
if self.snaky.collide_widget(self.evil_snaky):
self.game_over()
.kv部分:
<Snake>:
size: 50, 50
canvas:
Color:
rgba: 1,1,1,1
Ellipse:
pos: self.pos
size: self.size
<EvilSnake>:
size: 50, 50
canvas:
Color:
rgba: 1,1,1,1
Ellipse:
pos: self.pos
size: self.size
<SnakeGame>:
snaky: snake
evil_snaky: evilsnake
# canvas instructions
Snake:
id: snake
center: self.parent.center
EvilSnake:
id: evilsnake
center: self.parent.center[0]-70, self.parent.center[1]
他們碰撞和碰撞方法不會做自己應該,但快了很多,我本來想要。當它們碰撞時它看起來像這樣: http://postimg.org/image/uir5jqpht/
是否有任何簡單的方法使它們相互碰撞真的很近?
謝謝,正是我想要的! – Larisa