• Serpensine

    Wow, thanks for the in-depth response. I completely forgot about the fact that it would have to store every texture I was making. I understand that I am pushing the limits a bit trying to render so many nodes, but your optimisation seems to have greatly helped with both of the problems I mentioned. Thanks a bunch.

    posted in Pythonista read more
  • Serpensine

    Hello. I have been working on creating an isometric height map in Pythonista, and I have run into 2 problems. The code I have pasted here creates a 2D array of elements which is self.map_width lists long and every list has self.map_width random integers between 1 and 255. For every integer in the array, it creates 3 shape nodes to create the isometric tile which has a height equal to the integer. It then uses render_to_texture() to create one sprite node with the image of the three sides of the tile, and makes that sprite node a child of self.height_tile_node, which in turn is a sub node of the scene.

    Firstly, when I run the following code after a Pythonista restart, it does not create the right textures for the sprites. The left and right sides are flattened and lose their angle. This is fixed if the code is run again. I would like to know if this is an issue with the way I am creating these tiles, or a bug in the scene module.

    Secondly, the code crashes if self.map_width is put above 29. At 29, it creates 841 isometric tiles and runs at around 40fps. When I put self.map_width up to 30, where it tries to create 900 tiles, it crashes without ever rendering anything. I am wondering if I have hit a limit on the number of shape nodes or sprite nodes that I can create in the scene.

    I have tested these two issues on an iPad 4 and an iPad Air, and the same results have appeared on each. I would be grateful if anybody here knows why these two things happen.

    # coding: utf-8
        from scene import *
        import random
        class MyScene (Scene):
                def create_tile(self, height, position, width = 100):
                        left_path = ui.Path()
                        left_path.move_to(width / -2, 0)
                        left_path.line_to(width / -2, height)
                        left_path.line_to(0, height + math.ceil(width / 4))
                        left_path.line_to(0, width / 4)
                        left_path.line_to(width / -2, 0)
                        right_path = ui.Path()
                        right_path.move_to(width / 2, 0)
                        right_path.line_to(width / 2, height)
                        right_path.line_to(0, height + math.ceil(width / 4))
                        right_path.line_to(0, math.ceil(width / 4))
                        right_path.line_to(width / 2, 0)
                        top_path = ui.Path()
                        top_path.move_to(width / 2, 0)
                        top_path.line_to(width, width / 4)
                        top_path.line_to(width / 2, width / 2)
                        top_path.line_to(0, width/ 4)
                        top_path.line_to(width / 2, 0)
                        new_shape_tile = Node(position = position)
                        left_face = ShapeNode(left_path, position = (width / -4, height / 2), fill_color = '#3fb427', parent = new_shape_tile)
                        right_face = ShapeNode(right_path, position = (width / 4, height / 2), fill_color = '#009900', parent = new_shape_tile)
                        top_face = ShapeNode(top_path, position = (0, height + math.floor(width / 8)), fill_color = '#3aa243', parent = new_shape_tile)
                        terrain_tile = SpriteNode(texture = new_shape_tile.render_to_texture(), position = (position[0], position[1] + height / 2))
                def setup(self):
                        self.width = 100
                        self.map_width = 29
                        self.height_map = []
                        for i in range(0, self.map_width):
                                for k in range(0, self.map_width):
                                        self.height_map[-1].append(random.randint(1, 255))
                        self.height_tile_node = Node(position = (700, -50))
                        self.height_tile_node.scale = 0.32
                        self.height_tile_node.position = (275, 200)
                        for i in range(len(self.height_map) - 1, -1, -1):
                                for k in range(0, len(self.height_map[i])):
                                        tile_node = self.create_tile(self.height_map[i][k], (k * self.width / 2 + i * self.width / 2 - 738, i * self.width / 4 - k * self.width / 4 + 384), self.width)
                def update(self):
        run(MyScene(), show_fps=True)

    posted in Pythonista read more
  • Serpensine

    Ah yes, forgot about that. Works fine now.

    posted in Pythonista read more
  • Serpensine

    Is it possible to get a sound.Player to play in a scene? I have tried the following code in the setup method:

    music_player = sound.Player(file_path)

    But it does not work. sound.play_effect(file_path) does work though, and both of these work when not presented in a scene. Is there a way to make it work?

    posted in Pythonista read more
  • Serpensine

    I have noticed the same thing. At the moment I am converting a PIL image to a ui.Image using the following code (where img is the PIL image)

    imgfile = StringIO.StringIO()
    img.save(imgfile, format='PNG')
    imagestring = imgfile.getvalue()
    ui_image = ui.Image.from_data(imagestring)

    This is the best method I have found in the beta, but unfortunately I don't think there are any built-in functions to do it for you.

    posted in Pythonista read more
  • Serpensine

    In the 1.6 beta, is there a way to recreate the touch methods available for layers (Layer.touch_began, Layer.touch_moved and Layer.touch_ended) with nodes?

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!