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

2012/12/31

Quick Question

1
2
comandodude101 comandodude101

2012/12/31

#
OK I have decided I am doing a space game but I have a question. How would I make an actor move up the screen without turning? Down? I will be using the up and down keys to move.
comandodude101 comandodude101

2012/12/31

#
Also, if I have a large map and it needs scrolling how do I make the game auto stay with where the space ship is?
danpost danpost

2012/12/31

#
Use keypress detection (see 'Greenfoot' class API) and comparison of limits (high and low values) to the y-coordinate of the object's location (see 'Actor' class API) to control the movement coded in the 'act' method of the aforementioned 'actor' class. After trying to put some code together, if you are still having problems, post what code you have that you need help on.
comandodude101 comandodude101

2012/12/31

#
I lost you on "(see 'Greenfoot' class API)". Could you possibly give me an example code?
comandodude101 comandodude101

2012/12/31

#
Sorry I'm new :p
danpost danpost

2012/12/31

#
Near the top of this webpage in the green banner, there is a link to 'Documentation'. The top section on the right of the new page, you can click on 'online' to go to the APIs which show what methods are available in each available class in the 'greenfoot' package (made available by the 'import greenfoot.*;' statement at the top of each class' code). You can search through these APIs to determine which methods would be useful to accomplish your goal. Scrolling is not something that should be tackled by someone with little experience in programming. However, there are some demos and support classes available on the site that may come in handy for that purpose. Some are included within my Demos collection and my Support Classes collection.
comandodude101 comandodude101

2012/12/31

#
Well, if I should not use scrolling, how do you suggest I make my map larger?
danpost danpost

2012/12/31

#
I did not say you should not use scrolling. I was suggesting that you look over some code with scrolling in it, try to understand what it does before trying to implement your own scrolling; or use a scrolling support class for your world. Without knowing the particulars of your scenario, I could not say what possible complications might arise. Also, you did not say whether it would be vertically limited or infinite; but because you say you are using a map, my guess is limited. Using my 'Scrolling SuperWorld' support class might be the way to go.
comandodude101 comandodude101

2012/12/31

#
Where could I find that?
comandodude101 comandodude101

2012/12/31

#
I found it but how would I implement that into my game? Could you tell me the code?
danpost danpost

2012/12/31

#
Open the class code for 'SWorld' and follow the instructions.
comandodude101 comandodude101

2012/12/31

#
How do I open the class code? Srry Im quite new
comandodude101 comandodude101

2012/12/31

#
Let me clear things up about the game. I have everything working fine, its just the map is to large to fit on the screen. So to see the rest of the map, you have to scroll. So, ingame as you control your actor, if it goes to the section of the map that you must scroll to, you must scroll along the screen as you play. So what I want is that in automatically scrolls for you as you play. But I don't know the code for that. If you could give me it, that would be amazing and I would give you credit when I release the game.
Kyle273 Kyle273

2012/12/31

#
First of all, are you scrolling only horizontally, or vertically as well? One way you can think about it is moving the world around the player. So when you press Left, everything moves right. If you want something more advanced, feel free to take stuff from my project. (http://www.greenfoot.org/scenarios/6857) You'll find the relevant code in the RelativeActor, PlatformingWorld, and Camera classes.
danpost danpost

2012/12/31

#
Download my 'Scrolling SuperWorld' scenario and copy/paste the complete 'SWorld' class code into a new sub-class of World (replacing anything created in that new world). Then make your original world 'extend SWorld' instead of 'extend World'. Open up the code for the 'SWorld' class and complete the directions given there. The movement code for your hero should not be changed; but once you 'setMainActor' your hero in 'SWorld', the scrolling should work. Also, once you 'setScrollingBackground' your background image, it should scroll, too. Once the scrolling is working, please 'like' my scenario.
There are more replies on the next page.
1
2