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

Comments for Scrolling SuperWorld

Return to Scrolling SuperWorld

danpostdanpost

2013/1/11

@Dytanoth, in the meantime, you may have to do that yourself and use the finished image as the scrolling background.
DytanothDytanoth

2013/1/11

I'm not sure I complete understand what you are saying. I've put my scenario http://www.greenfoot.org/scenarios/7217. The world that is active is your world, it's called MyWorl3d. My world is named MyWorld. What do you mean by finished image, and what do i have to do myself :S If you can use some granny language, or even look at my scenario i'd be very gratefull
danpostdanpost

2013/1/11

@Dytanoth, my world did not have an act method in it. By you putting one in your world, it overrides the one in the 'SWorld' super-class. You just need to add the statement 'super.act();' in the 'act' method of your 'MyWorld' world class.
DytanothDytanoth

2013/1/13

Some of my actors, have a specific act on a location. How can I make sure my y-value, becomes a y+scroll value?
danpostdanpost

2013/1/13

@Dytanoth, you should be able to code their movement as normal using move(int) or setLocation(int, int). If using the 'setLocation(int, int)' method during game play, base the int values on the current x and y value of the actor; that is 'setLocation(getX()+xOffset, getY()+yOffset);'. Using absolute locations will not guarantee that the actor will end up in the world where you want because the scrolling world makes
danpostdanpost

2013/1/13

Sorry, did not mean to submit yet -- continuation follows: each location have various universal coordinates.
danpostdanpost

2013/1/13

I guess what I was trying to say was this: When using scrolling, no coordinates are absolute.
A new version of this scenario was uploaded on Sun Jan 13 10:46:23 UTC 2013 A support class for a scrolling world. Added a method for more versitility.
danpostdanpost

2013/1/13

@Dytanoth, I have incorporated the 'fillScrollingBackground' method into my scenario and uploaded it (with some minor comment changes). Hope this helps.
DytanothDytanoth

2013/1/13

That is really helpfull, thanks! You are fantastic!
your codes seem very complex. do you mind explaining it to me? the world, sworld and my world? Thank you. (I'm just a beginner btw, please go easy on me)
danpostdanpost

2013/3/5

I will start a Discussion thread called 'On Scrolling SuperWorld by danpost'. Please ask any specifics as to what you would like to know there. I will start will a general run-down.
where is that discussion thread? thank you again for being so helpful. :)
JetLennitJetLennit

2013/4/1

may i use this for something i want to make?
danpostdanpost

2013/4/1

Sure. After you 'like' it.
danpostdanpost

2013/4/1

@Velociraptor06, I was going to start one, but realized that the scenario was well documented with comments and all that it was not worth starting a new thread. If you have any specific questions about it that are not explained within the documentation, you can start the thread yourself and inform me that you have done so by leaving a comment here.
JetLennitJetLennit

2013/4/1

Thank you!
JetLennitJetLennit

2013/4/1

i'm confused...
danpostdanpost

2013/4/1

@JetLennit, start a discussion thread and explain why you are confused.
JetLennitJetLennit

2013/4/1

I suppose that i get it.... or at least i can use it =)
al_griffal_griff

2013/4/10

Is there a way to have the extra parts of the world populate to the right of your actor? At the moment, the space to scroll is split between the left and right.
danpostdanpost

2013/4/10

@al_griff, are you wanting your main actor to start at the left edge of the scroll world?
danpostdanpost

2013/4/10

My main actor is a Wombat object. To start him on the left edge of the scrollable world, the following can be used in the constructor for the subclass of SWorld: Wombat wombat = new Wombat(); // creates the main actor setMainActor(wombat, 250, 300); // sets as main actor and sets its range of movement GreenfootImage bg = new GreenfootImage("scene.jpg"); // create background image setScrollingBackground(bg); // set the scolling background image int leftOffset = -getUnivX(wombat.getX()); // get -offset from left edge of scroll world wombat.move(leftOffset); // move actor to left edge of scroll world act(); // adjust the scrolling background // add the rest of your objects
danpostdanpost

2013/4/10

@al_griff, the previous post has the code to do what I believe you wanted to do. The last line should probably read 'super.act()' (in case you add an act to your world -- if you do, make sure you call 'super.act()' in it also or the scrolling will not work).
al_griffal_griff

2013/4/12

Ok, thanks for that, I'll add that and see what happens.
JetLennitJetLennit

2013/4/22

Could you check this http://www.greenfoot.org/topics/3459?
al_griffal_griff

2013/4/23

I'm getting problems with the int leftOffset = -getUnivX(player.getX()); Greenfoot is saying that it cannot find the symbol.
danpostdanpost

2013/4/23

Are you placing this code in your sub-class of SWorld?
al_griffal_griff

2013/4/23

Yes.
danpostdanpost

2013/4/24

Maybe you should start a discussion, and explain what Greenfoot says it cannot find and give the code around where that highlighted statement is.
A new version of this scenario was uploaded on Fri Apr 26 05:04:38 UTC 2013 Added some helper methods.
A new version of this scenario was uploaded on Fri Apr 26 05:09:39 UTC 2013 Added some helper methods.
A new version of this scenario was uploaded on Fri Apr 26 11:38:46 UTC 2013 Added comments/documentation for the newly added methods.
Hey danpost, could you explain the UnviX and UnviY methods? I'm not exactly sure what they are supposed to do.
danpostdanpost

2013/5/10

@FlyingRabidUnicornPig, you enter a window coordinate in the parameter and it returns the universal coordinate. The top-left corner of the window in window coordinates is always (0, 0), no matter what scrolling has taken place; however, in universal coordinates, (0, 0) is always the top-left corner of the scrolling area. So, for example, if you wanted to know how far the background can scroll to the left in order to get to the left edge of the universe (or the left-most scrolling limit), you can use 'int remainingScrollToLeft = getWorld().getUnivX(0);'
Thank you!
What if I wanted to get the full width?
And I'm also getting a null pointer exception when trying to use getUnivX.
danpostdanpost

2013/5/10

Start a discussion and show your code.
A new version of this scenario was uploaded on Fri May 10 03:12:33 UTC 2013 'getUnivX' and 'getUnivY' can now be used without a background image being set.
A new version of this scenario was uploaded on Sat May 11 19:51:03 UTC 2013 Added methods to return the height and width of the scrolling area.
Entity1037Entity1037

2013/5/14

How do you make an exception for scrolling like for health meters?
danpostdanpost

2013/5/14

Same way I added the Counter object into the world in this scenario.
Entity1037Entity1037

2013/5/14

Oh duh, I feel stupid now. Thanks.
Entity1037Entity1037

2013/5/14

But wait, how do you do this from an actor? I'm sorry for all of the questions, but I'm only in Computer Science 1 and I don't know as much as I'd like to.
danpostdanpost

2013/5/14

Just prefix it with 'getWorld().'.
Entity1037Entity1037

2013/5/14

I do, but it doesn't let me use a boolean parameter at the end. I think it's calling the built in "addObject" method, and not the one you made.
danpostdanpost

2013/5/14

Ok. Prefix with '((SWorld)getWorld).'.
danpostdanpost

2013/5/14

That was supposed to be '((SWorld)getWorld()).'.
Entity1037Entity1037

2013/5/14

Ok nevermind, you just do ((SWorld)getWorld()).addObject(new Health1(),30,health,false);