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

2013/6/3

Trying do 2 lvl in me game

kexsas321 kexsas321

2013/6/3

#
when i in lvl2 edito entering { Greenfoot.setWorld(new Level2()); } in okey no syntaks error but level 2 is not vorking and java error java.lang.OutOfMemoryError: Java heap space at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:75) at java.awt.image.Raster.createPackedRaster(Raster.java:470) at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032) at java.awt.GraphicsConfiguration.createCompatibleImage(GraphicsConfiguration.java:186) at greenfoot.util.GraphicsUtilities.createCompatibleTranslucentImage(GraphicsUtilities.java:179) at greenfoot.GreenfootImage.<init>(GreenfootImage.java:131) at greenfoot.World.setBackground(World.java:156) at greenfoot.World.<init>(World.java:124) at greenfoot.World.<init>(World.java:104) at Level2.<init>(Level2.java:18) at Level2.<init>(Level2.java:21) at Level2.<init>(Level2.java:21) at Level2.<init>(Level2.java:21) at Level2.<init>(Level2.java:21) at Level2.<init>(Level2.java:21) at Level2.<init>(Level2.java:21) at Level2.<init>(Level2.java:21) at Level2.<init>(Level2.java:21) at Level2.<init>(Level2.java:21) at Level2.<init>(Level2.java:21) at Level2.<init>(Level2.java:21) at Level2.<init>(Level2.java:21) at Level2.<init>(Level2.java:21) at Level2.<init>(Level2.java:21) at Level2.<init>(Level2.java:21) at Level2.<init>(Level2.java:21) at Level2.<init>(Level2.java:21) at Level2.<init>(Level2.java:21) at Level2.<init>(Level2.java:21) at Level2.<init>(Level2.java:21) at Level2.<init>(Level2.java:21) at Level2.<init>(Level2.java:21) what i need do? maby 2 lvl work on greenfoot 2.1.0 me version 2.3.0
welleid welleid

2013/6/3

#
It's simple In fact, you create level 2 from level 2, which is a huge glitch in the universe and bugging the matrix. Perhaps you should put : Greenfoot.setWorld(new Level2()); in level 1 ?
danpost danpost

2013/6/3

#
The problem is not in the way it is called. It is something in the coding of the level 2 constructor. Please show the code for your Level2 world -- at least the block of code that consists of lines 18 through 21 of the class.
kexsas321 kexsas321

2013/6/4

#
who can put in youtube how to do it or i can share the game and somh1 plz fix it p.s. me level1 code 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 { /** * Constructor for objects of class Level1. * */ public Level1() { super(600, 400, 1); prepare(); { Greenfoot.setWorld(new Level2()); } } /** * Prepare the world for the start of the program. That is: create the initial * objects and add them to the world. */ private void prepare() { ground ground = new ground(); addObject(ground, 65, 395); ground ground2 = new ground(); addObject(ground2, 227, 356); ground.setLocation(58, 341); ground2.setLocation(210, 364); ground ground3 = new ground(); addObject(ground3, 367, 348); ground ground4 = new ground(); addObject(ground4, 488, 302); ground ground5 = new ground(); addObject(ground5, 378, 241); ground ground6 = new ground(); addObject(ground6, 269, 198); ground ground7 = new ground(); addObject(ground7, 147, 151); ground ground8 = new ground(); addObject(ground8, 71, 100); ground ground9 = new ground(); addObject(ground9, 256, 81); ground ground10 = new ground(); addObject(ground10, 378, 88); ground ground11 = new ground(); addObject(ground11, 515, 97); ground10.setLocation(371, 80); ground11.setLocation(485, 79); ground ground12 = new ground(); addObject(ground12, 533, 147); ground12.setLocation(533, 147); ground12.setLocation(533, 147); ground12.setLocation(533, 147); ground12.setLocation(533, 147); ground12.setLocation(589, 81); ground12.setLocation(599, 79); Player2 player2 = new Player2(); addObject(player2, 50, 313); } } Level2 code import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Level2 here. * * @author (your name) * @version (a version number or a date) */ public class Level2 extends World { /** * Constructor for objects of class Level2. * */ public Level2() { super(600, 400, 1); prepare(); } /** * Prepare the world for the start of the program. That is: create the initial * objects and add them to the world. */ private void prepare() { ground ground = new ground(); addObject(ground, 116, 373); ground ground2 = new ground(); addObject(ground2, 337, 270); ground ground3 = new ground(); addObject(ground3, 495, 199); Player2 player2 = new Player2(); addObject(player2, 102, 319); ground2.setLocation(288, 316); ground3.setLocation(444, 250); } } Actor code: import greenfoot.*; public class Player2 extends Actor { private int vSpeed = 3; private int acceleration = 1; private int jumpSpeed = 10; private boolean goingLeft = true; GreenfootImage gr = getImage(); private int count = 1; public void act() { checkKeys(); checkFall(); count++; } public void checkKeys() { if(Greenfoot.isKeyDown("left")) { if(goingLeft) { gr.mirrorHorizontally(); goingLeft=false; } this.setLocation(getX()-3,getY()); } if(Greenfoot.isKeyDown("right")) { if(!goingLeft) { gr.mirrorHorizontally(); goingLeft=true; } this.setLocation(getX()+3,getY()); } if(Greenfoot.isKeyDown("space")) { jump(); } } public void checkFall() { if(onGround()) { vSpeed = 1; } else { fall(); } } public boolean onGround() { int spriteHeight = getImage().getHeight(); int yDistance = (int) (spriteHeight / 2 + 5); Actor ground = getOneObjectAtOffset(0,getImage().getHeight()/2,ground.class); if(ground == null) { return false; } else { return true; } } public void moveToGround(Actor ground) { int groundHeight = ground.getImage().getHeight(); int newY = ground.getY() - (groundHeight + getImage().getHeight())/2; setLocation(getX(), newY); } public void fall() {if(count%2==0){ if(!onGround()) { vSpeed= vSpeed + acceleration; this.setLocation(getX(), getY() + vSpeed); }} } public void jump() { if(onGround()) { jumpSpeed = -90; this.setLocation(getX(), getY() + jumpSpeed); } } private boolean verSpeed() { if(vSpeed>=1) { return true; } else { return false; } } } ground code import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class ground here. * * @author (your name) * @version (a version number or a date) */ public class ground extends Actor { /** * Act - do whatever the ground wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move(0); } }
danpost danpost

2013/6/4

#
kexsas321 wrote...
public Level1()
{    
    super(600, 400, 1); 
    prepare(); 
    {  
        Greenfoot.setWorld(new Level2());
     } 
}
It does not good to call a new world from a world that is being created unless you are going back to it. I do not think you want to 'setWorld' to Level2 from the constructor of the first world.
You need to login to post a reply.