Clear an int[x][y] array in Objective-C
I am working on a iPhone game. Everything is working fine, but what is the correnct way to reset a array of ints in Objective-C? The array holds the coordinates for walls in each level. The array is set, every time a new level is loaded - But how can i开发者_JAVA技巧 "clear" the array?
LevelData.h
int wallH[50][2];
int wallV[50][2];
LevelData.m
-(void)setLevelOne {
// (50, 70)
wallH[0][0] = 50;
wallH[0][1] = 70;
// (50, 90)
wallH[1][0] = 50;
wallH[1][1] = 90;
// And so on ...
// The same for wallV (Vertical walls in the level)
}
How can I "clear" the array, so it's ready for the next level? [wallH release] doesn't work - We are talking about a c array :/
You can zero array using memset
function (in your case you know the number of elements in array so you can use "hardcoded" 100 determining size):
memset(wallH, 0, 100*sizeof(wallH[0][0]);
精彩评论