Objective C Sprite Kit Multiple Collisions - objective-c

I am currently working on a sprite kit game, with Objective-C. So far, I have everything working in order, however I am trying to accomplish multiple collisions and can't seem to accomplish this.
This is my code:
- (void)didBeginContact:(SKPhysicsContact *)contact
{
NSLog(#"contact!");
SKNode * nodeA = contact.bodyA.node;
SKNode *nodeB =contact.bodyB.node;
NSLog(#"%#", nodeA.name);
if ([contact.bodyA.node.name isEqualToString:#"david"] == YES ||
[contact.bodyB.node.name isEqualToString:#"david"] == NO) {
[self runAction:self.soundAction];
SKNode * nodeB = contact.bodyB.node;
SKAction * remove = [SKAction removeFromParent];
[nodeB runAction:remove];
counter++;
updateLabel = true;
}
else if([contact.bodyA.node.name isEqualToString:#"rock"] == YES ||
[contact.bodyB.node.name isEqualToString:#"rock"] == YES) {
SKAction * remove = [SKAction removeFromParent];
[nodeB runAction:remove];
for (int i = 0; i < 100; i++) {
SKSpriteNode * rock = [[SKSpriteNode alloc] initWithColor:[SKColor orangeColor] size:CGSizeMake(10, 10)];
rock.position = CGPointMake(CGRectGetMidX(self.frame) + skRand(-40, 40), CGRectGetMidY(self.frame) + 100 + skRand(-40, 40));
rock.name = #"rock";
rock.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:rock.size];
rock.physicsBody.usesPreciseCollisionDetection = YES;
rock.physicsBody.contactTestBitMask = 0x1;
[self addChild:rock];
CGVector dir = CGVectorMake(skRand(-5, 5), skRand(1, 4));
[rock.physicsBody applyImpulse:dir];
}
}
}

Related

Gravity not affecting a node when endless background is enabled in sprite kit

When I implement the following code, my main character is not affected by gravity.
SKSpriteNode *ball = [SKSpriteNode spriteNodeWithImageNamed:#"ball.png"];
ball.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:ball.size.height/2];
ball.physicsBody.dynamic = YES;
ball.physicsBody.linearDamping = NO;
ball.physicsBody.angularDamping = NO;
ball.physicsBody.friction = 0;
ball.physicsBody.usesPreciseCollisionDetection = YES;
ball.position = CGPointZero;
ball.zPosition = 1;
[myWorld addChild:ball];
Here's the background
for (int i = 0; i < 2; i++) {
SKSpriteNode * bg = [SKSpriteNode spriteNodeWithImageNamed:#"background"];
//bg.anchorPoint = CGPointZero;
bg.position = CGPointMake(i * bg.size.width, 0);
bg.name = #"background.png";
//bg.physicsBody = [SKPhysicsBody bodyWithEdgeFromPoint:CGPointMake(-bg.frame.size.width/2, -bg.frame.size.height/2 +20) toPoint:CGPointMake(bg.frame.size.width/2, -bg.frame.size.height/2 + 20)];
bg.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:bg.frame];
[self addChild:bg];
}
I tried the code here Stack discussion here and everything works as expected, except the gravity on the y axis.
Gravity in the scene:
if (self = [super initWithSize:size]) {
self.anchorPoint = CGPointMake(0.5, 0.5);
self.physicsWorld.gravity = CGVectorMake(0, -2);
[self startGravityIncrease];
........
- (void)startGravityIncrease {
SKAction *blockAction = [SKAction runBlock:^{
CGVector gravity = self.physicsWorld.gravity;
gravity.dx += 0.6;
gravity.dy -= 0.3;
self.physicsWorld.gravity = gravity;
}];
SKAction *waitAction = [SKAction waitForDuration:5];
SKAction *sequenceAction = [SKAction sequence:#[waitAction, blockAction]];
SKAction *repeatAction = [SKAction repeatActionForever:sequenceAction];
[self runAction:repeatAction];
}
What am I doing wrong here?

SpriteKit Add node in empty location with duration

I need some help.
I am developing a game and I have two questions.
Quick explanation of game :
There are three different nodes (shark (player), water ball and brick )
When the game starts there are one shark, four water balls and eight bricks.
when shark contacts with water ball, player earns point, water ball disappears and game adds another water ball in random location,
When shark contacts with brick shark dies and disappear from the screen.
My questions are;
First : When we hit the water ball how do we add the water ball in empty location. How do I make sure new water ball will be in different location then bricks and other water balls?
Second:
I want to wait a few seconds before I add the new water ball. How do I do that?
Here is some part of my code.
Thank you,
-(void) addWaterBallTopLeft {
WaterBall *waterBall = [WaterBall waterBallAtPosition:CGPointMake
([Util randomWithMin:(self.frame.size.width/10) + self.waterBall.size.width max:self.frame.size.width/2-self.brickT.size.width],
[Util randomWithMin:(self.frame.size.height- (self.frame.size.height/4)) + self.brickW.size.height max:self.frame.size.height-20])];
waterBall.name = #"WATERBALLTL";
[self addChild:waterBall ];
}
-(void) addWaterBallTopRight {
WaterBall *waterBall = [WaterBall waterBallAtPosition:CGPointMake([Util randomWithMin:self.frame.size.width/2+20 max:self.frame.size.width-20], [Util randomWithMin:(self.frame.size.height- (self.frame.size.height/4)-20) max:self.frame.size.height-20])];
waterBall.name = #"WATERBALLTR";
[self addChild:waterBall ];
}
-(void) addWaterBallBottomLeft {
WaterBall *waterBall = [WaterBall waterBallAtPosition:CGPointMake([Util randomWithMin:20 max:self.frame.size.width/2-20], [Util randomWithMin:(self.frame.size.height/2)+20 max:(self.frame.size.height- (self.frame.size.height/4)-20)])];
waterBall.name = #"WATERBALLBL";
[self addChild:waterBall];
}
-(void) addWaterBallBottomRight {
WaterBall *waterBall = [WaterBall waterBallAtPosition:CGPointMake([Util randomWithMin:self.frame.size.width/2+20 max:self.frame.size.width-20], [Util randomWithMin:(self.frame.size.height/2)+20 max:(self.frame.size.height- (self.frame.size.height/4)-20)])];
waterBall.name = #"WATERBALLBR";
[self addChild:waterBall];
}
-(void) addBrick {
BrickW *brickW1 = [BrickW BrickWAtPosition:CGPointMake( (self.frame.size.width/12)* 1 , self.frame.size.height - self.frame.size.height * 0.25) ];
[self addChild:brickW1];
BrickW *brickW2 = [BrickW BrickWAtPosition:CGPointMake( (self.frame.size.width/12)* 3 , self.frame.size.height - self.frame.size.height * 0.25) ];
[self addChild:brickW2];
BrickW *brickW3 = [BrickW BrickWAtPosition:CGPointMake( (self.frame.size.width/12)* 9, self.frame.size.height - self.frame.size.height * 0.25)];
[self addChild:brickW3];
BrickW *brickW4 = [BrickW BrickWAtPosition:CGPointMake( (self.frame.size.width/12)* 11, self.frame.size.height - self.frame.size.height * 0.25)];
[self addChild:brickW4];
BrickT *brickT1 = [BrickT BrickTAtPosition:CGPointMake( self.frame.size.width/2 , (self.frame.size.height / 24)*23 )];
[self addChild:brickT1];
BrickT *brickT2 = [BrickT BrickTAtPosition:CGPointMake( self.frame.size.width/2 , (self.frame.size.height / 24)*21 ) ];
[self addChild:brickT2];
BrickT *brickT3 = [BrickT BrickTAtPosition:CGPointMake( self.frame.size.width/2 , (self.frame.size.height / 24)*13 )];
[self addChild:brickT3];
BrickT *brickT4 = [BrickT BrickTAtPosition:CGPointMake( self.frame.size.width/2 , (self.frame.size.height / 24)*15)];
[self addChild:brickT4];
}
- (void) didBeginContact:(SKPhysicsContact *)contact {
SKPhysicsBody *firstBody, *secondBody;
if (contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask) {
firstBody = contact.bodyA;
secondBody = contact.bodyB;
} else {
firstBody = contact.bodyB;
secondBody = contact.bodyA;
}
if ( firstBody.categoryBitMask == CollisionCategoryBrick && secondBody.categoryBitMask == CollisionCategoryShark ) {
NSLog(#"BRICK");
[contact.bodyB.node removeFromParent];
} else if ( firstBody.categoryBitMask == CollisionCategoryWaterBall && secondBody.categoryBitMask == CollisionCategoryShark ) {
NSLog(#"BALL");
self.addSeconds =YES;
[contact.bodyA.node removeFromParent];
[self addPoints:PointsPerHit];
if (![ self childNodeWithName:#"WATERBALLTL"]) {
[self addWaterBallTopLeft];
}
if (![ self childNodeWithName:#"WATERBALLTR"]) {
[self addWaterBallTopRight];
}
if (![ self childNodeWithName:#"WATERBALLBL"]) {
[self addWaterBallBottomLeft];
}
if (![ self childNodeWithName:#"WATERBALLBR"]) {
[self addWaterBallBottomRight];
} }
NSLog(#"%lu", (unsigned long)[self.children count]);
}
-(void)update:(CFTimeInterval)currentTime {
if (startGamePlay){
startTime = currentTime;
startGamePlay = NO;
}
timeSinceStart = (currentTime -startTime);
countDownInt = 1000 - (int)(currentTime-startTime);
if (countDownInt > 0 && self.addSeconds == NO) {
countDown.text = [NSString stringWithFormat:#"%i", countDownInt];
} else if(countDownInt > 0 && self.addSeconds == YES){
startTime +=2;
countDown.text = [NSString stringWithFormat:#"%i", countDownInt];
self.addSeconds = NO;
}
if (countDownInt == 0 ){
countDown.text =#"0";
Level2 *level2 = [Level2 sceneWithSize:self.frame.size];
SKTransition *transition = [SKTransition fadeWithDuration:0.5];
[self.view presentScene:level2 transition:transition];
}
}
//answer of your second question use a skaction sequence which would fire a function after 1 second
SKAction *Timetofire= [SKAction sequence:#[
//time after you want to fire a function
[SKAction waitForDuration:1],
[SKAction performSelector:#selector(urFunction)
onTarget:self]
]];
[self runAction:Timetofire withKey:#"key"];
//if you want your function eld fire x number of time
[self runAction:[SKAction repeatAction:Timetofire count:10]];
where x in number of times you wan't your function to fire
//if you want your function fire forever
[self runAction:[SKAction repeatActionForever:Timetofire ]];
1)now the answer of your first question used predefined NSMutableArray to store multiple CGPoint. where each CGPoint define the position of your shark,ball and other item be sure that the value of each CGPoint is different from each other which would give your item a random occurrence.

Accessing an object's local variable from a method Objective-c

I'm trying to access an object's local variable from didBeginContact method. How's it possible ?
Let's say I've got a ball object and whenever it bounces from the player, that ball's bouncedFrom variable get's an identifier from the player.
This is my initBall method, which initialises a ball. It is called every 3-5(random) seconds.
-(void)initBall {
NSString *bouncedFrom;
bouncedFrom = #"";
ball = [SKSpriteNode spriteNodeWithImageNamed:#"ball"];
ball.name = ballCategoryName;
ball.zPosition = 0;
int cannonPos = (arc4random() % 3 ) + 1;
SKSpriteNode *cannon = (SKSpriteNode *)[self childNodeWithName:[NSString stringWithFormat:#"%i",cannonPos]];
ball.zPosition = 3;
ball.position = cannon.position;
ball.physicsBody.categoryBitMask = ballCategory;
ball.physicsBody.contactTestBitMask = wallCategory;
ball.physicsBody.collisionBitMask = wallCategory;
ball.physicsBody.usesPreciseCollisionDetection = YES;
[self addChild:ball];
ball.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:ball.frame.size.width/2];
ball.physicsBody.friction = 0.0f;
//Bounce back
ball.physicsBody.restitution = 1.0f;
//
ball.physicsBody.linearDamping = 0.0f;
ball.physicsBody.allowsRotation = NO;
switch (cannonPos) {
case 1:
ball.position = CGPointMake(ball.position.x+20, ball.position.y+20);
[ball.physicsBody applyImpulse:CGVectorMake(-1.0,1.0)];
break;
case 2:
ball.position = CGPointMake(ball.position.x-20, ball.position.y+15);
[ball.physicsBody applyImpulse:CGVectorMake(-1.0,1.0)];
break;
case 3:
ball.position = CGPointMake(ball.position.x-20, ball.position.y-15);
[ball.physicsBody applyImpulse:CGVectorMake(-1.0,-1.0)];
break;
case 4:
ball.position = CGPointMake(ball.position.x+20, ball.position.y-20);
[ball.physicsBody applyImpulse:CGVectorMake(-1.0,-1.0)];
default:
break;
}
What I want is something like this in the didBeginContact:
-(void)didBeginContact:(SKPhysicsContact *)contact {
SKPhysicsBody *firstBody;
SKPhysicsBody *secondBody;
if (contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask) {
firstBody = contact.bodyA;
secondBody = contact.bodyB;
} else {
firstBody = contact.bodyB;
secondBody = contact.bodyA;
}
if ((firstBody.categoryBitMask & ballCategory) !=0) {
SKNode *ball = contact.bodyB.node;
SKNode *player = contact.bodyA.node;
ball.bouncedFrom = PlayerCategory;
}
if ((firstBody.categoryBitMask & wallCategory) !=0) {
SKNode *ball = contact.bodyB.node;
SKAction *addScore = [SKAction runBlock:^{
if (ball.position.y < 0) playerScore--;
if (ball.position.x < 0) cpu2Score--;
if (ball.position.y > self.frame.size.height) cpu1Score--;
if (ball.position.x > self.frame.size.width) cpu3Score--;
}];
SKAction *removeNode = [SKAction removeFromParent];
SKAction *sequence = [SKAction sequence:#[addScore, removeNode]];
[ball runAction:sequence];
}
}
Both ball and xCategories are declared as static variables at the top of my code.
Is something like this possible ?
My first thought is that you should declare bouncedFrom as a class variable in the .h rather than declaring it in your init: method.
so in the .h should look like
#interface Ball: NSObject{<br>
NSString *bouncedFrom;<br>
}
#end

SKSpriteNode collision detection error

I am creating a game where a ball is suppose to bounce off from platforms. I have set up physics properties for the ball and the platform(platform only attains physics property when it's below the ball). My problem is: the ball is not bouncing (I have applied impulse in didbegincontact method) when the ball makes contact with the platform, it however detects contact.
Here is my didBeginContact Code:
- (void) didBeginContact:(SKPhysicsContact *)contact {
SKSpriteNode *firstNode, *secondNode;
firstNode = (SKSpriteNode*) contact.bodyA.node;
secondNode = (SKSpriteNode*) contact.bodyB.node;
if ((contact.bodyA.categoryBitMask == ballCategory) && (contact.bodyB.categoryBitMask == solidPlatformCategory)) {
NSLog(#"Platform Hit");
CGPoint contactPoint = contact.contactPoint;
[_ball.physicsBody applyImpulse:CGVectorMake(0, 4) atPoint:contactPoint];
}
}
///// Here is the code for SKSpriteNode Ball
- (void) addBall {
_myBall = [SKSpriteNode spriteNodeWithImageNamed:#"ball.png"];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
_myBall.scale = 0.4;
} else {
_myBall.scale = 0.3;
}
_ball.position = CGPointMake(self.frame.size.width/2, _solidPlatform.position.y + 2.5*_ball.size.height);
_ball.zPosition = 2;
_ball.name = #"doodle";
_ball.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:_myDoodle.frame.size];
_ball.physicsBody.mass = 1.0;
_ball.physicsBody.restitution = 0.8;
_ball.physicsBody.dynamic = YES;
_ball.physicsBody.allowsRotation = NO;
_ball.physicsBody.usesPreciseCollisionDetection = YES;
_ball.physicsBody.categoryBitMask = ballCategory;
_ball.physicsBody.collisionBitMask = solidPlatformCategory;
_ball.physicsBody.contactTestBitMask = solidPlatformCategory;
//SKAction *moveUpAction = [SKAction moveByX:0.0 y:8*numberOfPlatforms duration:0.5];
[self addChild:_ball];
}
////Platform has been defined as (not a complete code):
_solidPlatform7.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:_solidPlatform7.frame.size];
_solidPlatform7.physicsBody.dynamic = NO;
_solidPlatform7.physicsBody.affectedByGravity = NO;
_solidPlatform7.physicsBody.usesPreciseCollisionDetection = YES;
_solidPlatform7.physicsBody.categoryBitMask = solidPlatformCategory;
PS: I am not getting any collusion detection if I define platform as bodyWithEdgeFromRect
difficult to answer without seeing some code, but I'll try:
If the ball does not bounce at all, check the restitution property. Higher values provide a higher "bounciness":
ball.physicsBody.restitution=0.8;
If you want the ball to bounce endless between bottom and ceiling you can invert the gravity after each collision:
self.physicsWorld.gravity = CGVectorMake(0, self.physicsWorld.gravity.dy * (-1));
Hope that helps. If not, please share some code.
I've tried your code. With some smaller changes it works:
- (void) addBall {
// Bottom platforms
for (int i=0; i<10; i++) {
SKSpriteNode *mySprite = [SKSpriteNode spriteNodeWithColor:[UIColor redColor] size:CGSizeMake(40, 20)];
CGPoint location = CGPointMake(i*40+60, 10);
//mySprite.size =CGSizeMake(20, 40);
mySprite.position=location;
mySprite.physicsBody=[SKPhysicsBody bodyWithRectangleOfSize:mySprite.size];
mySprite.physicsBody.dynamic=false;
mySprite.physicsBody.categoryBitMask=solidPlatformCategory;
[self addChild:mySprite];
}
_ball = [SKSpriteNode spriteNodeWithImageNamed:#"ball.png"];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
_ball.scale = 0.4;
} else {
_ball.scale = 0.3;
}
_ball.position = CGPointMake(self.frame.size.width/2, self.frame.size.width/2);
_ball.zPosition = 2;
_ball.name = #"doodle";
//_ball.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:_myDoodle.frame.size];
_ball.physicsBody=[SKPhysicsBody bodyWithCircleOfRadius:_ball.size.width/2];
_ball.physicsBody.mass = 1.0;
_ball.physicsBody.restitution = 1;
_ball.physicsBody.dynamic = YES;
_ball.physicsBody.allowsRotation = NO;
_ball.physicsBody.usesPreciseCollisionDetection = YES;
_ball.physicsBody.categoryBitMask = ballCategory;
_ball.physicsBody.collisionBitMask = solidPlatformCategory;
_ball.physicsBody.contactTestBitMask = solidPlatformCategory;
//SKAction *moveUpAction = [SKAction moveByX:0.0 y:8*numberOfPlatforms duration:0.5];
[self addChild:_ball];
}

UIPinchGestureRecognizer trouble

Ok, i've read a few posts on this one (ex. UIImageView Gestures (Zoom, Rotate) Question) but I can't seem to fix my problem.
I have the following setup: an SKScene, an SKNode _backgroundLayer and 9 SKSpriteNodes that are tiles that make up the background and are attached to the _backgroundLayer.
Since these 9 tiles make a 3x3 square and they are quite large, I need to be able to zoom in and look at other SKSpriteNodes that will be on top of these 9 background images.
There are two problems:
1) When I pinch to zoom in or zoom out it seems like it is zooming in/out from location (0,0) of the _backgroundLayer and not from the touch location.
2) I have added some bounds so that the user can not scroll out of the 9 background images. In general it works. However, if I zoom in then move towards the top of the 9 background images and then zoom out the bounding conditions go berserk and the user can see the black space outside the background images. I need a way to limit the amount of zooming out that the user can do depending on where he's at.
Any ideas? Thanks!
I include my code below:
#import "LevelSelectScene.h"
#import "TurtleWorldSubScene.h"
#interface LevelSelectScene ()
#property (nonatomic, strong) SKNode *selectedNode;
#end
#implementation LevelSelectScene
{
SKNode *_backgroundLayer;
}
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
/* Setup your scene here */
_backgroundLayer = [SKNode node];
_backgroundLayer.name = #"backgroundLayer";
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[_backgroundLayer setScale:0.76];
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && IS_WIDESCREEN) {
} else {
[_backgroundLayer setScale:0.36];
}
[self addChild:_backgroundLayer];
SKTexture *backgroundTexture = [SKTexture textureWithImageNamed:#"levelSelect"];
int textureID = 0;
for (int i = 0; i<3; i++) {
for (int j = 0; j<3; j++) {
SKSpriteNode *background = [SKSpriteNode spriteNodeWithTexture:backgroundTexture];
background.anchorPoint = CGPointZero;
background.position = CGPointMake((background.size.width)*i, (background.size.height)*j);
background.zPosition = 0;
background.name = [NSString stringWithFormat:#"background%d", textureID];
textureID++;
[_backgroundLayer addChild:background];
}
}
[TurtleWorldSubScene displayTurtleWorld:self];
}
return self;
}
- (void)didMoveToView:(SKView *)view {
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(handlePanFrom:)];
[[self view] addGestureRecognizer:panGestureRecognizer];
//UITapGestureRecognizer * tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTap:)];
// [self.view addGestureRecognizer:tapRecognizer];
UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:#selector(handlePinch:)];
[[self view] addGestureRecognizer:pinchGestureRecognizer];
}
- (void)handlePanFrom:(UIPanGestureRecognizer *)recognizer {
if (recognizer.state == UIGestureRecognizerStateBegan) {
CGPoint touchLocation = [recognizer locationInView:recognizer.view];
touchLocation = [self convertPointFromView:touchLocation];
SKNode *node = [self nodeAtPoint:touchLocation];
_selectedNode = node;
} else if (recognizer.state == UIGestureRecognizerStateChanged) {
CGPoint translation = [recognizer translationInView:recognizer.view];
translation = CGPointMake(translation.x, -translation.y);
CGPoint initialPosition = CGPointAdd(_backgroundLayer.position, translation);
_backgroundLayer.position = [self boundLayerPos:initialPosition];
[recognizer setTranslation:CGPointZero inView:recognizer.view];
} else if (recognizer.state == UIGestureRecognizerStateEnded) {
float scrollDuration = 0.2;
CGPoint velocity = [recognizer velocityInView:recognizer.view];
CGPoint pos = [_backgroundLayer position];
CGPoint p = CGPointMultiplyScalar(velocity, scrollDuration);
CGPoint newPos = CGPointMake(pos.x + p.x, pos.y - p.y);
newPos = [self boundLayerPos:newPos];
[_backgroundLayer removeAllActions];
SKAction *moveTo = [SKAction moveTo:newPos duration:scrollDuration];
[moveTo setTimingMode:SKActionTimingEaseOut];
[_backgroundLayer runAction:moveTo];
}
}
- (void)handlePinch:(UIPinchGestureRecognizer *) recognizer
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
if(_backgroundLayer.xScale*recognizer.scale < 0.76) {
//SKSpriteNode *backgroundTile = (SKSpriteNode *)[_backgroundLayer childNodeWithName:#"background0"];
[_backgroundLayer setScale:0.76];
} else if(_backgroundLayer.xScale*recognizer.scale > 2) {
[_backgroundLayer setScale:2.0];
} else {
[_backgroundLayer runAction:[SKAction scaleBy:recognizer.scale duration:0]];
}
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && IS_WIDESCREEN) {
} else {
if(_backgroundLayer.xScale*recognizer.scale < 0.36) {
[_backgroundLayer setScale:0.36];
} else if(_backgroundLayer.xScale*recognizer.scale > 2) {
[_backgroundLayer setScale:2.0];
} else {
[_backgroundLayer runAction:[SKAction scaleBy:recognizer.scale duration:0]];
}
}
recognizer.scale = 1;
}
- (CGPoint)boundLayerPos:(CGPoint)newPos {
SKSpriteNode *backgroundTile = (SKSpriteNode *)[_backgroundLayer childNodeWithName:#"background0"];
CGPoint retval = newPos;
retval.x = MIN(retval.x, 0);
retval.x = MAX(retval.x, -(backgroundTile.size.width*_backgroundLayer.xScale*3)+self.size.width);
retval.y = MIN(retval.y, 0);
retval.y = MAX(retval.y, -(backgroundTile.size.height*_backgroundLayer.xScale*3)+self.size.height);
return retval;
}