My character must stop when he see the the right or the left side of platform. I have already done the top side and from above. But when he touches the left or right side he teleports to the top of the platform. Help me to find a mistake
Thank you. And sorry for my bad english.
Let's see my code.
public boolean checkRightPlatform()
{
int spriteWidth = getImage().getWidth();
int xDistance = (int)(spriteWidth/2);
Actor rightPlatform = getOneObjectAtOffset(xDistance, 0, Platform.class);
if(rightPlatform != null)
{
Speed = 1;
stopByRightPlatform(rightPlatform);
return true;
}
else
{
return false;
}
}
public void stopByRightPlatform(Actor rightPlatform)
{
int rightPlatformWidth = rightPlatform.getImage().getWidth();
int newX = rightPlatform.getX() + (rightPlatform.getX() + getImage().getWidth())/(-2);
setLocation( newX, getY() );
}
public boolean checkLeftPlatform()
{
int spriteWidth = getImage().getWidth();
int xDistance = (int)(spriteWidth/2);
Actor leftPlatform = getOneObjectAtOffset(xDistance, 0, Platform.class);
if(leftPlatform != null)
{
Speed = 1;
stopByLeftPlatform(leftPlatform);
return true;
}
else
{
return false;
}
}
public void stopByLeftPlatform(Actor leftPlatform)
{
int leftPlatformWidth = leftPlatform.getImage().getWidth();
int newX = leftPlatform.getX() + (leftPlatform.getX() + getImage().getWidth())/(-2);
setLocation( newX, getY() );
}
