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.
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)
-
@Kamozo welcome
For posting code to the forums, please use three backticks
before and after your code. That way it will format correctly. On ios devices holding the quote key will pop up three types of ticks, or, if you post a lot it is helpful to create a shortcut in settings to autoreplace some pattern like three commas to make it easier with an ios keyboard.anyway, if you take a look at the built in docs:
class scene.SpriteNode([texture, position=(0, 0), z_position=0.0, scale=1.0, x_scale=1.0, y_scale=1.0, alpha=1.0, speed=1.0, parent=None, size=None, color='white', blend_mode=0])
A SpriteNode is a node that draws a textured image, a colored square, or a textured image blended with a color. You can also provide a custom shader to create your own rendering effects.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).
So, you need to provide a ui.Image, not a string for initializing with your own image. Clicking the ui.Image link in the docs should take you to the ui.Image reference, which gets initialzed thusly:
ui.Image.named(my_image_name)
-
Thank you, I'll keep that in mind for future reference.
And thank you again for your reply.
Yes, I've read them a few times but I didn't quite seem to understand, I'm used to the old way of doing it, I'm very new to the changes to the scene module.
If it isn't too much to ask, could you give me an example of the changes required for me to achieve this, so I just have to insert the image? Thank you, I may be a novice but I already like this community a lot. -
So, you need to provide a ui.Image, not a string for initializing with your own image.
That's not quite correct.
SpriteNode
either takes ascene.Texture
object or a string (which is basically a shortcut forTexture(image_name)
). You could also create aTexture
from aui.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'
, using'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.
-
-
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.