Report as inappropriate.
You can use the ScrollingWorld class provided with this project to make scrolling worlds. The AppleWorld that the project starts up with is a simple example.
Use the arrow keys to scroll around and check out all the drifting apples. If you'd like to use this code in your own project, check out the comments in the code for the ScrollingWorld class, because there are a few idiosyncrasies about the way it works.
Questions I suspect you might have:
Q: Is this a repost of danpost's Scrolling SuperWorld?
A: No. This was created independently of danpost's project. It's kind of similar, except probably not as good.
Q: Is this adaptable to [x kind of project]?
A: Yes! The ScrollingWorld is a very general class. Here, we only see it used to examine apples drifting across a grid of smiley faces in space, but it could be used in any kind of project: sidescrolling, 2D RPG / adventure / exploration, arcade, etc. There is no "ScrollingActor" -- any kind of actor you wish to use can be put in a ScrollingWorld. Also, scrolling isn't necessarily controlled by the arrowkeys -- that's just for the purpose of this example. Normally the scrolling would be controlled by code.
Q: What about something where you have to click on things?
A: Sorry, no. At least not yet. Since the actors aren't *actually* in the world -- just being *drawn* to the world, while being *stored* in *another* world that's *technically* not currently on-screen -- using mouse events will give inaccurate results at best and no results at worst. I have something in mind that might be able to fix it, but that will happen later.
Q: Can the background scroll?
A: Nope. Making a background that big would be a huge memory sink. Besides, as long as you have enough actors to build a coherent world, a motionless background hopefully shouldn't be too much of an issue. I might address this later as well.
Q: Why aren't my actors scrolling?
A: Read the comments in the source code for ScrollingWorld. You can't just add actors directly into the world -- well, you can, but they're just going to stay on the screen. You have to add actors into the world that dwells *within* the world. You can access the world that lives in the world with getUnderlying().
Q: What do I do if my question isn't listed?
A: Leave a comment below and I'll be sure to get back to you!
Want to leave a comment? You must first log in.
No votes yet.