我在网上找到了这个代码:
var Circle = SKShapeNode(circleOfRadius: 40)Circle.position = CGPointMake(500,500)Circle.name = "defaultCircle"Circle.strokecolor = SKcolor.blackcolor()Circle.glowWIDth = 10.0Circle.fillcolor = SKcolor.yellowcolor()Circle.physicsBody = SKPhysicsBody(circleOfRadius: 40)Circle.physicsBody?.dynamic = true //.physicsBody?.dynamic = trueself.addChild(Circle)
但是当我将它放在xcode上并运行应用程序时,游戏场景中没有任何东西出现.
如果你只是想在某个时候画一个简单的圆圈就是这样的:func onelittleCircle(){ var Circle = SKShapeNode(circleOfRadius: 100 ) // Size of Circle Circle.position = CGPointMake(frame.mIDX,frame.mIDY) //MIDdle of Screen Circle.strokecolor = SKcolor.blackcolor() Circle.glowWIDth = 1.0 Circle.fillcolor = SKcolor.orangecolor() self.addChild(Circle)}
以下代码绘制了用户触摸的圆圈.
您可以用下面的代码替换默认的iOS SpriteKit Project“GameScene.swift”代码.
//// Draw Circle At touch .swift// Replace GameScene.swift in the Default SpriteKit Project,with this code.import SpriteKitclass GameScene: SKScene {overrIDe func dIDMovetoVIEw(vIEw: SKVIEw) { /* Setup your scene here */ scene?.backgroundcolor = SKcolor.whitecolor() //background color to white}overrIDe func touchesBegan(touches: NSSet,withEvent event: UIEvent) { /* Called when a touch begins */ for touch: AnyObject in touches { let location = touch.locationInNode(self) makeCirlceInposition(location) // Call makeCircleInPostion,send touch location. }}// Where the Magic Happens!func makeCirlceInposition(location: CGPoint){ var Circle = SKShapeNode(circleOfRadius: 70 ) // Size of Circle = Radius setting. Circle.position = location //touch location passed from touchesBegan. Circle.name = "defaultCircle" Circle.strokecolor = SKcolor.blackcolor() Circle.glowWIDth = 1.0 Circle.fillcolor = SKcolor.clearcolor() self.addChild(Circle)} overrIDe func update(currentTime: CFTimeInterval) { /* Called before each frame is rendered */}}总结
以上是内存溢出为你收集整理的如何使用spriteKit在swift中绘制一个圆圈?全部内容,希望文章能够帮你解决如何使用spriteKit在swift中绘制一个圆圈?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)