我想为我的游戏创建一个像水果忍者那样的CCBlade效果,所以我试图清除画布的尾部,使其看起来像水果忍者刀片那样,但是我不知道该怎么做。这是代码
from random import random
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.graphics import Color, Line
class Blade(Widget):
def on_touch_down(self, touch):
color = (random(), 1, 1)
with self.canvas:
Color(*color, mode='hsv')
touch.ud['line'] = Line(points=(touch.x, touch.y), pointsize=5)
def on_touch_up(self, *touch):
self.canvas.clear()
def on_touch_move(self, touch):
touch.ud['line'].points += [touch.x, touch.y]
self.clearTail(touch)
def clearTail(self, touch):
#How can i clear the tail of the canvas as i move my finger
#so that the line looks like it continuesly follows my finger
#I want the lenght of the line to be about 5cm or a bit long
#And no matter how long i move my finger
#the line must follows it and must not exceed 5cm or a bit longer (maybe 7cm - 15cm)
#AM TRYING TO ARCHIEVE CCBLADE EFFECT LIKE THAT OF FRUIT NINJA
pass
class BladeApp(App):
def build(self):
parent = Widget()
self.bldEfx = Blade()
parent.add_widget(self.bldEfx)
return parent
if __name__ == '__main__':
BladeApp().run()
当我移动手指时,如何清除画布的尾部,以使线条看起来像连续跟随我的手指。它看起来应该像水果忍者刀锋效果。我还有其他方法可以在猕猴桃上达到水果忍者之刃的效果吗?
答案 0 :(得分:0)
您可以尝试以下操作:
def clearTail(self, touch)
touch.ud['line'].points = touch.ud['line'].points[-10:]
将线限制为该线的最后五个点(每个点两个坐标)。