如何使用spriteKit在swift中绘制一个圆圈?

如何使用spriteKit在swift中绘制一个圆圈?,第1张

概述我刚刚开始使用ios开发,我无法弄清楚如何画一个圆.我只是想画一个圆圈,将其设置为一个变量并显示在屏幕上,以便稍后将其用作主播放器.有人可以告诉我如何做到这一点,或者为我提供代码? 我在网上找到了这个代码: var Circle = SKShapeNode(circleOfRadius: 40)Circle.position = CGPointMake(500, 500)Circle.name 我刚刚开始使用ios开发,我无法弄清楚如何画一个圆.我只是想画一个圆圈,将其设置为一个变量并显示在屏幕上,以便稍后将其用作主播放器.有人可以告诉我如何做到这一点,或者为我提供代码?

我在网上找到了这个代码:

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中绘制一个圆圈?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1038242.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存