This site requires JavaScript, please enable it in your browser!
Greenfoot back
KuroGuroChan
KuroGuroChan wrote ...

2014/4/13

Platform problems... yeah. I'm newbie.

KuroGuroChan KuroGuroChan

2014/4/13

#
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() ); }
danpost danpost

2014/4/13

#
KuroGuroChan wrote...
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
It the character teleports to the top of the platform, the code for the top and bottom might be quite relevant.
KuroGuroChan KuroGuroChan

2014/4/13

#
i actually took a code from an other platform game and i tried to modify it. But it didn't work at all. And i haven't a syntax error or something. Thank you
KuroGuroChan KuroGuroChan

2014/4/13

#
It works perfectly on top or from above.
danpost danpost

2014/4/13

#
KuroGuroChan wrote...
It works perfectly on top or from above.
Maybe it works too good. Comment out the top and bottom collision code and test it to see how the side collision is working. If it still teleports the character to the top of the platform, then I was wrong and I am sorry.
You need to login to post a reply.