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

2013/4/26

Scrolling Super World Issue

al_griff al_griff

2013/4/26

#
This is in regard to danpost's scenario, Scrolling Super World. I've been trying to get my actor to start at the far left edge of the world. As it is at the moment, the actor will instantiate at what seems to be the very middle of the world. I was suggested some code that would solve this issue, but I got an error - cannot find symbol - method getUnivX(int). This my code for instantiating the actor.
Player player = new Player();
        setMainActor(new Player(), 100, 342);
        mainActor.setLocation(100, 342);
        GreenfootImage bg = new GreenfootImage("background.png");
        setScrollingBackground(bg); // set the scolling background image
        int leftOffset = -getUnivX(player.getX());
        player.move(leftOffset);
This is all in my Environment, which is a subclass of SWorld, which is a subclass of the World.
danpost danpost

2013/4/26

#
You are setting 'player' to one Player object, then setting the main actor to a different one. That is why you were getting the error. Change line 2 to:
setMainActor(player, 100, 342);
Then, remove line 3. I think another problem may be the meaning of (100, 342). You seem to think that it is a location when it is not. The second parameter in the 'setMainActor' call (100) is the horizontal range of movement allowed for the actor in the window. The last parameter (342) is the vertical range of movement allowed for the main actor in the window.
al_griff al_griff

2013/4/26

#
So should I be changing those parameters to the size of my world? (600, 400)?
danpost danpost

2013/4/26

#
al_griff wrote...
So should I be changing those parameters to the size of my world? (600, 400)?
If you want your main actor to be able to go to the edges of the window before scrolling begins. If you want your main actor to stay in the middle of the window while the world scrolls until the edge of the scrolling world gets to the edge of the window (then the main actor will move toward that edge), then use (0, 0).
al_griff al_griff

2013/4/26

#
Ok, so I've made the adjustments that you suggested, but I'm still getting the same error. Is the getUnivX(player.getX()); something that is calling on the SWorld?
danpost danpost

2013/4/26

#
The 'getUnivX(int)' method is in the SWorld class (at least it was when you downloaded it). If you open the code to the SWorld class in 'Documentation' view, you should find it listed in the API. I do not think this will help, but maybe you should not refer to 'player' in lines 6 and 7, but to 'mainActor'. Please show the code you are using in your sub-class of SWorld from the beginning at least to the last line listed above.
danpost danpost

2013/4/26

#
I am so sorry. It appears I added some methods to my scenario and did not upload it with them in it. Download the Scrolling SuperWorld again and remove/replace your copy of the SWorld class with the newer version. Then it should work.
al_griff al_griff

2013/4/26

#
Ok, thanks for your help. I'll get back to you if I run into problems.
al_griff al_griff

2013/4/26

#
All seems to be working. Thank you very much for your help. Would you mind if I used this code for my major work? If you would let me that would be extremely helpful.
danpost danpost

2013/4/27

#
Like the scenario and give credit where due and all is well.
al_griff al_griff

2013/4/27

#
Of course. I know that in the scrolling world, there is still the section of yours where you claim ownership. I'll make sure to add a comment in the world source too.
You need to login to post a reply.