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

2016/8/18

code for pause world

1
2
danpost danpost

2016/8/22

#
loxtn10 wrote...
Nullpointerexception when i click x. the current code for when x is clicked and near the shop the show becomes 1;
 public void act() 
    {
        getImage().setTransparency(0);
        show = 0;
        if((isTouching(meh.class) || isTouching(meh2.class) ) && ("x".equals (Greenfoot.getKey())))
        {
            Greenfoot.getKey();
            show = 1;
        }
        
    } 
Remove line 7. Then change line 5 to this:
if((isTouching(meh.class) || isTouching(meh2.class) && Greenfoot.isKeyDown ("x"))
after the show gets 1 value this code then happens < Code Omitted > then proceeds to thes after opening the shop. RIGHT BEFORE THE SHOP OPENS nullpointerexception happens in this code. I've already cleared the Greenfoot.getKey() which means no more registered key. but nullpointerexception happens < Code Omitted >
Remove all 'Greenfoot.getKey()' operations and comparisons in the srrfc class.
loxtn10 loxtn10

2016/8/22

#
I didn't know that we made a weak program. i'm afraid I don't have enough time to remake the game. Thanks for letting me know that it makes the program more complex and issue-prone...ok thanks a lot.... Currently I won't be able to change the code. I'm on my highschool. Tips noted though.
Osares10 Osares10

2016/8/22

#
https://www.raspberrypi.org/forums/viewtopic.php?f=36&t=18916
loxtn10 loxtn10

2016/8/22

#
already did this to the srrfc,
danpost wrote...
Remove all 'Greenfoot.getKey()' operations and comparisons in the srrfc class.
the problem then is on the shopp triggerer. still error, I did what you said
Super_Hippo Super_Hippo

2016/8/22

#
You didn't change the line as he suggested. You still have the getKey method there.
loxtn10 loxtn10

2016/8/22

#
OK NEVERMIND THIS, It's already fixed,
loxtn10 wrote...
already did this to the srrfc,
danpost wrote...
Remove all 'Greenfoot.getKey()' operations and comparisons in the srrfc class.
the problem then is on the shopp triggerer. still error, I did what you said
I changed the getkey here to isKeyDown() Now the problem is not anymore an error but a bug, when I click x since the code is iskeydown() the one press of x gets to be registered too fast that it counts almost 10 or more in just a press, the shop and the scene then interchange very fast... Also I would like the world to not really interchange but can I put the world atop of the other so that I can sneak a pic of my progress but the gameworld (the scene) then pauses. Also how am I gonna change the background of this image to transaparent ?
 setImage (new GreenfootImage ("" + srrfc.ammo,30,Color.WHITE,Color.BLACK));//CAN I TURN THIS Color.BLACK PART INTO TRANSPARENT ?
danpost danpost

2016/8/22

#
loxtn10 wrote...
when I click x since the code is iskeydown() the one press of x gets to be registered too fast that it counts almost 10 or more in just a press, the shop and the scene then interchange very fast...
Use different keys for going to and returning from the shop (maybe use the "escape" key for returning).
Also I would like the world to not really interchange but can I put the world atop of the other so that I can sneak a pic of my progress but the gameworld (the scene) then pauses.
Maybe you can take a look at and utilize some of the code from my Pause World Class scenario. Or, you could use my PIP Actor Class to show the game world in during the active state of the shop world. I was thinking you could create a PIP Actor object for the game world and just draw its image onto the background of the shop world.
Also how am I gonna change the background of this image to transaparent ?
 setImage (new GreenfootImage ("" + srrfc.ammo,30,Color.WHITE,Color.BLACK));//CAN I TURN THIS Color.BLACK PART INTO TRANSPARENT ?
Simple -- use 'null' instead of 'Color.BLACK'. The default drawing colors for a new image are black text on transparent background. Using 'null' for either color parameters is equivalent to using its default color as the argument.
loxtn10 loxtn10

2016/8/22

#
danpost wrote...
Use different keys for going to and returning from the shop (maybe use the "escape" key for returning)
it still shifts I don't know why. the code in the shop world
if (Greenfoot.isKeyDown ("right"))
        {
            ammo ++;
        }
        else if (Greenfoot.isKeyDown ("left"))
        {
            if( ammo != 0 ) ammo --;
        }
        else if (Greenfoot.isKeyDown ("Escape"))
        {
            if (buy)
            {
                coinn -= ammo;
                ammoo += ammo;
                ammo = 0;
                Greenfoot.setWorld(gameWorld);
            }
            else{Greenfoot.setWorld(gameWorld);}
        }
The code for trigger shop is:
public static int show = 0;
    public void act() 
    {
        getImage().setTransparency(0);
        show = 0;
        if((isTouching(meh.class) || isTouching(meh2.class) ) && Greenfoot.isKeyDown ("x"))
        {
            show = 1;
        }
        
    } 
Super_Hippo Super_Hippo

2016/8/22

#
Couldn't you change the world like this without using the show variable to trigger the code in the world class?
Greenfoot.setWorld(new srrffc(getWorld()));
If you ask me, you are using too many static variables.
loxtn10 loxtn10

2016/8/22

#
I started the project knowing only few things. I didnt know such tricks tp simplify my ideas. You see I learn overtime. Tip noted though. Thanks ! Cx
You need to login to post a reply.
1
2