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

2017/3/26

How to do the Scrolling world- 2D Platformer

Jimmywow Jimmywow

2017/3/26

#
Hey so i have been looking at a lot of discussions and a lot of the scenarios have this applet tag thing so i cant see it... A scrolling world seems really complicated and I can't figure out whats wrong when I paste it in when I use some of them... I would like it so the screen would follow my main character or maybe just scroll to the right once he touches the edge. If someone could please please help me. YOU WOULD BE THE GODDAMN BEST PERSON EVER!!! thank you
danpost danpost

2017/3/26

#
Have you looked at my Scrolling Tutorial scenario? Everything you need is there somewhere (and there is a url given for the main Scroller class).
Jimmywow Jimmywow

2017/3/26

#
Yes, I have looked but i can't actually open the scenario but can go to this https://www.greenfoot.org/topics/57567/0#post_111359 im not 100% sure of what all the coding means but i have looked into your bee and baby game with the scrolling world :D The only problem now is that all of my objects that were places are gone... so if you could help me it would be SICK! Here is the code ( Yeah I would make the prepare method a bit neater.... but i don't which is which 0_0 sorry dan)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 
/**
 * Write a description of class Level1 here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class Level1 extends World
{
    public ImgScroll scroller; // scroll controller
    private Jimmy jimmy; // main actor
 
    /**
     * Constructor for objects of class Level1.
     *
     */
    public Level1()
    {   
        super(1080, 720, 1, false);
        // settings
        Greenfoot.setSpeed(63);
        setPaintOrder(GameOver.class, Jimmy.class);
        // initialize fields
        scroller = new ImgScroll(this, new GreenfootImage("Backround- Level 1.png"), 1700, 1500);
        // prepare and add actors to world
        for (int j=0; j<scroller.getScrollHeight()-100; j+=300)
            for (int i=0; i<scroller.getScrollWidth()-200; i+=300)
 
                addObject(jimmy = new Jimmy(), 60, 60);
 
    }
 
    public void act()
    {
        // exit method if game has already ended
        if (!getObjects(GameOver.class).isEmpty()) return;
 
        // run scroll engine (keeps boy in center when possible)
        scroller.scroll(getWidth()/2-jimmy.getX(), getHeight()/2-jimmy.getY());
 
    }
 
    /** prevents restarting after game over (called by greenfoot framework) */
    public void started()
    {
        if (!getObjects(GameOver.class).isEmpty()) Greenfoot.stop();
    }
 
    /**
     * Prepare the world for the start of the program.
     * That is: create the initial objects and add them to the world.
     */
    private void prepare()
    {
        Jimmy jimmy = new Jimmy();
        addObject(jimmy,7,29);
        jimmy.setLocation(7,29);
        Grizzwold grizzwold = new Grizzwold();
        addObject(grizzwold,227,616);
        grizzwold.setLocation(224,609);
 
        Ground ground = new Ground();
        addObject(ground,786,675);
        Ground ground2 = new Ground();
        addObject(ground2,893,489);
        ground.setLocation(1000,683);
        ground2.setLocation(2449,507);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3856,587);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3923,683);
        ground2.setLocation(3993,682);
        Television television = new Television();
        addObject(television,3962,601);
        television.setLocation(3959,591);
        Platform platform = new Platform();
        addObject(platform,2164,595);
        Platform platform2 = new Platform();
        addObject(platform2,2389,551);
        Platform platform3 = new Platform();
        addObject(platform3,2641,510);
        platform3.setLocation(2486,434);
        Platform platform4 = new Platform();
        addObject(platform4,2639,621);
        Platform platform5 = new Platform();
        addObject(platform5,2810,526);
        NPC npc = new NPC();
        addObject(npc,2513,376);
        NPC npc2 = new NPC();
        addObject(npc2,2173,529);
        NPC npc3 = new NPC();
        addObject(npc3,3223,570);
        NPC npc4 = new NPC();
        addObject(npc4,3496,573);
        NPC npc5 = new NPC();
        addObject(npc5,3631,352);
        npc5.setLocation(3641,608);
        npc4.setLocation(3500,606);
        npc3.setLocation(3226,604);
        npc.setLocation(2487,373);
        Deadzone deadzone = new Deadzone();
        addObject(deadzone,2004,693);
        deadzone.setLocation(2004,693);
        deadzone.setLocation(2004,693);
        deadzone.setLocation(2004,693);
        deadzone.setLocation(2004,693);
        deadzone.setLocation(2004,693);
        deadzone.setLocation(2004,693);
        deadzone.setLocation(2456,715);
        deadzone.setLocation(2456,715);
        deadzone.setLocation(2456,715);
        deadzone.setLocation(2456,715);
        deadzone.setLocation(2456,715);
        deadzone.setLocation(2456,715);
        deadzone.setLocation(2456,715);
        deadzone.setLocation(2456,715);
        deadzone.setLocation(2456,715);
        deadzone.setLocation(2456,715);
        deadzone.setLocation(2456,715);
        deadzone.setLocation(2456,715);
        deadzone.setLocation(2456,715);
        deadzone.setLocation(2456,715);
        deadzone.setLocation(2456,715);
        deadzone.setLocation(2456,715);
        deadzone.setLocation(2456,715);
        deadzone.setLocation(2456,715);
        deadzone.setLocation(2498,715);
        minionspeech minionspeech = new minionspeech();
        addObject(minionspeech,339,543);
        minionspeech.setLocation(333,536);
    }
}
Jimmywow Jimmywow

2017/3/26

#
Ok... So should i just remake the whole world? i have tried too but my actual character now duplicates and duplicates when I'm outside the world or when I'm just walking left and right.... I removed all the stuff in prepare
Super_Hippo Super_Hippo

2017/3/26

#
If Jimmy is your main actor, what you are trying to do in lines 27-30?
Jimmywow Jimmywow

2017/3/26

#
xD I'm not sure but i think i got it too work! ( I may have removed them...)
You need to login to post a reply.