以下のようにSKShapeNodeを利用したLineクラスを作成し、線を描画させることをしています。
しかしラインの頂点をを142個くらいタッチドラッグで増やしている途中にエラーが出ます。
エラーを検索したところ、頂点の数を減らしたら解決するということが書いてありました。
しかし何が原因で「142」という数が出てきたのかがわからないので、どのように減らしたら良いのかわかりません。
ちなみに、タッチし始めた時に142個追加してもエラーは出ませんでした。
[stack over flow] SpriteKit and UIKit compatibility: OpenGL error when migrating to Swift 2?
このことに関して知識をお持ちの方、アドバイスをいただけないでしょうか?
GameSceneクラス
swift
1 2 3import SpriteKit 4 5class GameScene: SKScene { 6 7 var lines : [Line] = [] 8 var currentLine : Line = Line() 9 10 override func didMoveToView(view: SKView) { 11 // sceneの背景を黒色に設定. 12 self.backgroundColor = UIColor.blackColor() 13 } 14 15 override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { 16 for touch in touches { 17 if(!drawing) 18 { 19 touch_hash = touch.hash 20 genarateLine() 21 addLineVertex(touch.locationInNode(self)) 22 // 以下のコードを有効にしてもエラーが出ない。 23 // for i in (1 ... 142){ 24 // addLineVertex(touch.locationInNode(self)) 25 // updateCurrentLine() 26 // } 27 drawing = true 28 } 29 } 30 } 31 32 override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) { 33 for touch in touches { 34 let touchPos = touch.locationInNode(self) 35 if(drawing) 36 { 37 if(touch_hash == touch.hash) 38 { 39 // 約142回目でエラーが発生する 40 addLineVertex(touchPos) 41 updateCurrentLine() 42 } 43 } 44 } 45 } 46 47 override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) { 48 drawing = false 49 } 50 51 func updateCurrentLine(){ 52 currentLine.DrawObject.removeFromParent() 53 // Pointの更新 54 currentLine.DrawObject = SKShapeNode(points: &(currentLine.Points), count: currentLine.Points.count) 55 self.addChild(currentLine.DrawObject) 56 } 57 58 func genarateLine() 59 { 60 currentLine = Line() 61 lines.append(currentLine) 62 self.addChild(currentLine.DrawObject) 63 } 64 65 func addLineVertex(touchPoint : CGPoint) 66 { 67 currentLine.AddVertex(touchPoint) 68 } 69 70} 71 72
Lineクラス
swift
1import SpriteKit 2import Foundation 3import UIKit 4 5class Line{ 6 var Points : [CGPoint] = [] 7 var DrawObject : SKShapeNode 8 9 init(){ 10 DrawObject = SKShapeNode(points: &Points, count: Points.count) 11 DrawObject.strokeColor = UIColor.whiteColor() 12 } 13 14 func addVertex(point : CGPoint) 15 { 16 Points.append(point) 17 } 18}
エラー文 Assertion failed: (length + offset <= _length), function commit_data, file /BuildRoot/Library/Caches/com.apple.xbs/Sources/Jet_Sim/Jet-1.50/Jet/jet_types_OpenGL.h, line 863.
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。