Trying to Convert a Pygame into Py.Processing

edited June 2016 in Python Mode

I'm not all that familiar with Python Mode in Processing, and have been trying to convert a simple game from Pygame to Processing.

But it appears I can't get from the Play Game screen to actual gameplay - it just crashes and gives me the error "Global name "self" is not defined" in the mouseClicked() function, but it is, isn't it? Either way, I'm sure this is riddled with errors, and can't seem to make it work properly, even though the Pygame version works fine. I know it's a longshot, but can anyone help or offer some advice?

Thanks!

Answers

  • Answer ✓

    I know very little Python Mode (Jython). But I'll try to give some advises:

    • Inside** mouseClicked()**, I believe those self's properties belong to class FlappyBird, right?
    • So you need an instance of that class in order to access them all.
    • I see that game = FlappyBird() statement @ line #87 instantiates a FlappyBird and assigns that reference to global variable game.
    • Therefore you should use that variable to access those properties in place of the unknown self.

    An extra advice:

    • Favor loading resources like images, sounds, etc. before draw() starts, while sketch is still in setup().
    • Remove those loadImage() from class FlappyBird.
    • Instead, pass the already loaded images to FlappyBird's __init__ constructor.
  • Thanks so much! Still working on it, but this was definitely helpful. I don't get immediate errors anymore, but once I press "Play Game" the screen remains black, which probably means the game function is not executing and/or there's an error in the logic.

Sign In or Register to comment.