thank you. I'm getting closer to figure that out.
but still have problems with the "display tree architecture", i guess...
this is what I did so far:
I created a BallController and a Ball class.
In the Game.h the controller is initialized like this:
-- Game.h:
#import <Foundation/Foundation.h>
#import "Sparrow.h"
@class Ball, BallController;
@interface Game : SPStage {
BallController *bController;
SPSprite *playFieldSprite;
SPSprite *bContainer;
}
@property (nonatomic, retain) BallController *bController;
-- Game.m:
// inside the initWithWidth method
bController = [[BallController alloc] initInSprite:bContainer numberOfBalls:10];
-- BallController.m:
-(id) initInSprite:(SPSprite*)theContainer numberOfBalls:(NSInteger)numBall{
int xPos = 10;
int yPos = 10;
int i;
ballCollection = [NSMutableArray array];
[ballCollection retain];
for (i=0; i<numBall;i++){
NSLog(@"new ball!");
xPos += 10; // move the new ball a bit...
yPos += 10;
Ball *newBall = [[Ball alloc]xPosition:xPos yPosition:yPos inSprite:theContainer];
[ballCollection addObject: newBall];
}
return self;
}
-- Ball.m:
- (Ball *)xPosition:(NSInteger)xPos yPosition:(NSInteger)yPos inSprite:(SPSprite *)container{
SPImage *image = [SPImage imageWithTexture:[SPTexture textureWithContentsOfFile:@"ball.png"]];
image.x = xPos;
image.y = yPos;
[container addChild:image];
moveX = 1;
moveY = 1;
return self;
}
The 10 balls appear on the screen, but I can't access them via onEnterFrame:
when I try to run the onEnterFrame eventListener
in the BallController.m or the Ball.m, its not firing at all.
I only can get it working in the main SPStage class.
And when I try what you suggested ( ball.x += [ball moveX]; etc.)
the debugger shows the error "invalid operands to binary + (have 'float' and 'id')"
oh my... I really wish that someone writes a tutorial on this topic...
however, any help is welcome