Question

I am trying to make flappy birds copy with Kivy, but at the moment I am having hard times. The problem is I don't know how to create multiple widgets in view.

Now I have in my kv file:

<Game>:
    col: column
    Column:
        id: column

<Column>:
    pos: 0, 0
    canva:
        Rectangle:
            pos: self.top_column_position
            size: 30, self.height
        Rectangle:
            pos: self.bottom_column_position
            size: 30, self.height

At the moment I am able to make single column, so the question is how to make so I could have multiple columns?

Was it helpful?

Solution

You kv language syntax has some problems:

  • You're missing indentation (this may be a typo), e.g. the lines below <Game>: should be indented by 4 extra spaces.
  • You wrote canva where you mean canvas.
  • Widgets cannot be added beneath the canvas, as you have written. The canvas is for graphics instructions.

I don't know what you mean about columns, you haven't given any information about what layouts you're using. In general, a solution might be to make your Game widget subclass BoxLayout, then simply add multiple column widgets beneath it and let this BoxLayout take care of rearranging and positioning them.

I previously implemented the basic mechanics of the game, available here. I took quite a different approach to what you seem to be doing, and the implementation is very basic, but perhaps it can help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top