Hello,
I tried too much to solve the problem of memory but it is still 15 to 16 mb. & my game slows down.
I have 30 levels in my game. There is xml file for each level. in my xml file i set the position,strength,.... for obstacles , enemy info, player tank info, power comes in that level.
I declare arrObstacle, arrPower, arrEnemy globally. when xml loads all sprites are add in array accordingly.
I have obstacle , enemy, power, bullet class files inherited from NSObject.
And all has many attributes as per requirement. eg obstacle class has following things.
NSString *name;
int type;
int life;
int effectType;
int direction;
float speed;
Now, i am moving player tank with accelerometer. I made one function [self schedule:@selector(movePlayerTank:)]; & set direction in accelerate event.
[self schedule:@selector(obstacleAnimation:)];
in which obstacle animation occurs of obstacle.
[self schedule:@selector(enemyAnimation:)];
in which I wrote the code to move enemy. it is very big function. I add the enemyType(int) attribute in my game. i am moving enemy with different logic.
-(void)enemyAnimation:(ccTime)dt
{
for(enemy *e in arrEnemy)
{
if(e.enemyType == 1)
{
//Logic of one type of moving
Check that enemy is not going to collide with any of obstacle and enemy
int resultCollision = [self collisionForEnemy:e direction:e.direction]; // this is the function which checks collision.
if(resultCollision == 0)
{
if no collision then move enemy in the same direction
}
else
{
[self setDirectionfortype1]; // Else i change the direction & this function differs for different enemy type.
}
}
else if(e.enemyType == 2)
{
//Logic of one type of moving
}
.........
else if(e.enemyType == 7)
{
//Logic of one type of moving
}
}
}
@interface obstacles : NSObject
{
Sprite *destroySprite;
NSString *animationname;
int animindex;
}
When player or enemy fires on obstacle one I add "destroySprite " in layer and one animation occurs and when animation completes I remove that sprite and obstacle from layer and array of obstacle.
This is what i am doing in coding.
my game slows down. enemy movement , player tank movement, animation get stuck etc . Pls help me to solve the problem. Is this due to memory???
I complete the game. i am waiting for only this problem to solve.
I made my game in v0.7. Today I downloaded vo.8 & made test application in it to check difference between sprite and Atlas sprite but both use the same memory. so, i didn't convert game to v0.8. is it really make difference if i use AtlasSprite instead of Sprite.??
Thanks in advance.