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

2013/9/4

Help with Changing the background when actor hits edge of world.

I know it's probably a stupid fault I made, but I can't figure it out. Can anyone tell me what I did wrong? Here's my code for background changing: public boolean atWorldEdge() { return (atHorizontalEdge() || atVerticalEdge()); } private boolean atVerticalEdge() { return (getX()<20 || getX()>getWorld().getWidth()-20); } private boolean atHorizontalEdge() { return (getY()<20 || getY()>getWorld().getHeight()-20); } if(atWorldEdge()) { if(atSideEdge()) { getWorld().setBackground("wolf-love.jpg"); int w=getWorld().getWidth(); setLocation((getX()+w-60)%(w-40)+20, getY()); } It's saying the "if(atWorldEdge())" is an illegal start of type, how do I fix that? I want my character to hit the edge of the world and then when that happens have the background scene change to another.
danpost danpost

2013/9/4

#
The code starting on that line is not within any method. You probably meant to have that in a 'public void act' method.
Ohhh okay thank you
With my code I made my character move and turn, but the character I made skips around instead of moving smoothly... Can I fix that? Here's the code: public void act() { move(1); turn(); } public void move(int moveAmt) { int dx = 0, dy = 0; if (Greenfoot.isKeyDown("d")) dx += 1; if (Greenfoot.isKeyDown("a")) dx -= 1; if (Greenfoot.isKeyDown("s")) dy += 1; if (Greenfoot.isKeyDown("w")) dy -= 1; for (int i = 0; i < moveAmt; i++) { setLocation(getX() + dx, getY()); if (getOneIntersectingObject(Wall.class) != null) setLocation(getX() - dx, getY()); setLocation(getX(), getY() + dy); if (getOneIntersectingObject(Wall.class) != null) setLocation(getX(), getY() - dy); } public void turn() { if (Greenfoot.isKeyDown("s")) { setRotation(90); } if (Greenfoot.isKeyDown("w")) {setRotation(270); } if(Greenfoot.isKeyDown("d")) {setRotation(0); } if(Greenfoot.isKeyDown("a")) {setRotation(180); }
danpost danpost

2013/9/4

#
There does not appear to be anything within the code provided that would cause that behavior. Are you sure there is no other code either in this class or elsewhere that could change the location of the character and produce that behavior?
I can send the whole code of my character to you so you may check it? Would you want me to?
danpost danpost

2013/9/5

#
You could upload the scenario on the site (making sure you check the 'Include source code' checkbox). Name it something as you would normally with '(WIP)' after the name (for 'work in progress').
I tried to publish the scenario, but when i click share after inputting all the information the program just says... "Publish failed: The host did not accept the connection withi..." And then it just cuts off the rest.
I understand what happened. The computer I tried publishing on wouldn't let me publish. I guess some weird restricted settings were in place that I couldn't get too. So I changed my computer and the game was published as Game-testing Work in Progress. Sorry bout all this, I know it may be troublesome helping me.
danpost danpost

2013/9/7

#
The reason your character does not move smoothly is because you have the scenario speed (set by the slider) way too slow and the move distance of your character is too large. Move the speed slider to around the middle of the bar and change the number in your 'move(int)' statement in the froggy class to a lesser number; maybe 3 .
Oh okay thank you
You need to login to post a reply.