#import "GameScene.h"
@implementation GameScene
-(void)didMoveToView:(SKView *)view {
/* Setup your scene here */
SKLabelNode *myLabel = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
myLabel.text = @"Hello, World!";
myLabel.fontSize = 65;
myLabel.position = CGPointMake(CGRectGetMidX(self.frame),
CGRectGetMidY(self.frame));
NSString *myParticlePath = [[NSBundle mainBundle] pathForResource:@"fireflies" ofType:@"sks"];
SKEmitterNode *myParticle = [NSKeyedUnarchiver unarchiveObjectWithFile:myParticlePath];
[self addChild:myParticle];
self.physicsWorld.gravity=CGVectorMake(0.0, -9);
self.physicsBody=[SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame];
self.physicsBody.linearDamping=0.0;
SKSpriteNode *rectNode=[SKSpriteNode spriteNodeWithColor:[SKColor greenColor] size:CGSizeMake(50, 50)];
[email protected]"rect";
rectNode.position=CGPointMake(300, 300);
[self addChild:rectNode];
[self moveAction];
}
-(SKAction*)groupAction:(CGPoint)points
{
SKAction *A=[SKAction moveTo:CGPointMake(points.x+100, points.y+100) duration:1];
SKAction *B=[SKAction moveTo:CGPointMake(500, 100) duration:1];
SKAction *C=[SKAction moveTo:CGPointMake(100, 100) duration:1];
SKAction *s=[SKAction sequence:@[A,B,C]];
return s;
}
-(void)moveRect:(SKNode*)node
{
[node runAction:[SKAction repeatActionForever:[self groupAction:node.position]] withKey:@"moveAction"];
}
-(void)moveAction
{
[self enumerateChildNodesWithName:@"rect" usingBlock:^(SKNode *node, BOOL *stop) {
[self moveRect:node];
}];
}
-(void)clearAction
{
[self enumerateChildNodesWithName:@"rect" usingBlock:^(SKNode *node, BOOL *stop) {
[node removeActionForKey:@"moveAction"];
}];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */
for (UITouch *touch in touches) {
CGPoint location = [touch locationInNode:self];
if(!_stop)
{
[self clearAction];
_stop=TRUE;
}
else
{
[self moveAction];
_stop=FALSE;
}
/*
SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"Spaceship"];
sprite.physicsBody.allowsRotation=FALSE;
sprite.physicsBody=[SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(sprite.size.width, sprite.size.height)];
sprite.physicsBody.friction=0.0;
sprite.physicsBody.linearDamping=0.0;
sprite.physicsBody.restitution=1.0;
sprite.xScale = 0.5;
sprite.yScale = 0.5;
sprite.position = location;
[self addChild:sprite];
*/
}
}
-(void)update:(CFTimeInterval)currentTime {
/* Called before each frame is rendered */
}
@end
체크 아웃 난 그냥 하나의 사각형을 사용하여이 예를 완료하지만 당신은 당신이 다른 행동 있는지 확인하려면 많은 개체를 사용할 수 있습니다 이온 그룹은 다른 이름을 포함하므로 사용자가 터치 스크린을 적용 할 때 작업을 삭제하고 일시 중지하기가 쉽고 작업이 삭제되거나 일시 중지되었을 때 다른 개체에 새 작업 그룹이 적용됩니다.
[sprite runAction : A 완료 :^{ [스프라이트 setPaused : True] ]]; – dragoneye
답해 주셔서 감사합니다;) – isicom
죄송합니다 ...하지만 이건 나를 구할 수 없습니다. 다시 설명해 드리겠습니다 ... 스프라이트가 있습니다. FollowPath/RepeatForever/RunAction을 통해 이동합니다. B 코너에서 B 코너로, B에서 C, C-D 그리고 다시 A-B ... 이제 터치가 감지되면 스프라이트가 현재 위치에서 멈춰야하고 새 운동을 시작해야합니다. 0에서 Pi * 2까지의 아크를 실행하고 완료 한 후, 첫 번째 움직임을 놓고 마지막 현재 위치에서 시작합니다. 만지면 멈추었습니다 ... 희망, 이것은 충분히 명확합니다 .../길을 찾아주세요! 고맙습니다. 그리고 축하합니다. – isicom