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

2012/12/12

how do i make a wall with scrolling background

KierTulp KierTulp

2012/12/12

#
Hello everybody, I need some help with my Uman THE ROBOT script (here's a link to the scenario) http://www.greenfoot.org/scenarios/6895 Here's my problem: I want to make a wall that blocks my player and when it blocks my player stops the background from moving. As of right now i have made a wall that can block my player, but when I walk into it blocks him and my background keeps scrolling. My walls block only from one way because I am not sure on how to make him block from each direction, if you happen to know a way on stopping that I would be glad to implement that as well. I am not the very best at coding so if you awnser, please awnser in easy codes :D. I am aware that I already made this topic, but i wasn't very clear on what the problem was in that one, and I really need this awnser now, so i made a new topic in hope of getting helped earlier. thanks in advance.
danpost danpost

2012/12/12

#
Do the collision checking as normal for the Uman object (in the Uman class, check for intersecting Wall object and do not move, if about to move into one ).
KierTulp KierTulp

2012/12/12

#
Yes, but when I keep holding right, my background will keep scrolling, pushing me out of sight. I need my character to stay in the center. your code will stop my player from going through walls, but it will not stop my background from scrolling when i hold the right key.
danpost danpost

2012/12/12

#
The scrolling background must be controlled by the player's movement also. The key presses should only control the player.
KierTulp KierTulp

2012/12/12

#
but how should I make the background move? Can i make the background move from in the code of the player? like put a code in my uman class saying that the background should move? Could you give me an example say like a code in which you show what needs to be done in my uman class? thanks for the awnsers.
danpost danpost

2012/12/12

#
I see you have not updated your scenario lately. Maybe you should show what you have so far. so I can help in a more efficient manner.
KierTulp KierTulp

2012/12/12

#
I just updated it( http://www.greenfoot.org/scenarios/6895 ), but I havn't really changed that mutch about it. In this one i still have the keypress controles in my background because I dont really know how to make my background move in my player class. i have two walls, the wallrechts blocks from the right side, and wall links blocks from the left side. I did this because i am not sure on how to make on object that blocks from all sides. I used to use my Uman for walking, with the checkKeys in the uman code, but I decided to switch to the scrolling background because the levels needed to be bigger. I kept the checkKeys in the Uman code just in case I needed it again. I placed one of the walls out side of view using the tecnique you showed me. I added walls to show what the biggest problem is right now. When you just hold right, my character will stop when hitting the wall but the scrolling doesn't. thanks!
danpost danpost

2012/12/12

#
I had a lot of trouble looking at the code due to OutOfMemory errors (too many large images). Was not able to look at it on site; but was able to download it and, with some juggling of images, finally got to look at the code. I believe it might be best for you to remove what images you are not using at the moment and re-upload it as I am not seeing, at this point, that which you described in your last post. In fact, I never saw any wall (or block) objects in the world.
KierTulp KierTulp

2012/12/12

#
i deleted a lot of the pictures i wasn't using so i hope that fixed the problem, i also added a wall in the back so if you walk to the left you will see a huge wall you cant pass through, unfortunately my background still scrolls so the uman will be blocked out of sight. I hope this shows you the problem of my background still being able to scroll when you walk into a wall. thanks again!
danpost danpost

2012/12/12

#
Remove all movement code from everything except the uman class which should have a 'checkKeys' call in the 'act' method. Then add the following 'act' method to the world class:
public void act()
{
    uman um=(uman) getObjects(uman.class).get(0);
    int dx=um.getX()-getWidth()/2;
    for(Object obj : getObjects(null))
    {
        Actor actor=(Actor)obj;
        actor.setLocation(actor.getX()-dx, actor.getY());
    }
}
KierTulp KierTulp

2012/12/12

#
thanks for the awnser! it worked fine but I got this error. Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space I ignored it at first and your code worked fine exept for the fact that the ground beneath me still slides so when i walk to the side it eventually dissapears beneath me. but when I try to open the sourcecode i keep getting that error. I also noticed that my background(the one in the actor class) is gone, and i dont know why. I am not sure if it works because of there not being a background right now. do you happen to know a solution to this error?
danpost danpost

2012/12/12

#
I am not sure if it is because you are using too much space with images (you image folder contains too much data) or possibly you have one or more images that are corrupted. Remember, I said I had to juggle the images out of the folder and move them back in one at a time to get an idea of what was going on with the scrolling.
danpost danpost

2012/12/12

#
By the way, my system would not let me delete some of the files in your scenario (telling me that they were still in use; even when nothing was open). I had to re-format to get rid of them. Fortunately, I am using USB drives. I copied all the files to another flash to re-format, then copied them back. Then, I was able to delete them.
You need to login to post a reply.