From: Neil Date: Thu, 18 Jul 2013 15:29:40 +0000 (+0200) Subject: Tweak drawing code. Ensure we try children for touch events before the scroll view... X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=6cefa33d402e3bfff5cef31baa4a77e477d552a5;p=erdslangetjie.git Tweak drawing code. Ensure we try children for touch events before the scroll view, for better behaviour --- diff --git a/erdslangetjie/localwidgets.py b/erdslangetjie/localwidgets.py index fe719be..06f6a0a 100644 --- a/erdslangetjie/localwidgets.py +++ b/erdslangetjie/localwidgets.py @@ -63,18 +63,15 @@ class GameWindow(RelativeLayout): self._background = Widget(size=self.size, pos=(0, 0)) tiles = self.level_obj.get_tiles() bx, by = 0, 0 - for tile_line in tiles: - bx = 0 - for tile in tile_line: - self.draw_tile((bx, by), tile) - bx += TILE_SIZE - by += TILE_SIZE - self.add_widget(self._background) - - def draw_tile(self, pos, tile): with self._background.canvas: - Rectangle(pos=pos, size=(TILE_SIZE, TILE_SIZE), - texture=tile.texture) + for tile_line in tiles: + bx = 0 + for tile in tile_line: + Rectangle(pos=(bx, by), size=(TILE_SIZE, TILE_SIZE), + texture=tile.texture) + bx += TILE_SIZE + by += TILE_SIZE + self.add_widget(self._background) def fix_scroll_margins(self): # We need to call this after app.root is set @@ -282,7 +279,9 @@ class GameWindow(RelativeLayout): self.level_obj.trigger_button(self.nemesis.pos) for map_pos, new_tile in self.level_obj.get_changed_tiles(): pos = (map_pos[0] * TILE_SIZE, map_pos[1] * TILE_SIZE) - self.draw_tile(pos, new_tile) + with self._background.canvas: + Rectangle(pos=pos, size=(TILE_SIZE, TILE_SIZE), + texture=new_tile.texture) return False def _calc_mouse_pos(self, pos): @@ -298,6 +297,7 @@ class GameWindow(RelativeLayout): if self._near_player(pos): self.mouse_move = True self.mouse_start = pos + return True def on_touch_up(self, touch): self.mouse_move = False @@ -311,6 +311,7 @@ class GameWindow(RelativeLayout): pos[1] - self.mouse_start[1]) self.do_move(direction) self.mouse_start = pos + return True class Screen(Widget): @@ -365,11 +366,15 @@ class MyScrollView(ScrollView): def on_touch_down(self, touch): for child in self.children: - child.on_touch_down(touch) + if child.on_touch_down(touch): + return True + return super(MyScrollView, self).on_touch_up(touch) def on_touch_up(self, touch): for child in self.children: - child.on_touch_up(touch) + if child.on_touch_up(touch): + return True + return super(MyScrollView, self).on_touch_up(touch) class GameApp(App):