sprite-kit

Scrollview stopping at a certain point

若如初见. 提交于 2019-12-25 08:54:04
问题 Hi I currently have a horizontal UIScrollView that allows me to pick a character in my game and then select it but the problem that I have now is I am trying to get the scrollview to stop at the point where the sprite/character is in the middle of the screen and instead of having it stop anywhere. My UIScrollView has a “moveable node” that contains multiple pages that hold all the sprites as seen below: scrollViewHorizontal = CustomScrollView(frame: CGRect(x: 0, y: 0, width: self.frame.size

How to make camera follow the player?

浪子不回头ぞ 提交于 2019-12-25 08:47:37
问题 Anybody have a code in swift to make camera follow the player? Whether to create camera node, like: var camera = SKSpriteNode() ? 回答1: The above answer is actually wrong, Apple docs provides you with a whole implementation for a camera node (although I've always read it through Objective-C). I'll link you, and others, to the doc in this answer so you can learn it instead of just copy and pasting some code. Hope this helps! https://developer.apple.com/library/prerelease/ios/documentation

SceneKit with SpriteKit intersection of nodes

自作多情 提交于 2019-12-25 08:18:30
问题 Hi I want to have a selection box on my game. I assume that making with 'SpriteKit' overlay is the easiest way to do But is there any API to detect intersection of 'SKShapeNode' and 'SCNNode' (Ignoring the Z axis ofcourse) ? What have I tried to do: _unitsArray is an array of SCNNodes that I wish to have they're bounding boxes in a SKScene for (SCNNode * node in _unitsArray) { SCNVector3 min = SCNVector3Zero; SCNVector3 max = SCNVector3Zero; [node getBoundingBoxMin:&min max:&max]; NSLog(@"Min

How to draw 720 data points using Swift

心已入冬 提交于 2019-12-25 08:03:12
问题 I am currently writing a joystick app and I want to display the contours of my lidar sensor; I am using sprite kit but it's lagging; I am assuming that it is taking up too much memory My lidar sensor returns to me 360 data points where each degree represents the distances of where it hit an object (wall) I am initializing all of my sprite kit nodes in didMoveToView, is there a better way to achieve this? perhaps in init? I am creating 720 sprite kit nodes because 360 are for the lines and 360

Sprite position not working in Objective-C, Xcode

≡放荡痞女 提交于 2019-12-25 07:54:23
问题 It has been a year or so since I've used Objective-C and I must have forgot something because this is stumping me. I didn't use a for loop because I wanted a delay, but I logged all these variables, r is a float, j is an integer. r and j were initialized to 0. -(void)fire{ r = j; if (j < 80) { j = j + 1; bullet.position = CGPointMake(2*r, 15); NSLog(@"r is %f", r); NSLog(@"j is %i", j); NSLog(@"position is %f, %f",bullet.position.x, bullet.position.y); NSLog(@"x is, %f", r/8); [self

Updating texture not working

时光毁灭记忆、已成空白 提交于 2019-12-25 07:28:09
问题 Not working update on this texture. The code is an abbreviated version and I need it so. I need to update the texture. How would I be able to do this in Swift in SpriteKit? func didBeginContact(contact: SKPhysicsContact) { if firstBody.categoryBitMask == PhysicsCatagory.ball && secondBody.categoryBitMask == PhysicsCatagory.coin { vyhodnoceni() screen(2) }} override func update(currentTime: NSTimeInterval) { vysledekHvezdyTexture = SKTexture(imageNamed: starString1!)} func vyhodnoceni(){

Duplicate Sprite in Random Positions with SpriteKit

北战南征 提交于 2019-12-25 07:16:37
问题 I'm trying to create a game with Swift and SpriteKit and I'd like to create multiple instances of the same sprite in random positions, but I can't figure out how to do it. I considered just doing adding this code: addChild(object) multiple times, but this causes the app to crash. How can I solve my problem? EDIT: I've fixed this part of the problem, but now I want to add my random sprites in random X locations. I've tried to generate random positions by executing this code: var randomNumber =

Collision checking issues

你说的曾经没有我的故事 提交于 2019-12-25 06:05:31
问题 The code checks if the user taps a ball with the same texture as a ball that randomly changes textures. But in my console "Point" is only printed occasionally although I tap on the ball with the same texture as the ball that randomly changes texture. How can this be fixed. Has this something to do with adding a physicsBody to the other balls? override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { var array = [blueTexture, redTexture, greenTexture, yellowTexture]// var

Collision checking issues

旧巷老猫 提交于 2019-12-25 06:05:25
问题 The code checks if the user taps a ball with the same texture as a ball that randomly changes textures. But in my console "Point" is only printed occasionally although I tap on the ball with the same texture as the ball that randomly changes texture. How can this be fixed. Has this something to do with adding a physicsBody to the other balls? override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { var array = [blueTexture, redTexture, greenTexture, yellowTexture]// var

SpriteNode/Shapes change size and disappear after returning to GameScene (Swift SpriteKit)

…衆ロ難τιáo~ 提交于 2019-12-25 04:50:16
问题 GIF of the issue in action: http://i.imgur.com/hiF5lyw.gifv As you can see, the main Player is a SKSpriteNode, and when you hit a falling block which is a SKShapeNode, the game switches to the GameOver scene. When you click restart in the GameOver scene and move back to the GameScene the falling blocks disappear and the dimensions of the Player sprite is changed along with its y position. All the code contains pretty detailed comments but if you have any questions about it feel free to ask.