Reputation: 6900
I'm doing some experimentation with SpriteKit and am roadblocked on a concept that to me seems very simple. I'm trying to draw simple shape (ie: square, circle) to the screen.
var testNode = SKSpriteNode()
testNode = SKSpriteNode(color: UIColor.orangeColor(), size: CGSizeMake(20, 20))
testNode.position = goalPoint
testNode.color = UIColor.orangeColor()
self.addChild(testNode)
According to the developer documentation for SKSpriteNode
An SKSpriteNode is a node that draws a textured image, a colored square, or a textured image blended with a color. You can also provide a custom shader to create your own rendering effects.
Apparently I'm missing how to do the colored square. I was able to create an SKTexture and get a sprite to appear, but without one I've been unable to get geometric shapes to appear.
I also attempted to use the SKShapeNode
class but was unable to get that to appear either. I assume I'm missing something simple. Any suggestions?
Upvotes: 0
Views: 238
Reputation: 113
The code in itself is correct, the only two things I can think of to be the problem is:
goalPoint - Is somewhere out of the screen bounds.
The location of the code. Where is your code located in your project?
In my didMoveToView I have the following :
var testNode = SKSpriteNode()
testNode = SKSpriteNode(color: UIColor.orangeColor(), size: CGSizeMake(20, 20))
testNode.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame));
testNode.color = UIColor.orangeColor()
self.addChild(testNode)
And it works like a charm.
So relocate your code to somewhere you are sure it's executed. And make sure goalPoint is within the screen.
Good luck :)
Upvotes: 2