V
V
Viktor Paperno2017-03-14 21:31:55
Python
Viktor Paperno, 2017-03-14 21:31:55

Programmatically generating Kivy widgets?

I'm making an arkanoid, I created a class to describe one block. Now the question arose, how to create many blocks? Do not prescribe every time?
And I want to create blocks of the same size, but different colors and in different positions on the screen.
How to do it?
Description kv:

<PongPaddle2>:
    size: 25, 50
    canvas:
        Rectangle:
            pos:self.pos
            size:self.size
        Color:
            rgba: 0, 1, 0, .5

Class description:
class PongPaddle2(Widget):
    status = NumericProperty(0)
    def bounce_ball(self, ball):
        if self.collide_widget(ball) and self.status!=-1:
            vx, vy = ball.velocity
            offset = (ball.center_y - self.center_y) / (self.height / 2)
            bounced = Vector(-1 * vx, vy)
            vel = bounced * 1.1
            ball.velocity = vel.x, vel.y + offset
            self.parent.remove_widget(self)
            self.status=-1

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question