My apologies if this has been answered before, I searched but couldn’t find it. Also, it should be noted that I’m just learning Python so I could be making silly mistakes.
I’m having an issue where there is a slight delay (about 2 seconds) when touching the left or down touchscreen arrows before the sprite starts moving. This only happens on the edges of the arrows. If you touch the same arrows a bit more away from the edge of the screen they move instantly. There are no issues with the up and right arrows. It almost seems to me like there is some sort of delay built into iOS or Pythonista 3 to allow for accidental screen-edge touches, although I know this isn’t the case as none of my games or apps suffer from this. Here’s my code. Any help would be appreciated.
from scene import *
class MyScene(Scene):
#---------------------------------------------
# All game setup goes here.
#---------------------------------------------
def setup(self):
sz=get_screen_size()
print("Screen: " + str(sz))
self.background_color = '#004f82'
# Load player sprite.
self.player = SpriteNode('emj:Alien_Monster')
self.player.position = (200, 200)
self.player.mv = 1
self.player.moving = False
self.player.direction = 0
self.player.x_mov = 0
self.player.y_mov = 0
self.player.mov_rate = 2
self.add_child(self.player)
print(self.player.size)
# Load Arrow controls.
self.left_arrow = SpriteNode('iow:arrow_left_a_256')
self.left_arrow.alpha = 0.5
self.left_arrow.size = (72, 72)
self.left_arrow.anchor_point = (0, 0)
self.left_arrow.position = (0, 48)
self.add_child(self.left_arrow)
self.right_arrow = SpriteNode('iow:arrow_right_a_256')
self.right_arrow.alpha = 0.5
self.right_arrow.size = (72, 72)
self.right_arrow.anchor_point = (0, 0)
self.right_arrow.position = (96, 48)
self.add_child(self.right_arrow)
self.up_arrow = SpriteNode('iow:arrow_up_a_256')
self.up_arrow.alpha = 0.5
self.up_arrow.size = (72, 72)
self.up_arrow.anchor_point = (0, 0)
self.up_arrow.position = (48, 96)
self.add_child(self.up_arrow)
self.down_arrow = SpriteNode('iow:arrow_down_a_256')
self.down_arrow.alpha = 0.5
self.down_arrow.size = (72, 72)
self.down_arrow.anchor_point = (0, 0)
self.down_arrow.position = (48, 0)
self.add_child(self.down_arrow)
def did_change_size(self):
pass
#---------------------------------------------
# Main game loop. Ran 60 time per second.
#---------------------------------------------
def update(self):
self.update_player()
#---------------------------------------------
# All player logic here.
#---------------------------------------------
def update_player(self):
# Calculate player movement.
x, y = self.player.position
x += self.player.x_mov * self.player.mov_rate
y += self.player.y_mov * self.player.mov_rate
# Keep player on screen.
x = max(0 + self.player.size.w/2, min(x, self.size.w - self.player.size.w/2))
y = max(0 + self.player.size.h/2, min(y, self.size.h - self.player.size.h/2))
# Set new player position.
self.player.position = (x, y)
#---------------------------------------------
# Handle touch screen.
#---------------------------------------------
def touch_began(self, touch):
self.handle_touch(touch)
def touch_moved(self, touch):
self.handle_touch(touch)
def touch_ended(self, touch):
self.player.moving = False
self.player.x_mov = 0
self.player.y_mov = 0
#self.player.direction = 0
def handle_touch(self, touch):
if touch.location in self.left_arrow.frame:
self.player.x_mov = -1
self.player.y_mov = 0
if touch.location in self.right_arrow.frame:
self.player.x_mov = 1
self.player.y_mov = 0
if touch.location in self.up_arrow.frame:
self.player.y_mov = 1
self.player.x_mov = 0
if touch.location in self.down_arrow.frame:
self.player.y_mov = -1
self.player.x_mov = 0
if __name__ == '__main__':
run(MyScene(), orientation=LANDSCAPE, show_fps=True)