so my today goal is try to understand what the meaning of each of the complicated file
there is a helloworld.h and helloworld.m
the .h seem like is declare what is the classes and .m contain all the method and function
but i still cannot understand how the entire stuff running
on my helloworld.h i have 2 interface
===========================
@interface helloworld:CCColorLayer
@interface HelloworldScene: CCScene
( I am just guessing we need a scene, inside the scene we have a layer)
on my helloworld.m i have 2 implementation with 10 function
===========================================
@implementation HelloworldScene
-(id)init
-(void)dealloc
(I am guessing one is for initialize and one is for deallocate memory)
@implementation HelloWorld
-(void)spriteMoveFinished:(id)sender
-(void)addTarget
-(void)gameLogic:(ccTime)dt
-(id)init
-(void)update:(ccTime)dt
-(void)pauseGame
-(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
-(void)dealloc
(this one complicate out of me, there are 8 method inside the implementation of hello world, but which one of the method is the timer? i am guessing is the update???? let me check the code inside)
ok, after 2 minutes of reading,
i found inside the -(id)init there is 2 line of scheduling code
// Call game logic about every second
[self schedule:@selector(gameLogic:) interval:1.0];
[self schedule:@selector(update:)];
i guess this is the way it run the timer, every single second it will call the method "gamelogic and also "update"
the (void)gameLogic will calling the (void)addTarget every single second, and (void)addTarget will create an enemy every single second by first declaring the
CCSprite *target = [CCSprite spriteWithFile:@"Target.png" rect:CGRectMake(0, 0, 27, 40)];
target.position = ccp(winSize.width + (target.contentSize.width/2), actualY);
[self addChild:target];notice all this SELF stuff is very confusing i guess you need to memorize them
inside the (void)update there are 4 for loop i guess is to loop through all the stuff every single second
for (CCSprite *projectile in _projectiles) {
for (CCSprite *target in _targets) {}
}
for (CCSprite *target in targetsToDelete) {}
for (CCSprite *projectile in projectilesToDelete) {}
But I cannot found the code part of enemy movement and projectile movement inside the (void)update method i guess the code must be somewhere
after 2 minute of searching, i found this two code inside the (void)addTarget and (void)ccTouchesEnded
// Create the actions
id actionMove = [CCMoveTo actionWithDuration:actualDuration position:ccp(-target.contentSize.width/2, actualY)];
id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)];
[target runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];
// Move projectile to actual endpoint
[projectile runAction:[CCSequence actions:
[CCMoveTo actionWithDuration:realMoveDuration position:realDest],
[CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)],
nil]];
Seem like the object CCSprite have its own runAction which will move auto once you set it
ok
So it only mean one thing, the (void)update is only used as a collision detection
first it loop the projectile, for each projectile it check is it collide with the target, if yes, remove both the projectile and the target
ok, i can understand 80% to 90% now, so can move along to the next tutorial
So it only mean one thing, the (void)update is only used as a collision detection
first it loop the projectile, for each projectile it check is it collide with the target, if yes, remove both the projectile and the target
ok, i can understand 80% to 90% now, so can move along to the next tutorial