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

2013/3/12

removeObject troubles

CreepZilla CreepZilla

2013/3/12

#
I am currently creating a two player game for a school project. For my game I am trying to make it so that each player is dependent on the other. eg, Player 1 pulling lever. to raise platform for Player2 I am stuck on a remove object code: public void PanelOne() { Actor panel1; panel1 = getOneObjectAtOffset(0,0, FloorPanel.class); if(panel1 != null) { Actor block; block = getOneObjectAtOffset(0,0, Map_One_Block.class); World world; world = getWorld(); world.removeObject(block); panel1.setImage("FloorPanel2.png"); } } "panel1" is changing its image - to show its pressed however the actor "block" is not being removed. Can anyone help? PanelOne() is being called from a subclass in it's Act() Method.
davmac davmac

2013/3/12

#
We'd probably need to see more code with a more complete explanation of what you want to happen. It may be that your actor isn't close enough to the block you want removed, so 'getOneObjectAtOffset(0, 0, Map_One_Block.class)' isn't finding it.
CreepZilla CreepZilla

2013/3/14

#
It not being close enough might be it they are on opposite sides of the world. This is the code for the character that presses the button (panel) private int right = 0; private int left = 0; private int up = 0; private int down = 0; public void act() { TopCollision(); BottomCollision(); PanelOne(); if(Greenfoot.isKeyDown("right")) { if(right==0) { this.setImage("Player1_Right2.png"); this.setLocation(this.getX() + 3, this.getY()); right++; }else{ this.setImage("Player1_Right1.png"); this.setLocation(this.getX() + 3, this.getY()); right--; } } //Movement to the left, switch image and move. if(Greenfoot.isKeyDown("left")) { if(left==0) { this.setImage("Player1_Left2.png"); this.setLocation(this.getX() - 3, this.getY()); left++; }else { this.setImage("Player1_Left1.png"); this.setLocation(this.getX() - 3, this.getY()); left--; } } if(Greenfoot.isKeyDown("up")) { if(up==0) { this.setImage("Player1_Back1.png"); this.setLocation(this.getX(), this.getY() - 3); up++; }else { this.setImage("Player1_Back2.png"); this.setLocation(this.getX(), this.getY() - 3); up--; } } if(Greenfoot.isKeyDown("down")) { if(down==0) { this.setImage("Player1_Front1.png"); this.setLocation(this.getX(), this.getY() + 3); down++; }else { this.setImage("Player1_Front2.png"); this.setLocation(this.getX(), this.getY() + 3); down--; } } } /////////////// The code at start of discussion is for the block disappearing when panel is pressed
CreepZilla CreepZilla

2013/3/14

#
my display picture at the moment is the world, The blue circle at top is panel, and brown plank at bottom is 'block'
danpost danpost

2013/3/14

#
To remove ALL plank objects from the world, you can use:
World world;
world = getWorld();
world.removeObjects(world.getObjects(Map_One_Block.class));
CreepZilla CreepZilla

2013/3/14

#
yes that worked thanks :)
You need to login to post a reply.