A new version of this scenario was uploaded on Tue May 07 07:18:03 UTC 2013
Added a superclass for fixed objects that aren't moved by the scrolling system.
A new version of this scenario was uploaded on Tue May 07 07:21:53 UTC 2013
Added discriptions for the fixed objects.
Click "Open in Greenfoot" download and open the program in Greenfoot, then you can look at the code from inside greenfoot. If you can't figure out how to go from documentation to code, go to the top right corner of the window, and click on the dropdown button that says "Documentation", then click on "Source Code". Or you could press CTR+J
You mean that the actor moves on so that he's not in the middle of the world anymore when he reaches the edge of the scrolling world?
Well this is not provided in this scrolling system.
But if you use my Multi Scrolling Engine (http://www.greenfoot.org/scenarios/10595) it should work.
Using the Multi Scrolling Engine you can change the scrolling system while playing. So you could change it so that the actor is no longer the center of the scrolling system.
i thought the actor should remain in the middle, until he reaches the end of the world.
Then he shoul move normal. If he moves back he should be again in the middle.
How do i do that.
Therefore you need to change the scrolling system using the Multi Scrolling Engine.
I'm currently working on this engine and on exactly this problem.
If you give me a fiew minutes to add some funktions to the engine I can tell you how to do this.
Ok it took a bit longer than I thought but I got it working now.
If you add the following code to your actor it should work:
if (((MultiScrollingWorld) getWorld()).getTotalXMovement() >= MultiScrollingWorld.WORLD_WIDTH/2 - 10) {
((MultiScrollingWorld) getWorld()).setScrollingSystem(MultiScrollingWorld.NO_SCROLLING_SYSTEM);
}
else if (((MultiScrollingWorld) getWorld()).getTotalXMovement() <= -MultiScrollingWorld.WORLD_WIDTH/2 + 10) {
((MultiScrollingWorld) getWorld()).setScrollingSystem(MultiScrollingWorld.NO_SCROLLING_SYSTEM);
}
else if (((MultiScrollingWorld) getWorld()).getTotalYMovement() >= MultiScrollingWorld.WORLD_HEIGHT/2 - 10) {
((MultiScrollingWorld) getWorld()).setScrollingSystem(MultiScrollingWorld.NO_SCROLLING_SYSTEM);
}
else if (((MultiScrollingWorld) getWorld()).getTotalYMovement() <= -MultiScrollingWorld.WORLD_HEIGHT/2 + 10) {
((MultiScrollingWorld) getWorld()).setScrollingSystem(MultiScrollingWorld.NO_SCROLLING_SYSTEM);
}
if (((MultiScrollingWorld) getWorld()).getTotalXMovement() < 0 && getX() < getWorld().getWidth()/2) {
((MultiScrollingWorld) getWorld()).setScrollingSystem(MultiScrollingWorld.CENTRAL_ACTOR_SCROLLING_SYSTEM);
}
else if (((MultiScrollingWorld) getWorld()).getTotalXMovement() > 0 && getX() > getWorld().getWidth()/2) {
((MultiScrollingWorld) getWorld()).setScrollingSystem(MultiScrollingWorld.CENTRAL_ACTOR_SCROLLING_SYSTEM);
}
if (((MultiScrollingWorld) getWorld()).getTotalYMovement() < 0 && getY() < getWorld().getHeight()/2) {
((MultiScrollingWorld) getWorld()).setScrollingSystem(MultiScrollingWorld.CENTRAL_ACTOR_SCROLLING_SYSTEM);
}
else if (((MultiScrollingWorld) getWorld()).getTotalYMovement() > 0 && getY() > getWorld().getHeight()/2) {
((MultiScrollingWorld) getWorld()).setScrollingSystem(MultiScrollingWorld.CENTRAL_ACTOR_SCROLLING_SYSTEM);
}
This will cause that there is no scrolling system used when the actor touches the edge of the world so he's able to move everywhere.
They are just used to visualize some things.
You can delete them in the act method of the class ExampleWorld.
If you delete the whole run method and change the super call in the constructor to this:
super(800, 450, 1, 2000, 2000, MultiScrollingWorld.CENTRAL_ACTOR_SCROLLING_SYSTEM, false);
it should work.
The scrolling system usually stays the same untill you change it.
In the demo I uploaded the scrolling system is changed by clicking on the worlds background.
If you delete the code that causes this (in the run method of the class ExampleWorld) the scrolling system will not change until you change it manually or by moving to the side of the world.
i copied and pasted all the coding but on the first line of the coding where it says gettotalxmovement down the bottom it says it cannot find the symbol.
@AreebRaza:
There are some loops in the createTextur() method of the ScrollingWorld class that might take a long time to complete when the player is very far afield. Here's a version without the loops that uses mod math to do the same job.
/**
* Creates a moving textur on the background image of the world.
*/
protected final void createTextur() {
// Higher performance version:
int x = totalXMovement;
x %= textur.getWidth();
if ( x > 0 ) x -= textur.getWidth();
int y = totalYMovement;
y %= textur.getHeight();
if ( y > 0 ) y -= textur.getHeight();
getBackground().clear();
for (int i = x; i < getWidth(); i += textur.getWidth()) {
for (int j = y; j < getHeight(); j += textur.getHeight()) {
getBackground().drawImage(textur, i, j);
}
}
}
Alright, say I wanted to use this to generate a world as people enter the different areas but keep track of where everything was... How would I do that?
2013/5/27
2013/5/27
2013/5/27
2013/8/13
2014/1/11
2014/1/11
2014/1/11
2014/1/11
2014/1/11
2014/1/11
2014/1/11
2014/1/11
2014/1/11
2014/1/11
2014/1/11
2014/1/11
2014/1/11
2014/1/11
2015/10/9
2016/5/18
2017/2/17
2018/3/28
2018/4/25
2018/6/19
2018/6/19