Skip to content

Instantly share code, notes, and snippets.

@willrax
Last active August 29, 2015 14:01

Revisions

  1. willrax revised this gist May 10, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion my_scene.rb
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ def add_ground
    2.times do |i|
    ground = SKSpriteNode.spriteNodeWithTexture ground_texture
    ground.position = CGPointMake(x + (i * x * 2), 56)
    ground.runAction scroll_action(x, :ground)
    ground.runAction scroll_action(x, 0.02)

    addChild ground
    end
  2. willrax revised this gist May 10, 2014. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion my_scene.rb
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,6 @@ def scroll_action(x, duration)
    end

    def add_ground
    texture =
    x = CGRectGetMidX(self.frame) + 7

    2.times do |i|
  3. willrax revised this gist May 10, 2014. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions my_scene.rb
    Original file line number Diff line number Diff line change
    @@ -10,11 +10,11 @@ def scroll_action(x, duration)
    end

    def add_ground
    texture = SKTexture.textureWithImageNamed "ground.png"
    texture =
    x = CGRectGetMidX(self.frame) + 7

    2.times do |i|
    ground = SKSpriteNode.spriteNodeWithTexture texture
    ground = SKSpriteNode.spriteNodeWithTexture ground_texture
    ground.position = CGPointMake(x + (i * x * 2), 56)
    ground.runAction scroll_action(x, :ground)

    @@ -34,6 +34,10 @@ def sky_texture
    SKTexture.textureWithImageNamed "skyline.png"
    end

    def ground_texture
    SKTexture.textureWithImageNamed "ground.png"
    end

    def add_skyline
    2.times do |i|
    x_position = mid_x + (i * mid_x * 2)
  4. willrax revised this gist May 10, 2014. 1 changed file with 15 additions and 17 deletions.
    32 changes: 15 additions & 17 deletions my_scene.rb
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,27 @@
    # Video of it in action: http://cl.ly/VSIF

    class MyScene < SKScene
    def scroll_action(x, duration)
    def scroll_action(x, duration)
    width = (x * 2)
    move = SKAction.moveByX(-width, y: 0, duration: duration * width)
    reset = SKAction.moveByX(width, y: 0, duration: 0)

    SKAction.repeatActionForever(SKAction.sequence([move, reset]))
    end

    def add_ground
    texture = SKTexture.textureWithImageNamed "ground.png"
    x = CGRectGetMidX(self.frame) + 7

    2.times do |i|
    ground = SKSpriteNode.spriteNodeWithTexture texture
    ground.position = CGPointMake(x + (i * x * 2), 56)
    ground.runAction scroll_action(x, :ground)

    addChild ground
    end
    end

    def mid_x
    CGRectGetMidX(self.frame)
    end
    @@ -24,29 +37,14 @@ def sky_texture
    def add_skyline
    2.times do |i|
    x_position = mid_x + (i * mid_x * 2)

    skyline = SKSpriteNode.spriteNodeWithTexture sky_texture
    skyline.position = CGPointMake(x_position, mid_y)
    skyline.zPosition = -20
    skyline.scale = 1.12

    skyline.runAction scroll_action(mid_x, 0.1)

    addChild skyline
    end
    end

    def add_ground
    texture = SKTexture.textureWithImageNamed "ground.png"
    x_position = mid_x + 7
    x_position =

    2.times do |i|
    ground = SKSpriteNode.spriteNodeWithTexture texture
    ground.position = CGPointMake(half_width + (i * half_width* 2),56)
    ground.runAction scroll_action(x_position, 0.02)

    addChild ground
    end
    end
    end
  5. willrax revised this gist May 10, 2014. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions my_scene.rb
    Original file line number Diff line number Diff line change
    @@ -38,11 +38,12 @@ def add_skyline

    def add_ground
    texture = SKTexture.textureWithImageNamed "ground.png"
    x_position = mid_x + 7 + (i * half_width* 2),
    x_position = mid_x + 7
    x_position =

    2.times do |i|
    ground = SKSpriteNode.spriteNodeWithTexture texture
    ground.position = CGPointMake(x_position 56)
    ground.position = CGPointMake(half_width + (i * half_width* 2),56)
    ground.runAction scroll_action(x_position, 0.02)

    addChild ground
  6. willrax revised this gist May 10, 2014. 1 changed file with 29 additions and 19 deletions.
    48 changes: 29 additions & 19 deletions my_scene.rb
    Original file line number Diff line number Diff line change
    @@ -1,41 +1,51 @@
    # Video of it in action: http://cl.ly/VSIF

    class MyScene < SKScene
    def scroll_action(x, type)
    duration = type == :ground ? 0.02 : 0.1
    def scroll_action(x, duration)
    width = (x * 2)
    move = SKAction.moveByX(-width, y: 0, duration: duration * width)
    reset = SKAction.moveByX(width, y: 0, duration: 0)

    SKAction.repeatActionForever(SKAction.sequence([move, reset]))
    end

    def add_ground
    texture = SKTexture.textureWithImageNamed "ground.png"
    x = CGRectGetMidX(self.frame) + 7
    def mid_x
    CGRectGetMidX(self.frame)
    end

    2.times do |i|
    ground = SKSpriteNode.spriteNodeWithTexture texture
    ground.position = CGPointMake(x + (i * x * 2), 56)
    ground.runAction scroll_action(x, :ground)
    def mid_y
    CGRectGetMidY(self.frame)
    end

    addChild ground
    end
    def sky_texture
    SKTexture.textureWithImageNamed "skyline.png"
    end

    def add_skyline
    texture = SKTexture.textureWithImageNamed "skyline.png"
    x = CGRectGetMidX(self.frame)

    2.times do |i|
    skyline = SKSpriteNode.spriteNodeWithTexture texture
    skyline.scale = 1.12
    skyline.position = CGPointMake(x + (i * x * 2), CGRectGetMidY(self.frame))
    skyline.zPosition = -20
    x_position = mid_x + (i * mid_x * 2)

    skyline.runAction scroll_action(x, :skyline)
    skyline = SKSpriteNode.spriteNodeWithTexture sky_texture
    skyline.position = CGPointMake(x_position, mid_y)
    skyline.zPosition = -20
    skyline.scale = 1.12

    skyline.runAction scroll_action(mid_x, 0.1)

    addChild skyline
    end
    end

    def add_ground
    texture = SKTexture.textureWithImageNamed "ground.png"
    x_position = mid_x + 7 + (i * half_width* 2),

    2.times do |i|
    ground = SKSpriteNode.spriteNodeWithTexture texture
    ground.position = CGPointMake(x_position 56)
    ground.runAction scroll_action(x_position, 0.02)

    addChild ground
    end
    end
    end
  7. willrax revised this gist May 10, 2014. 1 changed file with 21 additions and 20 deletions.
    41 changes: 21 additions & 20 deletions my_scene.rb
    Original file line number Diff line number Diff line change
    @@ -1,40 +1,41 @@
    # Video of it in action: http://cl.ly/VSIF

    class MyScene < SKScene
    def add_skyline
    texture = SKTexture.textureWithImageNamed "skyline.png"
    x = CGRectGetMidX(self.frame)

    2.times do |i|
    skyline = SKSpriteNode.spriteNodeWithTexture texture
    skyline.scale = 1.12
    skyline.position = CGPointMake(x + (i * x * 2), CGRectGetMidY(self.frame))
    skyline.zPosition = -20

    skyline.runAction scroll_action(x)
    def scroll_action(x, type)
    duration = type == :ground ? 0.02 : 0.1
    width = (x * 2)
    move = SKAction.moveByX(-width, y: 0, duration: duration * width)
    reset = SKAction.moveByX(width, y: 0, duration: 0)

    addChild skyline
    end
    SKAction.repeatActionForever(SKAction.sequence([move, reset]))
    end

    def add_ground
    texture = SKTexture.textureWithImageNamed "ground.png"
    x = CGRectGetMidX(self.frame) + 7

    2.times do |i|
    ground = SKSpriteNode.spriteNodeWithTexture texture
    ground.position = CGPointMake(x + (i * x * 2), 56)
    ground.runAction scroll_action(x)
    ground.runAction scroll_action(x, :ground)

    addChild ground
    end
    end

    def scroll_action(x)
    width = (x * 2)
    move = SKAction.moveByX(-width, y: 0, duration: 0.02 * width)
    reset = SKAction.moveByX(width, y: 0, duration: 0)
    def add_skyline
    texture = SKTexture.textureWithImageNamed "skyline.png"
    x = CGRectGetMidX(self.frame)

    SKAction.repeatActionForever(SKAction.sequence([move, reset]))
    2.times do |i|
    skyline = SKSpriteNode.spriteNodeWithTexture texture
    skyline.scale = 1.12
    skyline.position = CGPointMake(x + (i * x * 2), CGRectGetMidY(self.frame))
    skyline.zPosition = -20

    skyline.runAction scroll_action(x, :skyline)

    addChild skyline
    end
    end
    end
  8. willrax revised this gist May 10, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion my_scene.rb
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # Video: http://cl.ly/VSIF
    # Video of it in action: http://cl.ly/VSIF

    class MyScene < SKScene
    def add_skyline
  9. willrax revised this gist May 10, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion my_scene.rb
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # Video: https://www.dropbox.com/s/e0pw03fu1lz65q4/parallax.mov
    # Video: http://cl.ly/VSIF

    class MyScene < SKScene
    def add_skyline
  10. willrax revised this gist May 10, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions my_scene.rb
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # Video: https://www.dropbox.com/s/e0pw03fu1lz65q4/parallax.mov

    class MyScene < SKScene
    def add_skyline
    texture = SKTexture.textureWithImageNamed "skyline.png"
  11. willrax revised this gist May 10, 2014. 1 changed file with 14 additions and 1 deletion.
    15 changes: 14 additions & 1 deletion my_scene.rb
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,20 @@ def add_skyline
    end
    end

    def scroll_action(x)
    def add_ground
    texture = SKTexture.textureWithImageNamed "ground.png"
    x = CGRectGetMidX(self.frame) + 7

    2.times do |i|
    ground = SKSpriteNode.spriteNodeWithTexture texture
    ground.position = CGPointMake(x + (i * x * 2), 56)
    ground.runAction scroll_action(x)

    addChild ground
    end
    end

    def scroll_action(x)
    width = (x * 2)
    move = SKAction.moveByX(-width, y: 0, duration: 0.02 * width)
    reset = SKAction.moveByX(width, y: 0, duration: 0)
  12. willrax created this gist May 10, 2014.
    25 changes: 25 additions & 0 deletions my_scene.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    class MyScene < SKScene
    def add_skyline
    texture = SKTexture.textureWithImageNamed "skyline.png"
    x = CGRectGetMidX(self.frame)

    2.times do |i|
    skyline = SKSpriteNode.spriteNodeWithTexture texture
    skyline.scale = 1.12
    skyline.position = CGPointMake(x + (i * x * 2), CGRectGetMidY(self.frame))
    skyline.zPosition = -20

    skyline.runAction scroll_action(x)

    addChild skyline
    end
    end

    def scroll_action(x)
    width = (x * 2)
    move = SKAction.moveByX(-width, y: 0, duration: 0.02 * width)
    reset = SKAction.moveByX(width, y: 0, duration: 0)

    SKAction.repeatActionForever(SKAction.sequence([move, reset]))
    end
    end