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

2013/3/14

Scrolling help needed

1
2
Game/maniac Game/maniac

2013/3/14

#
I would like to make my minecraft game have scrolling implemented but as a block exits the screen I want the world to store all of the blocks data then remove them, and on the opposite side I want new blocks to generate. How do I go around doing this?
Gevater_Tod4711 Gevater_Tod4711

2013/3/14

#
If you want the world to store the objects whichs positions are greater than the worlds size you just have to use another constructor for the world: Instead of World(int worldWidth, int worldHeight, int cellSize) use World(int worldWidth, int worldHeight, int cellSize, boolean bounded) If the last parameter is false the world will store everything that is out of the screen. To generate new objects you have to use your terain generator and create new objects if your character reaches the edge of the world. And also you have to move all of your objects to the left or right if the character reaches the edge of the world.
Game/maniac Game/maniac

2013/3/14

#
Wont it create a lot of lag though if you don't remove the objects
Gevater_Tod4711 Gevater_Tod4711

2013/3/14

#
Yes that would be the case. But if you kan just delete all objects that fall out of the screen. Or if you don't want to remove them because then the world would look diferent you should save them not as objects but as files or strings in your programm. That would take much less ram.
Game/maniac Game/maniac

2013/3/14

#
How do I do that?
-nic- -nic-

2013/3/14

#
Also i noticed that all the code for action for your blocks is in your blocks class's you could take out alot of this code to reduce lagg and put it it into other class's so that you dont have to have so many objects using resources when you could have one or two in exchange for maby less structured code
Game/maniac Game/maniac

2013/3/14

#
Good Idea
Game/maniac Game/maniac

2013/3/14

#
How do you store info in strings
Gevater_Tod4711 Gevater_Tod4711

2013/3/15

#
You have to write a method that gives all the important information of the object and you have to get the objects coordinates. To get the important information of the object you should overwrite the toString method of java.lang.Object. Then if you want to save the strings you should use a file writer because all the informations of the area is very much to save it in the ram.
-nic- -nic-

2013/3/15

#
Would you re-add the objects by just adding a object by the data thats in the string like type x y ?
Game/maniac Game/maniac

2013/3/15

#
Is there any easier way of storing the info like in an array
Gevater_Tod4711 Gevater_Tod4711

2013/3/15

#
Well I most times use java.util.List<E> or java.util.ArrayList<E> instead of arrays because lists haven't got a static size and you can use many methods of the class. Also a ArrayIndexOutOfBoundsException is not caused that easily. But if you have to save very much data you better use a file because otherwhise the ram Greenfoot uses will not be enought. You would have to run a very long time in one direction to cause a OutOfMemoryError but this could be the case.
danpost danpost

2013/3/15

#
@Game/maniac, I have created a scenario with a bounded world that appears like an unbounded side-scrolling world. It builds uncharted territories as they come into view that remain forever unchanged. I will post it if you wish to take a look. It is not finished as far as having scrollable objects moved or removed, but the idea is there. I will continue to build on it. I did get a chance to document it a bit also.
Game/maniac Game/maniac

2013/3/15

#
cool I would love to look at it when you post it
Game/maniac Game/maniac

2013/3/15

#
@Gevater_Tod4711 I could make it so the world size is limited
There are more replies on the next page.
1
2