Thanks for that, exception is ‘could not load texture’
Had to remove ui.image.named as I couldn’t convert it to a texture for SpriteNode
Exception doesn’t really help us much, this is a weird one.
self.background = SpriteNode('IMG_0202.PNG')
except Exception as e:
i added a try catch block, wasn’t sure how to catch the error though. But strangely even trying to list the current dir is not working. I’m not much of a python programmer, am a Swift coder, but I realise now that the strange errors are actually due to it throwing an exception in the init method. My errors happen in other methods due to the rest of the init method not being run.
class MyScene (Scene):
self.background_color = '#000000' #print(os.listdir('.')) try: self.image = ui.Image('IMG_0204.PNG') except: print(os.listdir('.'))
I am now thinking it may be something to do with directory length. This project is anpbout 5 sub folders deep.
I am currently teaching some young kids to code using Pythonista, our current project is Pac Man. As the kids are young I am having to take some shortcuts. For instance instead of building the background with tiles, I just want to load it from an image.
So I have saved some images from the internet and am attempting to load them into my Scene as a SpriteNode. I can import them into Pythonista without any issue, however when I try to use them in the code I get strange errors. Sometime it is ‘could not load image’, but other times it gives errors on future lines, such as if you forget a semi colon.
My image is in the same folder as the code, and I have tried lots of different images. One time one image worked, so I deleted it and tried again (need to ensure it works for kids) and it failed.
I am on iOS11 with the latest version of Pythonista. Has anybody ne experienced this issue or have an ideas?
from scene import *
from joystick import Joystick
from player import Player
from tile import Tile
from direction import Direction
A = Action
class MyScene (Scene):
self.background_color = '#000000' self.background = SpriteNode('IMG_0204.PNG') self.background.position = self.size.width / 2, self.size.height / 2 self.add_child(self.background)
I am playing around with some Fractal drawing using the canvas module. My scripts use recursion and I am finding that if I go to many levels deep (10ish) and “wide” then the output flashes up briefly and disappears. By “wide” l am referring to the fact that my recursion doubles each time I go down a level as it calls itself twice. The result is that the stack probably resembles the Fractal Tree I am trying to draw.
Adding begin_updates and end_updates just causes a crash.
Any advice on how I might get around this?
from math import pi
def drawBranch( angle, length):
if length < 10: return canvas.draw_line( 0, 0, 0, length) canvas.translate( 0, length) canvas.save_gstate() canvas.rotate( angle * pi / 180) drawBranch( angle, length -10) canvas.restore_gstate() canvas.save_gstate() canvas.rotate( - angle * pi / 180) drawBranch( angle, length -10) canvas.restore_gstate()
width = 800
height = 800
canvas.set_size( width, height)
canvas.translate( width / 2, 0)
drawBranch( 17, 120)