Bonjour,

Je suis en train de développer un jeu sur iphone en utilisant la library cocos2d, et j'ai un soucis pour mettre à jour la position de mon curseur dans ma fonction d'update.

Je ne fais que ça dans mon update :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
 
-(void)update:(ccTime)dt
{
	cursor.sprite.position = [self getTouchedTilePosition];
}
Voici ma fonction getToucheTilePosition, je pense qu'elle fonctionne, car je passe dedans à l'initialisation de mon curseur et le curseur est à la bonne position au début.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
 
-(CGPoint) getTouchedTilePosition
{
	BoD_Map *m = (BoD_Map*)[world.maps objectAtIndex:0];
	BoD_Tile *t = (BoD_Tile*)[m.tiles objectAtIndex:indexTouchedTile];
	return t.sprite.position;
}
Mon soucis est que une fois l'initialisation passée, quand le programme repasse dans cette fonction durant l'update, le programme crash à la récupération du NSMutableArray maps dans l'objet world, alors qu'il n'a pas été modifié depuis l'initialisation.

Voici mon code d'initialisation :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 
// on "init" you need to initialize your instance
-(id) init
{
	if( (self=[super init] )) 
	{
		indexTouchedTile = (16 / 2) + (15 / 2)*16;
		if( [self initWorld] != 0 && [self initCursor] !=0)
		{
			self.isTouchEnabled = YES;
			[self schedule:@selector(update:)];
			return self;
		}
	}
	return NULL;
}
 
 
//Initialize the world
-(int) initWorld
{
	world = [[BoD_World alloc] init];
 
	if(world != NULL)
	{
		BoD_Map *m = (BoD_Map*)[world.maps objectAtIndex:0];
		for(int i=0; i<[m.tiles count]; i++)
		{
			CCSprite *s = ((BoD_Tile*)[m.tiles objectAtIndex:i]).sprite;
			[self addChild:s];
		}
 
		return 1;
	}else{
		return 0;
	}
}
 
 
//Initialize the cursor
-(int) initCursor
{
	cursor = [[BoD_Cursor alloc] init];
 
	if(cursor != NULL)
	{
		cursor.sprite.position = [self getTouchedTilePosition];
		[self addChild:cursor.sprite];
		return 1;
	}else{
		return 0;
	}
}