使用spritekit做游戏开发时候,图片的素材可能是序列帧,也可能是多帧显示在一张图片上。如果一帧显示在一张图片上的时候,怎么获取每张想要的图片那?
let birdTexture = SKTexture(imageNamed: "bird")
let bird1 = SKTexture(rect:CGRect(origin:birdTexture.textureRect().origin,size:CGSize(width:
birdTexture.textureRect().maxX / 3,height:birdTexture.size().height)),in: birdTexture)
主角帧.append(bird1)
var rect2 = birdTexture.textureRect().origin
rect2.x = rect2.x + birdTexture.textureRect().maxX / 3
let bird2 = SKTexture(rect:CGRect(origin:rect2,size:CGSize(width:birdTexture.textureRect().maxX / 3,in: birdTexture)
主角帧.append(bird2)
var rect3 = birdTexture.textureRect().origin
rect3.x = rect3.x + birdTexture.textureRect().maxX / 3 * 2
let bird3 = SKTexture(rect:CGRect(origin:rect3,in: birdTexture)
主角帧.append(bird3)
这样就拿到了一个图片texture的数组。