2015-08-13 11 views
5

कैसे दिखा सकता हूं नीचे दिखाए गए कोड के साथ मैं अपने दृश्य में एक गोलाकार करने में सक्षम हूं। नीली पृष्ठभूमि के साथ ... मैं आईओएस में दृश्यकिट के लिए नया हूं। मैं जानना चाहता हूं कि हम उस वस्तु को कैसे स्थानांतरित कर सकते हैं (क्षेत्र को खींचें) दूसरी स्थिति (ड्रॉप) पर।Scenekit - मैं

override func viewDidLoad() { 
    super.viewDidLoad() 
    sceneView = SCNView(frame: self.view.frame) 
    sceneView.scene = SCNScene() 
    self.view.addSubview(sceneView) 


    let groundGeometry = SCNFloor() 
    groundGeometry.reflectivity = 0 
    let groundMaterial = SCNMaterial() 
    groundMaterial.diffuse.contents = UIColor.blueColor() 
    groundGeometry.materials = [groundMaterial] 
    ground = SCNNode(geometry: groundGeometry) 

    let camera = SCNCamera() 
    camera.zFar = 10000 
    self.camera = SCNNode() 
    self.camera.camera = camera 
    self.camera.position = SCNVector3(x: -20, y: 15, z: 20) 
    let constraint = SCNLookAtConstraint(target: ground) 
    constraint.gimbalLockEnabled = true 
    self.camera.constraints = [constraint] 

    let ambientLight = SCNLight() 
    ambientLight.color = UIColor.darkGrayColor() 
    ambientLight.type = SCNLightTypeAmbient 
    self.camera.light = ambientLight 

    let spotLight = SCNLight() 
    spotLight.type = SCNLightTypeSpot 
    spotLight.castsShadow = true 
    spotLight.spotInnerAngle = 70.0 
    spotLight.spotOuterAngle = 90.0 
    spotLight.zFar = 500 
    light = SCNNode() 
    light.light = spotLight 
    light.position = SCNVector3(x: 0, y: 25, z: 25) 
    light.constraints = [constraint] 

    let sphereGeometry = SCNSphere(radius: 1.5) 
    let sphereMaterial = SCNMaterial() 
    sphereMaterial.diffuse.contents = UIColor.greenColor() 
    sphereGeometry.materials = [sphereMaterial] 
    sphere1 = SCNNode(geometry: sphereGeometry) 
    sphere1.position = SCNVector3(x: -15, y: 1.5, z: 0) 


    sceneView.scene?.rootNode.addChildNode(self.camera) 
    sceneView.scene?.rootNode.addChildNode(ground) 
    sceneView.scene?.rootNode.addChildNode(light) 

    sceneView.scene?.rootNode.addChildNode(sphere1) 

} 

उत्तर

1

मी, मैंने कुछ महीनों पहले उद्देश्य के साथ दृश्यकिट की कोशिश की है, यह समाधान को सामान्य बनाने में आपकी मदद कर सकता है। नोड्स के ड्रैग और ड्रॉप के लिए मैंने UIPanGestureRecognizer का उपयोग किया। पैनिंग (चलती) के लिए

// इशारा पहचानकर्ता

UIGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanFrom:)]; 
[[self view] addGestureRecognizer:panGestureRecognizer]; 

// फिर "handlePanFrom"

- (void)handlePanFrom:(UIPanGestureRecognizer *)recognizer { 


    if (recognizer.state == UIGestureRecognizerStateChanged) 
    { 
     //Getting the new location of the view after pan gesture 
     CGPoint translation = [recognizer translationInView:recognizer.view]; 

     //Converting this translation as per the SpriteKit coordinates 
     translation = CGPointMake(translation.x, -translation.y); 

     //Changing the position of sphere node with the translation 
     CGPoint position = [sphere position]; 
     [sphere setPosition:CGPointMake(position.x + translation.x, position.y + translation.y)]; 

     //Resetting the values of recognizer 
     [recognizer setTranslation:CGPointZero inView:recognizer.view]; 

    } 
    else if (recognizer.state == UIGestureRecognizerStateEnded) 
    { 
     float scrollDuration = 1; 
     CGPoint velocity = [recognizer velocityInView:recognizer.view]; 

     //Taking current position of sphere node 
     CGPoint pos = [sphere position]; 

     //Finding change in position on the basis of velocity and scroll duration 
     CGPoint p = mult(velocity, scrollDuration); 

     //Calculating new position of the sphere 
     CGPoint newPos = CGPointMake(pos.x + p.x, pos.y - p.y); 

     [sphere removeAllActions]; 

     //Action for moving the sprite to the new location 
     SKAction *moveTo = [SKAction moveTo:newPos duration:scrollDuration]; 
     [moveTo setTimingMode:SKActionTimingEaseOut]; 
     [sphere runAction:moveTo]; 
    } 
} 

में अधिक मदद के लिए आप इस अच्छा ट्यूटोरियल http://www.raywenderlich.com/44270/sprite-kit-tutorial-how-to-drag-and-drop-sprites

+0

हाई जांच कर सकते हैं .. कोड के लिए धन्यवाद .. लेकिन यह ठीक काम नहीं कर रहा है ... क्षेत्र एससीएनएनओडी है और मैं एसकेएक्शन नहीं दे सकता। (मैंने स्प्राइटकिट आयात किया और एसकेएक्शन की कोशिश की) और स्थिति के साथ भी समस्या: एससीएनवीक्टर में आईएम प्राप्त करने की स्थिति 3 .. इसे CGPoint में कनवर्ट करना असफल रहा .. – Mee

+0

मी .. सोरीकिट के बजाए spriteKit के लिए कोड प्रदान करने के लिए क्षमा करें। मुझे उस पर ध्यान देना चाहिए था। – Jaideep

+0

क्या आप दृश्यावली के लिए कोड अपडेट कर सकते हैं – madLokesh

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