nmo*_*ary 3 ios sprite-kit skshapenode swift
我想绘制一个圆圈并在其中放入一个文本.我能做什么?
如果我移动或调整圆的大小,文本移动或调整大小

var color = UIColor(red: 0x00, green: 0x44, blue: 0x44, alpha: 1)
var Circle = SKShapeNode(circleOfRadius: 100 )
Circle.position = CGPointMake(frame.midX, frame.midY)
Circle.strokeColor = SKColor.blackColor()
Circle.glowWidth = 1.0
Circle.fillColor = color
let myLabel = SKLabelNode(fontNamed:"Chalkduster")
myLabel.text = "Hello, World!";
myLabel.fontSize = 60;
myLabel.position = CGPointMake(frame.midX, frame.midY)
myLabel.fontColor = UIColor.blackColor()
self.addChild(Circle)
Run Code Online (Sandbox Code Playgroud)
一次拖动两种方法的方法是,您可以将两者都添加到同一个视图中,之后您可以通过触摸事件(如show下面的代码)更改两者的位置.
import SpriteKit
class GameScene: SKScene {
var deltaPoint = CGPointZero
let myLabel = SKLabelNode(fontNamed:"Chalkduster")
var Circle = SKShapeNode(circleOfRadius: 100 )
override func didMoveToView(view: SKView) {
/* Setup your scene here */
var color = UIColor(red: 0x00, green: 0x44, blue: 0x44, alpha: 1)
Circle.position = CGPointMake(frame.midX, frame.midY)
Circle.strokeColor = SKColor.blackColor()
Circle.glowWidth = 1.0
Circle.fillColor = color
myLabel.text = "Hello, World!";
myLabel.fontSize = 20
myLabel.position = CGPointMake(Circle.frame.midX, Circle.frame.midY)
myLabel.fontColor = UIColor.blackColor()
// Add them into same scene
self.addChild(Circle)
self.addChild(myLabel)
}
override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
if let touch = touches.first as? UITouch {
let currentPoint = touch.locationInNode(self)
let previousPoint = touch.previousLocationInNode(self)
deltaPoint = CGPointMake(currentPoint.x - previousPoint.x, currentPoint.y - previousPoint.y)
}
}
override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
deltaPoint = CGPointZero
}
override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
deltaPoint = CGPointZero
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
var newPoint = CGPointMake(self.myLabel.position.x + self.deltaPoint.x, self.myLabel.position.y + self.deltaPoint.y)
// you can drag both item at same time
myLabel.position = newPoint
Circle.position = newPoint
deltaPoint = CGPointZero
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2942 次 |
| 最近记录: |