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.
Possible to resize SpriteNode image?
-
Hi, I'm new to Pythonista, so I'm sorry if this is a very basic question. I've made a simple Memory-like card game, with three levels. The cards have an image on each side (a back and a face), and the image size and card size is 150 square. That works fine for the first two levels, but the third level has a 6x6 board, and is larger than the iPad screen width. Is there a way to resize the images in the code? I tried resizing the Tile size, but it's set by the texture so that didn't work. So I tried changing the texture size, but got the error that Texture.size is read-only.
I know this must be a common thing to do (eventually I'd like to resize them based on display size as well), and I'm hoping I won't need to create multiple sizes of each image, because before I'm done there's going to be a lot of them.
Thanks in advance!
-
SpriteNode.size?
import scene class MyScene(scene.Scene): def setup(self): scene.SpriteNode('card:BackBlue2', parent=self, position=(100, 130)) scene.SpriteNode('card:BackRed2', parent=self, position=(300, 220), size=(240, 380)) if __name__ == '__main__': scene.run(MyScene())
-
I'd recommend setting the
scale
attribute. Setting thesize
(as @ccc has shown) would also work, but you would need to set it again when you change the texture of a sprite.It might actually be easier to set the
scale
of the entire scene instead of scaling each card individually. -
Ah, I knew I must be missing something obvious! I implemented the .size solution, and it works great, though I did have to repeat it when the cards turned over, and when they turned back again (if there's no match). I'll try the scale solution later to see if I can save a few lines of code.
Thank you both!