Hi,
I am implementing a simple finger tracker animation (circle fading out) and it seems to work. However, when I run it in instruments, there is no deallocation taking place. Am I doing something wrong? How does a programmer ensure object transiency using Sparrow? Using Sparrow Main 2.01 w/ ARC.
I wish to use many temporary objects in my programming and it would be quite a pain if too many retains end up damaging performance.
Here is my code
//
// Game.m
// AppScaffold
//
#import "Game.h"
// --- private interface ---------------------------------------------------------------------------
@interface Game ()
- (void)setup;
- (void)onImageTouched:(SPTouchEvent *)event;
- (void)onResize:(SPResizeEvent *)event;
@end
// --- class implementation ------------------------------------------------------------------------
@implementation Game
{
SPSprite *_contents;
SPTexture * _circleTex;
}
- (id)init
{
if ((self = [super init]))
{
[self setup];
}
return self;
}
- (void)dealloc
{
[Media releaseAtlas];
[Media releaseSound];
}
- (void)setup
{
[SPAudioEngine start];
[Media initAtlas];
[Media initSound];
_contents = [SPSprite sprite];
[self addChild:_contents];
SPImage *background = [[SPImage alloc] initWithContentsOfFile:@"background.png"];
[_contents addChild:background];
_circleTex = [[SPTexture alloc] initWithContentsOfFile:@"fingerCircle.png"];
[self addEventListener:@selector(onResize:) atObject:self forType:SP_EVENT_TYPE_RESIZE];
[self addEventListener:@selector(onTouch:) atObject:self forType:SP_EVENT_TYPE_TOUCH];
}
- (void) onTouch: (SPTouchEvent *) event
{
NSArray * touches = [[event touchesWithTarget:self] allObjects];
@autoreleasepool {
for (SPTouch * touch in touches)
{
SPPoint * point = [touch locationInSpace:_contents];
SPImage * fingaTracker = [[SPImage alloc] initWithTexture:_circleTex];
fingaTracker.x = point.x;
fingaTracker.y = point.y;
fingaTracker.pivotX = _circleTex.width * 0.5;
fingaTracker.pivotY = _circleTex.height * 0.5;
SPTween * fadeOut = [SPTween tweenWithTarget:fingaTracker time:1.0f];
[fadeOut animateProperty:@"alpha" targetValue:0.0f];
[Sparrow.juggler addObject:fadeOut];
[fingaTracker addEventListener:@selector(removeFromParent) atObject:fingaTracker forType: SP_EVENT_TYPE_REMOVE_FROM_JUGGLER];
[_contents addChild:fingaTracker];
}
}
}
- (void)updateLocations
{
int gameWidth = Sparrow.stage.width;
int gameHeight = Sparrow.stage.height;
_contents.x = (int) (gameWidth - _contents.width) * 0.5;
_contents.y = (int) (gameHeight - _contents.height) * 0.5;
}
- (void)onResize:(SPResizeEvent *)event
{
NSLog(@"new size: %.0fx%.0f (%@)", event.width, event.height,
event.isPortrait ? @"portrait" : @"landscape");
[self updateLocations];
}
@end
Thank you for your consideration.