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

2013/5/11

Counter

Hawx_ Hawx_

2013/5/11

#
Hi , I need a code for a counter that goes up when the player touches another actor(Helm) and that displays on the screen. I don't know how to go about this. Please help. Hawx_ Edit: Classes - World - Road Actor - Player : Player Object : Helm Counter : Counter
GreenGoo GreenGoo

2013/5/11

#
This is in the world: int timesTouched = 0; addObject(new Score(), 90, 10); This is an object called Score: import greenfoot.*; import java.awt.Color; public class Score extends Actor { public void act() { setImage(new GreenfootImage("Enemies remaining : "+ (((MyWorld) getWorld()).timesTouched), 22, Color.WHITE, null)); } } This is a method in the one of the objects being touched: Actor shipLaser = getOneIntersectingObject(ShipLaser.class); if (shipLaser != null) { getWorld().removeObject(shipLaser); ((MyWorld) getWorld()).timesTouched++; Or something like that.
Hawx_ Hawx_

2013/5/11

#
Thanks , works perfectly!
You need to login to post a reply.