I made a script using scene module. Basically it shows a different "image" depending on horizontal touch.location.
from scene import *
import ui
glyphsDict = {} # My dictionary with paths to draw
class MyScene (Scene):
def setup(self):
self.myPath = ShapeNode(glyphsDict[1]) # first path to draw
self.add_child(self.myPath)
self.background_color = 'lightgrey'
def touch_began(self, touch):
x, y = touch.location
z = int(x/(10.24/2)+1)
self.myPath.path = glyphsDict[z] # Setting a new path to draw
def touch_moved(self, touch):
x, y = touch.location
z = int(x/(10.24/2)+1)
self.myPath.path = glyphsDict[z] # Setting a new path to draw
run(MyScene())
Before that i did the same using SpriteNode and swapping textures. I had 200 .gif images 7KB each (1.4MB summed up) and while the app crashed from time to time i got a rather smooth result if i "loaded" all the images by slowly moving my finger across the screen.
The version with SpriteNode and images looked like this: https://www.instagram.com/p/BSL9ea8g0dv/
I thought i'd move to drawing paths and the code above reflects that. My path information is 200KB so 7 times smaller that all the .gif's i was loading before. But now the animation is super slow and looks like 2fps or is not reacting at all if i move my finger very fast. On the bright side, I don't see the app crashing anymore.
How can i improve on this? Why drawing paths is slower than loading images that are bigger?