Using my own images in the scene module, Help would be appreciated.
'#I am new to Pythonista, and the forums, so I apologise if I'm doing anything wrong. The updates to the scene module are confusing me. I really need to be able to add my own image from my photos into the space I mention below, I can't seem to figure it out. I can use the built in sprites just fine, but I want to be able to use my own now.
Help is appreciated, thankyou.
# coding: utf-8 from scene import * class Game (Scene): def setup(self): self.background_color = '#000000' ground = Node(parent=self) x = 0 while x <= self.size.w + 64: tile = SpriteNode('plf:Ground_SnowMid', position=(x, 0)) ground.add_child(tile) x += 64 self.player = SpriteNode('') #This is where I want to add an image of my own. self.player.anchor_point = (0.5, 0) self.player.position = (self.size.w/2, 32) self.add_child(self.player) if __name__ == '__main__': run(Game(), LANDSCAPE, show_fps=True)
So, you need to provide a ui.Image, not a string for initializing with your own image.
That's not quite correct.
SpriteNodeeither takes a
scene.Textureobject or a string (which is basically a shortcut for
Texture(image_name)). You could also create a
ui.Image, but that wouldn't be necessary here (that's basically just for drawing custom shapes etc. without a corresponding image file).
When you import a photo, it gets a file name in the library. It should be possible to just replace
'plf:Ground_SnowMid'with something like
'Image01.jpg'(or whatever the name of your imported photo is). Note that the extension (jpg, png...) is required, and that the name is case-sensitive, so if the filename is
'image.jpg'wouldn't work. Files from the photo library tend to have all-uppercase names.
Thank you for the reply.
How do I get the name of the image?
In the "images" section of Pythonista, I have the sprite I wish to use, and it has a name something like "IMG.3836.PNG" or something very similar, but it doesn't seem to work.
Did you insert the name directly from the "Files" section in the image picker or type it by hand?
By hand. How do I insert the name directly?
My bad.. didn't actually try it. Look like the docs need update
When initializing a SpriteNode, you can provide the texture as either a Texture object, a ui.Image, or the name of a built-in image (a string).
@Kamozo Look for the + button at the top of the screen, then click over to images, the select File
I've already tried it, it's empty.
@JonB You're quite right, I'll correct that.
@Kamozo Do you mean the image picker is empty, or the sprite that you're trying to create in the scene? Are you sure that your imported image file is in the same folder as your script? Does it show up in the library (when tapping the "≣" button)?
Thank you so much guys, I've figured it, it really means a lot that you guys took the time to help me.
I didn't have it in the same folder as my script, ameteur mistake.
But then again I am an ameteur, so it's to be expected.
Thanks again, this was A LOT easier to understand, it's great to finally get this sorted.