• mikael

    Here's a pool/billiards table I am using as a testbed for the SpriteKit wrapper.

    Pool table

    You can actually play 8-ball with it, but mainly demo-pool.py tests and demonstrates how to:

    1. Create a "hollow sprite" - the sides of the pool table, for the balls to bounce in.
    2. Make a node (the table) unmoveable by setting dynamic to False.
    3. Make nodes for display only (the pockets) by setting body to None.
    4. Create a gravity field node (in the pockets) to simulate the small slope into the pockets.
    5. Limit the effect of the gravity field to a small circular region - first version pulled the balls clear across the table, which made the game a bit too easy. :-)
    6. Manage the touches on the cue ball with its internal coordinate system that of course rotates with the ball.
    7. Use category_bitmask and contact_bitmask to detect when the ball enters a pocket.
    8. Use update to make changes that cannot be made while the simulation step is running (moving balls to the side of the table).
    9. Use category_bitmask and collision_bitmask to temporarily prevent a pocketes cue ball from interacting with the table or other balls when it is being moved back to the table.

    I think that this also demonstrates the relative power of SpriteKit, as the demo is only about 200 lines of code.

    posted in Pythonista read more
  • mikael

    @Ichicoro, maybe check @JonB’s code for Overlay?

    posted in Pythonista read more
  • mikael

    Demo gif

    Got excited about using SpriteKit, and quickly noted that it is not fun to use without a Python wrapper, so.

    SpriteKit is interesting mainly if you need some 2D physics like collisions or field effects.

    Here‘s a simple example demonstrating some features available so far:

    scene = Scene(
      background_color='black',     #1
      physics=SpacePhysics)         #2
      
    class SpaceRock(SpriteNode):    #3
      
      def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.angular_velocity = random.random()*4-2
        self.touch_enabled = True   #4
        
      def touch_ended(self, touch): #4
        self.velocity = (
          random.randint(-100, 100),
          random.randint(-100, 100)
        )
      
    ship = SpriteNode(
      image=ui.Image('spc:EnemyBlue2'), 
      position=(150,600),
      velocity=(0, -100),          #5
      parent=scene)
      
    rock = SpaceRock(
      image=ui.Image('spc:MeteorGrayBig3'), 
      position=(170,100),
      velocity=(0,100),
      parent=scene)
      
    scene.view.present()
    

    Points to note:

    1. Many familiar features work as they do in the scene module, like setting colors etc.
    2. Physics settings like gravity, linear damping (air friction) and restoration (bounciness) can be set with convenient packages.
    3. All nodes are inheritable.
    4. Individual nodes are touchable (and thus support gestures as well).
    5. Physics are accessible without explicitly playing with SpriteKit physicsBody.

    This is work in progress, available on github. If you are interested in using SpriteKit in this way, let me know and we can guide the wrapping progress in a useful way.

    posted in Pythonista read more
  • mikael

    @cvp, works splendidly, thank you! No way I would have gotten there on my own.

    posted in Pythonista read more
  • mikael

    The following crashes on the last line and in objc_util.py on line 897. Any ideas how to get this working?

    from objc_util import *
    load_framework('SpriteKit')
    SKShapeNode = ObjCClass('SKShapeNode')
    
    cg_points = [CGPoint(0,0), CGPoint(10,5), CGPoint(5,0)]
    
    node = SKShapeNode.shapeNodeWithSplinePoints_count_(cg_points, len(cg_points))
    

    posted in Pythonista read more
  • mikael

    @Valiarnt, can you share some code?

    posted in Pythonista read more
  • mikael

    @shinyformica, thanks (again) for all the ObjC heavy lifting you did back in this thread.

    I had a dire need for some gradients, so I packaged your code into a class and added the radial option (here).

    Some usage examples:

    Linear gradient, left to right, adjusting the location of the color shift for best effect:

    Gradient(['grey', 'black'], locations=[0.0, 0.6])
    

    Radial gradient from center:

    Gradient(['white', 'transparent'], radial=True, width=200, height=200)
    

    Finer control available with the additional parameters, I can detail those if someone has a need - too late now for serious documentation.

    posted in Pythonista read more
  • mikael

    @shinyformica, for the exact location you probably need ObjC, see here.

    posted in Pythonista read more
  • mikael

    @shinyformica, the following works. Setting content_offset before present does not - offset is set, but gets set again back to (0,0).

    Hope this helps.

    #coding: utf-8
    from ui import *
    import editor
    
    '''
    Dummy
    lines
    to
    have
    something
    to
    scroll
    to
    '''
    
    l = ListDataSource(editor.get_text().splitlines())
    v = TableView()
    v.data_source = l
    v.background_color = 'white'
    v.present()
    v.content_offset = (0,100)
    

    posted in Pythonista read more
  • mikael

    @virexcr, unfortunately you will not be able to install compiled C code in the Pythonista sandbox on iOS, due to Apple restrictions. Cython naturally needs to compile C, and probably also needs some new C components to work.

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!