Last active
September 23, 2016 05:27
-
-
Save tanduynguyen/a5e1e3db1ddcc380e5c628b50c17fb41 to your computer and use it in GitHub Desktop.
initWithSpriteSheetNamed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created by Duy Nguyen on 22/9/16. | |
// | |
import SpriteKit | |
class Entity { | |
// var mAnimatingFrames = Entity.initWithSpriteSheetNamed("SpriteSheetNamed", sourceRect: CGRectMake(0, 0, 1600, 300), numberOfSprites: 6) | |
class func initWithSpriteSheetNamed(spriteSheet: String, sourceRect: CGRect, numberOfSprites: Int) -> [SKTexture] { | |
var mAnimatingFrames = [SKTexture]() | |
let ssTexture = SKTexture(imageNamed: spriteSheet) | |
ssTexture.filteringMode = .Nearest | |
var sx = sourceRect.origin.x | |
let sy = sourceRect.origin.y | |
let sHeight = sourceRect.size.height | |
let sWidth = sourceRect.size.width / CGFloat(numberOfSprites) | |
for _ in 1...numberOfSprites { | |
let cutter = CGRectMake(sx, sy/ssTexture.size().width, sWidth/ssTexture.size().width, sHeight/ssTexture.size().height) | |
let temp = SKTexture(rect: cutter, inTexture: ssTexture) | |
mAnimatingFrames.append(temp) | |
sx += sWidth / ssTexture.size().width | |
} | |
return mAnimatingFrames | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment