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

2012/10/23

Scroll world problem

1
2
3
treinentom treinentom

2012/10/23

#
Hi guys, We're experiencing a rather large sized problem. We're creating a game for a school project in which we want the player to move around while the world moves along. We've decided to implement the "Scrolling world Demo" scrollworld class. It compiles and all, but the new background is white instead of the declared image. Here are the ScrollWorld setnewbackground function and the usage of the setnewbackground function in our world-class. setNewBackground function:
public void setNewBackground(GreenfootImage background)
    {
        GreenfootImage back = background;
        
        bigBackground.clear();
        bigBackground.drawImage(back, 0,0);
        bigBackground.drawImage(back, width,0);
        bigBackground.drawImage(back, 0,height);
        bigBackground.drawImage(back, width,height);
        
        back.drawImage(bigBackground, scrollPosX, scrollPosY);
    }
And our implementation:
GreenfootImage lvl1 = new GreenfootImage("lvl1.png");
            setNewBackground(lvl1);
            bestandsnaam = "upfrombelow";
Thanks, Tom
danpost danpost

2012/10/23

#
In the setNewBackground(GreenfootImage) method:
// instead of line 5 being
bigBackground.clear();
// try
bigBackground = new GreenfootImage(bigBackground.getWidth(), bigBackground.getHeight());
SPower SPower

2012/10/23

#
I'm the creator of that demo, so I should be able to help you. Are you putting your given code in your constructor, before you changed the location of the camera?
danpost danpost

2012/10/23

#
If the background is totally white, then:
// at the top of the class
import java.awt.Color;
// after creating new image
bigBackground.setColor(Color.white);
bigBackground.fill();
treinentom treinentom

2012/10/23

#
Well the only difference from the original code is that we're using a custom background. And if we're using the setNewBackground() funtion, then it doesn't change the background. Do you need more lines from our code?
SPower SPower

2012/10/23

#
@danpost The problem is that is it white, not that it has to be white :)
SPower SPower

2012/10/23

#
@treinentom Well, you could email the scenario to me: svnigte@gmail.com
danpost danpost

2012/10/23

#
How about adding a 'setBackgound(back);' statement at the end of the method
SPower SPower

2012/10/23

#
@danpost It lookslike you don't know the API of my Scroll world scenario. Take a look at it to learn more :)
danpost danpost

2012/10/23

#
I guess not. sorry.
SPower SPower

2012/10/23

#
@treintom Just realized you're using an old version. Please download the new one here.
treinentom treinentom

2012/10/23

#
Oh yeah, thanks, I will try that one! There is an problem with mailing, our project is 122MB... ;p
treinentom treinentom

2012/10/23

#
Well, the new version fixed the backgroundbug:) But we have a new problem! And that is that for some reason the camera starts on the top left instead of the position of the camera follower. O, and another question, do you speak Dutch? That would make the conversation much easier!:)
SPower SPower

2012/10/23

#
Ja, ik spreek nederlands :) De camera's locatie begint inderdaad in de linker bovenkant, maar ik denk dat je cameraFollowers niet helemaal begrijpt. Als je een ScrollActor toevoegt als een camera follower (met de addCameraFollower methode), dan volgt dat object de camera als die beweegt (door bijvoorbeeld de setCameraLocation of de moveCamera methode). Maar, als je de begin positie van de camera niet goed vindt, dan kan je die altijd veranderen door de methode setCameraLocation.
treinentom treinentom

2012/10/23

#
Aah okee. Maar ik heb een Actor toegevoegd (die kan bewegen dmv de pijltjestoetsen) met de addCameraFollower methode. Probleem is dus dat de camera daar niet start, en ook niet beweegt als ik het poppetje bestuur. Code van de actor:
if(Greenfoot.isKeyDown("d"))
        {
           setRotation(0);
           // move();
           // move();
           getWorld().moveCameraForward(MOVE_AMOUNT);
        }
        if(Greenfoot.isKeyDown("a"))
        {
            setRotation(180);
            //move();
            //move();
            setRotation(0);
            getWorld().moveCameraForward(-MOVE_AMOUNT);
         }      
met een waarde van 5 voor MOVE_AMOUNT. Ook heb ik een tweede vraag, en dat is dat ons mannetje ook moet springen, de springfunctie is gemaakt, maar hoe laat ik de camera die beweging volgen? Dank!
There are more replies on the next page.
1
2
3