2016-06-20 17 views
5

मैं एक कैनवास प्राप्त करना चाहता हूं जिसे मैं आकर्षित करने के लिए उपयोग कर सकता हूं। लक्ष्य आईओएस आधारित स्विफ्ट खेल का मैदान होगा। मैंने प्रलेखन की खोज की और मुझे कैनवास नामक एक वस्तु नहीं मिली, लेकिन अगर ऐसा कुछ है तो यह मेरे लिए भी अच्छा होगा।एक स्विफ्ट प्लेग्राउंड में कैनवास कैसे प्राप्त करें

+1

पर Playground डाउनलोड करें आप ड्राइंग कैनवास के रूप में 'UIView' का उपयोग कर सकते हैं। – Moritz

उत्तर

7

आप इस तरह के कुछ उपयोग कर सकते हैं, ध्यान दें कि आपको स्प्राइट किट कक्षाओं का उपयोग करने की आवश्यकता नहीं है।

import UIKit 
import PlaygroundSupport 
import SpriteKit 


// Playground Container Setup 
// 
// 
let containerWidth: CGFloat = 667.0 
let containerHeight: CGFloat = 375.0 
let containerCenter: CGPoint = CGPoint(x: (containerWidth/2), y: (containerHeight/2)) 


let containerView = SKView(frame: CGRect(x: 0.0, y: 0.0, width: containerWidth, height: containerHeight)) 


PlaygroundPage.current.liveView = containerView 


let containterScene: SKScene = SKScene(size: CGSize(width: containerWidth, height: containerHeight)) 
containerView.presentScene(containterScene) 

मैं इस सब के लिए आसान बनाने के लिए एक आवरण वर्ग बना लिया अपडेट किया गया। github

+0

मैंने कोड चिपकाया लेकिन PlaygroundSupport आयात गुम मॉड्यूल के बारे में एक्सकोड 7 में एक त्रुटि संदेश उत्पन्न करता है। – gyurisc

+2

'प्लेग्राउंड सपोर्ट' मॉड्यूल केवल स्विफ्ट 3.0 के साथ एक्सकोड 8 में उपलब्ध है। – Sean

+1

एक्सकोड 7 में मॉड्यूल 'XCPlayground' का उपयोग करें और' PlaygroundPage.current.liveView = containerView' के बजाय निम्न का उपयोग करें: 'XCPShowView (पहचानकर्ता: स्ट्रिंग, देखें: UIView) ' – Sean

संबंधित मुद्दे