Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
How do I add textures to sprites?
-
That solves the issue with the blue gem not appearing, but if I use one of my own images that I imported into the folder
self.spriteName.texture = Texture('IMG_0469.JPG')
returns a "Image not found" error and
self.spriteName.texture = Texture(ui.Image.named('IMG_0469.JPG'))
returns a "Could not load image" error
-
Is the imported image in the same folder as your script?
-
Yes it is
-
@omz Does the folder have to have the same name as the program?
-
No, that's not necessary, but the image shouldn't be in a sub-folder (or you'd need to include the sub-folder's name in the image name).
-
It's not in a sub folder. I have no idea why it's not working.
-
Try...
import os print(os.listdir(os.curdir)) # see if 'IMG_0469.JPG' is in that list
-
from scene import * class MyScene (Scene): def setup(self): self.background_color = 'green' self.spriteName = SpriteNode() self.spriteName.position = self.size / 2 self.spriteName.texture = Texture('plc:Gem_Blue') #self.spriteName.texture = Texture('canvas.png') #self.spriteName.texture = Texture('image000.jpg') self.add_child(self.spriteName) run(MyScene())
-
@heyguy4
Try addingimport os print(os.path.abspath(os.curdir)) print(os.listdir('.'))
at the start of your script. Then, copy and paste the name of the image that gets printed to the console. A common problem is that this is case sensitive, you must type the name exactly as it is printed.
-
I did what you said but I'm still getting the "Image Not Found" Error
-
What was printed when you added @JonB and/or my code?!?
Does adding the following code print True or False?!?
import os print('IMG_0469.JPG' in os.listdir(os.curdir))