Skift billede i "ccTouchesMoved"?
Jeg er ved at udvikle et spil i Xcode med Cocos2D. Jeg synes dog ikke jeg kan få ændret "frogCharacter"'s billede når "ccTouchesEnded" går i gang. Jeg har prøvet at ændre billedet i min "CCSequence" hvilket bare giver en fejl. Hvordan skal jeg gribe det an - er det overhovedet i min Sequence jeg skal ændre billedet?- Jeg vil altså gerne ændre billedet fra "frog-sitting.png" når jeg slipper "musen/fingeren" fra enheden til "frog-jumping.png".
Koden i min init kan ses her:
self.isTouchEnabled = YES;
CGSize s = [[CCDirector sharedDirector] winSize];
CCSprite *frogCharacter = [CCSprite spriteWithFile:@"frog-sitting.png"];
frogCharacter.position = ccp(s.width/2,s.height/8);
frogCharacter.scale = .50;
[self addChild:frogCharacter];
frogCharacter.tag = 1;
CCSprite *background = [CCSprite spriteWithFile:@"background.png"];
background.anchorPoint = ccp(0,0);
background.scale = .50;
[self addChild:background z:-1];
}
return self;
}
-(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
CCSprite *frogCharacter = (CCSprite *) [self getChildByTag:1];
if (CGRectContainsPoint([frogCharacter boundingBox], location)) {
[frogCharacter runAction:[CCSequence actions:
[CCCallFuncND actionWithTarget:self selector:@selector(changeImage:data:) data:@"frog-jumping.png"],
[CCMoveBy actionWithDuration:0.5 position:ccp(0,240)],
[CCMoveBy actionWithDuration:0.2 position:ccp(0,60)],
[CCMoveBy actionWithDuration:0.2 position:ccp(0,50)],
[CCMoveBy actionWithDuration:0.2 position:ccp(0,20)],
[CCRotateBy actionWithDuration:0.1 angle:180],
[CCMoveBy actionWithDuration:0.2 position:ccp(0,-20)],
[CCMoveBy actionWithDuration:0.3 position:ccp(0,-350)],
[CCRotateBy actionWithDuration:0.1 angle:180],
nil]];
}
}
-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
CCSprite *frogCharacter = (CCSprite *) [self getChildByTag:1];
if (CGRectContainsPoint([frogCharacter boundingBox], location)) {
frogCharacter.position = location;
}
}
På forhånd tak for hjælpen! :)