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

2016/11/29

Game works while in Greenfoot but not uploaded or as .jar

1
2
MJBelmer MJBelmer

2016/12/1

#
Okay drawing the image seems like a great idea, two questions on that though. How can I Center the image that is being drawn or even when I'm setting a new world background how can I get it to be centered in the window when it's smaller than the largest world, rather than always appearing in the top left corner? Also how can I clear the background of a world that isn't active anymore so it's not visible behind the new world?
danpost danpost

2016/12/1

#
MJBelmer wrote...
How can I Center the image that is being drawn or even when I'm setting a new world background how can I get it to be centered in the window when it's smaller than the largest world, rather than always appearing in the top left corner? Also how can I clear the background of a world that isn't active anymore so it's not visible behind the new world?
I gave the code, not only to center the image (see line 13), but to provide a border color (for area not taken by image in world background -- see line 10), above. You should not have to worry about any part of the background of one world interfering with the background of another (one is removed before the new one becomes active).
MJBelmer MJBelmer

2016/12/2

#
Am I using this correctly? Things are not clearing and now the fireballs on the right side leave a path of their image across the area that isn't the world but still has a background on it from previous worlds.
    /**
     * Constructor for objects of class PointMessage.
     * 
     */
    public PointMessage(DragonArena da, Dragon dragon)
    {
        super(400, 300, 1);
        dragonArena = da;
        if (dragon == dragonArena.getRedDragon())
        {
            String filename = "redpoint.png";
            GreenfootImage bg = new GreenfootImage(getWidth(), getHeight());
            bg.setColor(new java.awt.Color(0, 0, 0));
            bg.fill();
            GreenfootImage img = new GreenfootImage(filename);
            bg.drawImage(img, (getWidth()-img.getWidth())/2, (getHeight()-getHeight())/2);
            setBackground(bg);
        }//end if
        if (dragon == dragonArena.getBlueDragon())
        {
            String filename = "bluepoint.png";
            GreenfootImage bg = new GreenfootImage(getWidth(), getHeight());
            bg.setColor(new java.awt.Color(0, 0, 0));
            bg.fill();
            GreenfootImage img = new GreenfootImage(filename);
            bg.drawImage(img, (getWidth()-img.getWidth())/2, (getHeight()-getHeight())/2);
            setBackground(bg);
        }//end if
    }//end PointMessage
danpost danpost

2016/12/2

#
MJBelmer wrote...
Things are not clearing and now the fireballs on the right side leave a path of their image across the area that isn't the world but still has a background on it from previous worlds.
You might be able to just change the size of the world to (800, 768) to avoid most, if not all, of that. I think the areas outside the edges of the world is a greenfoot site issue that you can do nothing about.
MJBelmer MJBelmer

2016/12/2

#
In the intro? or all of the worlds to that and keep that same code?
danpost danpost

2016/12/2

#
MJBelmer wrote...
In the intro? or all of the worlds to that and keep that same code?
You were showing the PointMessage world -- which is what I was specifically referring to in my last post. I doubt you could simply do that in some of your other worlds.
MJBelmer MJBelmer

2016/12/2

#
Okay yes that makes sense. I was pretty sure I used the code correctly for PointMessage and it centers it horizontally but for some reason not vertically. Also if you take my scenario and run it as a jar you'll notice the issue I'm having with previous worlds not being cleared. You said when new worlds are set they are automatically cleared? It seems not to be doing that for me for some odd reason. Its not a huge deal but aesthetically it bother me haha. This project is already well past requirements for class but I have a desire to make things perfect.
danpost danpost

2016/12/2

#
MJBelmer wrote...
it centers it horizontally but for some reason not vertically.
Sorry, line 16 should read:
bg.drawImage(img, (getWidth()-img.getWidth())/2, (getHeight()-img.getHeight())/2);
Oh, my line 13 shows correctly; but your lines 16 and 26 do not coincide with it.
if you take my scenario and run it as a jar you'll notice the issue I'm having with previous worlds not being cleared. You said when new worlds are set they are automatically cleared? It seems not to be doing that for me for some odd reason.
I ran a test jar file with my version of greenfoot (USB 2.3.0 for Windows -- which I am quite content with) and there are no issues with residual images (there are none).
MJBelmer MJBelmer

2016/12/2

#
Ahhh I should have noticed it needed the img. part! Perfect, not sure why my version of JRE is giving me residual images i'll check for an update.
danpost danpost

2016/12/2

#
MJBelmer wrote...
Ahhh I should have noticed it needed the img. part! Perfect, not sure why my version of JRE is giving me residual images i'll check for an update.
I don't think it is a java or JRE issue. It is probably a issue in newer version(s) of BlueJ or Greenfoot.
danpost danpost

2016/12/2

#
I do not see why you cannot make all the worlds the same size. You can scale whatever background image needs to fit or draw it onto a larger background as you have been doing.
You need to login to post a reply.
1
2