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)
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.