충돌 감지 후 내 앱의 종료 화면을 만들어야합니다. 주 메뉴/게임으로 돌아 가기 버튼이있는 종료 화면을 만드는 가장 쉬운 방법은 무엇입니까? ViewController
을 사용할 수 있습니까? 여기에 또한 모든 게시물을 자습서, 비디오를 많이 읽고, 한 : 이것은 내 현재 코드 (안 그것은 모든 단지 몇 가지 중요한 것들) 장면 위로 게임을보기위한 컨트롤러 사용
입니다
: 내가 원하는@implementation MyScene
static const int squirrelHitCategory = 1;
static const int nutHitCategory = 2;
- (instancetype)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
self.physicsWorld.contactDelegate = self;
_squirrelSprite = [SKSpriteNode spriteNodeWithImageNamed:@"squirrel"];
_squirrelSprite.position = _firstPosition;
_atFirstPosition = YES;
_squirrelSprite.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:10];
_squirrelSprite.physicsBody.categoryBitMask = squirrelHitCategory;
_squirrelSprite.physicsBody.contactTestBitMask = nutHitCategory;
_squirrelSprite.physicsBody.collisionBitMask = nutHitCategory;
_squirrelSprite.physicsBody.affectedByGravity = NO;
self.physicsWorld.contactDelegate = self;
[self addChild:_squirrelSprite];
SKAction *wait = [SKAction waitForDuration:3.0];
SKSpriteNode *lightnut = [SKSpriteNode spriteNodeWithImageNamed:@"lightnut.png"];
lightnut.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(200,160)];
lightnut.physicsBody.categoryBitMask = nutHitCategory;
lightnut.physicsBody.contactTestBitMask = squirrelHitCategory;
lightnut.physicsBody.collisionBitMask = squirrelHitCategory;
lightnut.physicsBody.affectedByGravity = NO;
self.physicsWorld.contactDelegate = self;
[self addChild: lightnut];
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
// Check time since the last touch event
if (touch.timestamp-_lastTouch >= .9) {
// Allow touch
NSLog(@"greater than or equal to 3 seconds");
if (_atFirstPosition)
{
SKAction *moveNodeLeft = [SKAction moveByX:-207.8 y:0.0 duration:0.85];
[_squirrelSprite runAction: moveNodeLeft withKey:@"moveleft"];
} else {
SKAction *moveNodeRight = [SKAction moveByX:207.8 y:0.0 duration:0.85];
[_squirrelSprite runAction: moveNodeRight withKey:@"moveright"];
}
_atFirstPosition = !_atFirstPosition;
_squirrelSprite.xScale *= -1.0;
}
else {
// Ignore touch
NSLog(@"Seconds since last touch %g",touch.timestamp-_lastTouch);
}
// Store timestamp
_lastTouch = touch.timestamp;
}
-(void)didBeginContact:(SKPhysicsContact *)contact
{
NSLog(@"contact detected");
SKPhysicsBody *firstBody, *secondBody;
firstBody = contact.bodyA;
secondBody = contact.bodyB;
if(firstBody.categoryBitMask == squirrelHitCategory || secondBody.categoryBitMask == nutHitCategory)
{
}
}
내 끝 화면은 간단하므로 가장 쉽게 만들 수 있습니다. 고맙습니다!
방법에 대한 유용한 자습서가 있습니까? 나는 아직도 프로그래밍에 익숙하지 않다. 고맙습니다! – Ryanc
@Ryanc 시작하기에 도움이 될만한 코드를 사용하여 답변을 업데이트했습니다. 나는 내 스토리 보드 사진을 게시하지 않았지만 더 많은 도움이 필요하면 알려 주시기 바랍니다. – Scott