Last active
April 12, 2020 05:39
-
-
Save GOROman/11ea148a8daca39e913abdccbe8cc544 to your computer and use it in GitHub Desktop.
iOS SpriteKit のテクスチャを動的になんとかしてスプライトにする(エミュレータ移植用)
This file contains hidden or 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
let w = 768 // テクスチャ Width | |
let h = 512 // テクスチャ Height | |
let bpp = 4 // RGBAなので4バイト | |
// RGBAな配列 | |
var image = [UInt8](repeating: 0x00, count: w * h * bpp ) | |
// imageに転送する | |
xxxxx_GetImage( &image ) // エミュレータ側のC関数(Bridging-Headerを使う) | |
let cgsize = CGSize(width: w, height: h) | |
let tex = SKTexture.init(data: Data(image), size: cgsize, flipped: true ) | |
// SpriteKitのスプライトを生成 | |
SKSpriteNode.init(texture: tex, size: cgsize); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
予めSKSpriteNodeはクラスのメンバ(self.spr)にしておいて
self.spr.textute = tex
などで書き換え可能
スプライトの大きさは
self.spr.xScale = xxx
self.spr.yScale = xxxx
でスケーリングできる