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

2019/4/12

DansPost - ImgScroll (Questions)

OnFight OnFight

2019/4/12

#
(Intro: So, I was making an '2D RPG' style project, and made a 4000x4000 base Map, with a viewpoint of 1280x720, and I wanted to make my Actor Centered and then make the Background Scroll accordingly to the Actor's movement.) Just like in this guide: DansPost Tutorial It has a Scroller Class and multiple instances of different Scroller types. The one I wanted to implement in my "Main" World was the ImageScroll (which meets all the requisites) to what I wanted in the first place. So I wrote the following code provided in the Tutorial for the ImageScroll. The Question is: In the Tutorial he provides two different "private void scroll()" methods: The first one that does: The Second one that does:
First:

// attempts scrolling when actor is not in center of visible world
    
private void scroll(){
(...)
}

Second:

// the following can be used to allow some actor movement before scrolling begins:
// attempts scrolling when actor is outside roaming limits
    
private void scroll(){
(...)
}
Which gives me an Error, "method scroll() is already defined in (this) class" The first question I had was: I am defining the "ImageScrollWorld" under World to then create a Subclass which creates an instance of this type of World ("ImageScrollWorld"), is that how it is meant to be done? The second question was: I assume the second definition of "method scroll()" is probably meant to be written as maybe Override somewhere else?? If yes, where should I call it?? Under my World instance of "ImageScrollWorld", in a instance of "Player" under Actor? ------------------------------------------ (I've only had a few weeks of experience under Greenfoot, maybe the questions are obvious, but I don't wanna move or Delete any further code without a "public opinion").
danpost danpost

2019/4/12

#
OnFight wrote...
In the Tutorial he provides two different "private void scroll()" methods: << Code Omitted >> Which gives me an Error, "method scroll() is already defined in (this) class"
You are only to use one of those methods -- not both. In your case, use the first one.
The first question I had was: I am defining the "ImageScrollWorld" under World to then create a Subclass which creates an instance of this type of World ("ImageScrollWorld"), is that how it is meant to be done?
No. You have your "Main" world. In it, you create a Scroller object and add your scroll method. Then call the scroll method from its act method (which you may have to add).
The second question was: I assume the second definition of "method scroll()" is probably meant to be written as maybe Override somewhere else?? If yes, where should I call it?? Under my World instance of "ImageScrollWorld", in a instance of "Player" under Actor?
Answered (do not use that second scroll method; remove it).
OnFight OnFight

2019/4/12

#
danpost wrote...
OnFight wrote...
In the Tutorial he provides two different "private void scroll()" methods: << Code Omitted >> Which gives me an Error, "method scroll() is already defined in (this) class"
You are only to use one of those methods -- not both. In your case, use the first one.
The first question I had was: I am defining the "ImageScrollWorld" under World to then create a Subclass which creates an instance of this type of World ("ImageScrollWorld"), is that how it is meant to be done?
No. You have your "Main" world. In it, you create a Scroller object and add your scroll method. Then call the scroll method from its act method (which you may have to add).
The second question was: I assume the second definition of "method scroll()" is probably meant to be written as maybe Override somewhere else?? If yes, where should I call it?? Under my World instance of "ImageScrollWorld", in a instance of "Player" under Actor?
Answered (do not use that second scroll method; remove it).
Lovely, managed to get it to work, thank you.. :) But I am still curious what is behind the making of the second scroll? If something goes wrong it corrects? Like if somehow you manage to get outside of the limits?
danpost danpost

2019/4/12

#
OnFight wrote...
I am still curious what is behind the making of the second scroll? If something goes wrong it corrects? Like if somehow you manage to get outside of the limits?
The second scroll is used to allow your main actor some wiggle room before scrolling takes effect. That is, with that method, scrolling will not begin until your main actor moves some allowable distance away from the center of the window.
OnFight OnFight

2019/4/12

#
danpost wrote...
OnFight wrote...
I am still curious what is behind the making of the second scroll? If something goes wrong it corrects? Like if somehow you manage to get outside of the limits?
The second scroll is used to allow your main actor some wiggle room before scrolling takes effect. That is, with that method, scrolling will not begin until your main actor moves some allowable distance away from the center of the window.
Oh, i should've had calculated that was it, (the demo had an option for bigger region).
You need to login to post a reply.