沮丧 - 水果忍者 Blade 效果
Kivy - fruit ninja Blade effect
我正在尝试为我的游戏创建类似于水果忍者的 CCBlade 效果,因此我正在尝试清除 canvas 的尾巴以使其看起来像水果忍者 blade 但我不知道该怎么做。这是代码
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()
如何在移动手指时清除 canvas 的尾部,使线条看起来像在继续跟随我的手指。它应该看起来像水果忍者 Blade 效果。有没有其他方法可以在 kivy 上实现水果忍者 blade 效果。
您可以尝试类似的方法:
def clearTail(self, touch)
touch.ud['line'].points = touch.ud['line'].points[-10:]
将线限制为线的最后五个点(每个点两个坐标)。
我正在尝试为我的游戏创建类似于水果忍者的 CCBlade 效果,因此我正在尝试清除 canvas 的尾巴以使其看起来像水果忍者 blade 但我不知道该怎么做。这是代码
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()
如何在移动手指时清除 canvas 的尾部,使线条看起来像在继续跟随我的手指。它应该看起来像水果忍者 Blade 效果。有没有其他方法可以在 kivy 上实现水果忍者 blade 效果。
您可以尝试类似的方法:
def clearTail(self, touch)
touch.ud['line'].points = touch.ud['line'].points[-10:]
将线限制为线的最后五个点(每个点两个坐标)。