I'm using Pythonista for python and am trying to use Scene to program my game. I am completely new to this. I use colortaleTitle as the name of a SpriteNode, but keep getting a name error stating that colortaleTitle is undefined. I am following the intro to the Scene documentation almost exactly (I think).
So far, I have tried renaming this, but still have not gotten the expected results.
from scene import *
import time
import sound
class ColorTaleMenu (Scene):
def setup(self):
self.background_color = 'black'
self.colortaleTitle = SpriteNode('colortaleTitle.png')
self.colortaleTitle.position = colortaleTitle.size / 2
Scene.add_child(self.colortaleTitle)
I want it to show colortaleTitle.png in the center of the screen.
It changes the background_color to black, but never puts in the image.
Your error is on this line:
self.colortaleTitle.position = colortaleTitle.size / 2
On the right hand side of the assignment, you're trying to access colortaleTitle
, but that's not defined. Instead, you earlier defined self.colortaleTitle
, which is not the same thing (it's an attribute, not a local variable). Try adding a self.
prefix to the variable name and it should fix the issue.