Im starting with CoCos2d development and I think I have some issues with nodespace, and actions, this is my code and nothings moving although I seem to have no errors when running the code, any comments are appreciated:
+(id) create {
return [[self alloc] init];}
-(id) init {
if ((self = [super init]))
{
CGSize scSize = [[CCDirector sharedDirector] winSize];
self.position = ccp(0,scSize.height);;
touchArea = [CCSprite spriteWithFile:@"touchArea.png"];
[touchArea setAnchorPoint:ccp(0, 0.5)];
[self addChild:touchArea];
obj_1 = [CCSprite spriteWithFile:@"obj1.png"];
obj_2 = [CCSprite spriteWithFile:@"obj2.png"];
obj_3 = [CCSprite spriteWithFile:@"obj3.png"];
obj_tab = [NSMutableArray arrayWithObjects:obj_1, obj_2, obj_3, nil];
for (int i=0; i < obj_tab.count; i++)
{
CCSprite *obj = [obj_tab objectAtIndex:i];
float offSetPos = ((float)(i+1)) / (obj_tab.count +1);
CGPoint pos = ccp(scSize.width*offSetPos, 0);
obj.position = pos;
[obj setAnchorPoint:ccp(0.5, -0.25)];
[touchArea addChild:obj];
}
velocidad = 3;
destino = ccp(0,-100);
//[self scheduleUpdate];
[self moveIt] // <-- Edited to call another method
}
return self;
}
-(void) moveit{
CCMoveTo *moverAction = [CCMoveTo actionWithDuration:5 position:ccp(0,0)];
CCCallFunc *onEndAction = [CCCallFunc actionWithTarget:self selector:@selector(onEndMove:)];
CCSequence *moveSequence = [CCSequence actions: moverAction, onEndAction, nil];
[touchArea runAction:moveSequence];
{
-(void) update:(ccTime)delta {
}
-(void)onEndMove:(id)sender{
NSLog(@"OnEndMove fired");
}
-(void) onEnter{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:-1 swallowsTouches:YES];
}
-(void) onExit {
[[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
}
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{
CGRect boundingBox = touchArea.boundingBox;
boundingBox.origin = CGPointZero;
BOOL isTouchHandled = CGRectContainsPoint(boundingBox, [touchArea convertTouchToNodeSpace: touch]);
//NSLog(@"touchLocation y = %f", touchLocation.y);
//NSLog(@"touchArea y = %f", touchArea.position.y);
if (isTouchHandled){
NSLog(@"Touch Handled");
}
return isTouchHandled;
}
@end
I am assuming that ‘self’ , the class of the code showed above, derives from CCNode. Make certain that ‘self’ is running, it must be a descendant of CCNode, and will be running when it is added to a running node. This is what happens in a CCNode’s onEnter (taken from version 1.0.1):
this is where the scheduler and actions are enabled for the node. If it is never invoked, your actions will not run.
You could move your moveIt code to the onEnter method, which will be invoked when the object becomes running.