터치했을 때 이미지를 변경해야합니다.터치했을 때 이미지 변경
현재 변경되는 이미지는 다음 이미지로, 자동으로 생성되지 않습니다.
@implementation MyScene2
{
Marsugo *marsugo;
SKAction *actionMoveDown;
SKAction *actionMoveEnded;
SKTexture *rescued;
}
-(id)initWithSize:(CGSize)size
{
if (self = [super initWithSize:size]) {
// Initializes Background
self.currentBackground = [Background generateNewBackground];
[self addChild:self.currentBackground];
}
return self;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *touch in touches) {
NSArray *nodes = [self nodesAtPoint:[touch locationInNode:self]];
for (SKNode *node in nodes) {
if ([node.name isEqualToString:playerObject]) {
rescued = [SKTexture textureWithImageNamed:@"rescued"];
marsugo.texture = rescued;
// this is changing the image of the next marsugo that spawns instead of self.
}
}
}
}
-(void)addMarsugos
{
// the marsugo is being initialized inside this method, that might be the issue i believe
// Create sprite
marsugo = [[Marsugo alloc]init];
marsugo.xScale = 0.3;
marsugo.yScale = 0.3;
marsugo.zPosition = 75;
// Bounds + Spawn Positions
int minX = marsugo.size.width;
int maxX = self.frame.size.width - marsugo.size.width;
int rangeX = maxX - minX;
int actualX = (arc4random() % rangeX) + minX;
marsugo.position = CGPointMake(actualX, self.frame.size.height + 50);
[self addChild:marsugo];
// Spawn Timer
int minDuration = 1;
int maxDuration = 10;
int rangeDuration = maxDuration - minDuration;
int actualDuration = (arc4random() % rangeDuration) + minDuration;
// Movement Actions
actionMoveDown = [SKAction moveTo:CGPointMake(actualX, CGRectGetMinY(self.frame)) duration:actualDuration];
actionMoveEnded = [SKAction removeFromParent];
[marsugo runAction:[SKAction sequence:@[actionMoveDown, actionMoveEnded]]];
NSLog(@"Marsugo X: %f - Speed: %i", marsugo.position.x, actualDuration);
}
@end
내가 이전에 말했듯이, 나는 "다음 스폰되는 스프라이트"가 아니라 텍스처를 바꾸기 위해 자기 스프라이트가 필요합니다.
이 문제를 해결하는 데 도움을 주시면 감사하겠습니다. 감사합니다.
을 내 SKScene에는보기가 없습니다. – user3504848
SKScene의 하위 클래스는 무엇입니까? – Mike
그러면 더 나은 옵션은 아래에 언급 된 것처럼'- (void) touchesBegan : (NSSet *) toEvents : (UIEvent *) event'를 오버라이드하는 것입니다. – nikhil84