Good day,
A null-pointer error is occurring upon trying to adding new 'Heart' class objects to the world through the 'Player' actor. (the method which creates new objects in the world was added to the 'Player' class constructor. I wouldn't know if this is error causing however...)
Would like an extra pair of eyes which could help pin-point what is causing the error:
It can be noted that the 'removeHearts' method is commented as that method seemed to cause errors for me when running as well of which I do not grasp as to why either... (do I need to store the actor list in something else?)
Let me know if you wish to see the error report.
private void removeHearts()
{
getWorld().removeObjects( getWorld().getObjects(Health.class) );
}
private int[] heartsCoordX=
{
92,97,102,92,97,102,92,97,102
};
private int[] heartsCoordY=
{
16,21,26
};
private void createHearts(int healthNo)
{
int iX = 0;
int iY = 0;
//removeHearts();
if(healthNo <4)
{
while(iX < healthNo)
{
getWorld().addObject(new Health(), heartsCoordX[iX],heartsCoordY[iY] );
iX += 1;
}
}
if(healthNo > 3 && healthNo < 7)
{
while(iX < healthNo)
{
getWorld().addObject(new Health(), heartsCoordX[iX],heartsCoordY[iY] );
iX += 1;
if(iX == 4)
{
iY += 1;
}
}
}
if(healthNo > 6)
{
while(iX < healthNo)
{
getWorld().addObject(new Health(), heartsCoordX[iX],heartsCoordY[iY] );
iX += 1;
if(iX == 4)
{
iY += 1;
}
if(iX == 7)
{
iY += 1;
}
}
}
}
public int healthCount = 3;
public int healthChange(int callType)
{
if(callType == 1)
{
healthCount -= 1;
}
if(callType == 2)
{
healthCount -= 2;
}
return healthCount;
}
int health;
private void health()
{
if(health != healthChange(0))
{
createHearts(health);
healthChange(-health);
}
if(health == 0)
{
//Greenfoot.setWorld(new GameOver());
//getWorld().showText("Would be what you could acknowledge if you had actually won", 42,32);
//getWorld().removeObject(this);
}
health = healthChange(0);
}

