you need to design your scene so that you don't hardcode sizes, but instead base everything on the screen size, width and height.
One approach would be to set the Scene.view.transform scale based on the minimum ratio between current screen size and your design size. This would be the easiest -- for instance if you hard coded everything like positions, or motions in pixels, etc. However, this might not work for really big discrepancies, and may not be the fastest.
from scene import *
import random
design_size=Size(1024,768)
sz=get_screen_size()
size_ratio=min([x/y for x,y in zip(tuple(sz),tuple(design_size))])
'''
approach 1: design everything for design_size, but then scale using view.transform. this is probably not the most efficient way, and also your aspect ratio will be fixed.
'''
class MyScene(Scene):
def setup(self):
self.size=design_size
self.setup_map()
self.view.transform=ui.Transform.scale(size_ratio,size_ratio)
def setup_map(self):
#create "road" by scaling cards to just fit
x=0
while x<self.size.width:
imagename=random.choice(['plf:BG_Blue_desert','plf:BG_Blue_grass',
'plf:BG_Blue_land','plf:BG_Blue_shroom'])
tile=SpriteNode(imagename)
tile.size=tile.size*(self.size.width/tile.size.width/2.)
tile.anchor_point=(0,1)
tile.position=(x,self.size.height)
self.add_child(tile)
x+=tile.size.width
x=0
while x<self.size.width:
imagename='plf:Ground_DirtMid'
tile=SpriteNode(imagename)
tile.size=tile.size*(self.size.width/tile.size.width/3.5)
tile.anchor_point=(0,0)
tile.position=(x,0)
self.add_child(tile)
x+=tile.size.width
#for testing purposes
s=MyScene()
run(s)
Another approach: use the size ratio to scale sprite sizes, but do all of your math based on the scene size. so road_speed=0.7 changes to road_speed=0.7*size_ratio, and you have to scale all of your sprites, etc. but you would draw your background to cover the full screen which might be taller or wider than what you designed for.