【问题标题】:Kivy - fruit ninja Blade effectKivy - 水果忍者刀片效果
【发布时间】:2018-09-27 09:20:21
【问题描述】:

我正在尝试为我的游戏创建一个类似于水果忍者的 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()

我如何在移动手指时清除画布的尾部,以使线条看起来像继续跟随我的手指一样。它应该看起来像水果忍者刀片效果。有没有其他方法可以在kivy上实现水果忍者刀片效果。

【问题讨论】:

    标签: python python-2.7 kivy kivy-language


    【解决方案1】:

    你可以试试这样的:

    def clearTail(self, touch)
        touch.ud['line'].points = touch.ud['line'].points[-10:]
    

    这将线限制为线的最后五个点(每个点两个坐标)。

    【讨论】:

    • 您的贡献挽救了我的生命。太感谢了。 @约翰
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-04
    • 2016-02-06
    • 2015-03-21
    相关资源
    最近更新 更多