Tan
Tan

Reputation: 53

How to make images move in kivy

I'm trying to make my bird image move up and then automatically come down. I was watching a youtube video on this here's the link https://www.youtube.com/watch?v=2dn_ohAqkus&ab_channel=ErikSandberg his seems to be working but not mines. Around Minute 14 he starts coding about what I'm talking about. One thing that does work for me is when I click on the screen the bird changes. Here's my code

class GameScreen(Screen):
pass


class Bird(Image):
    velocity = NumericProperty(0)

def on_touch_down(self, touch):
    self.source = "icons/bird2.png"
    self.velocity = 150
    super().on_touch_down(touch)

def on_touch_up(self, touch):
    self.source = "icons/bird1.png"
    super().on_touch_up(touch)


def move_bird(self, time_passed):
    bird = self.root.ids.bird
    bird.y = bird.y + bird.velocity * time_passed
    bird.velocity = bird.velocity - self.GRAVITY * time_passed

    Clock.schedule_interval(self.move_bird, 1/60)

my kivy code note this in inside a FloatLayout

Bird:
    source: "icons/bird1.png"
    size_hint: None, None
    size: 475, 475
    pos_hint: { "center_x": .5, "center_y": .4}
    id: bird

Upvotes: 0

Views: 52

Answers (1)

John Anderson
John Anderson

Reputation: 39092

You will not be able to change the bird position when you have set pos_hint (as you did in the kivy code). The pos_hint will take priority over pos. Try replacing the pos_hint with some initial pos in the kivy code.

Upvotes: 1

Related Questions