so i have an actor array in the MyWorld class and i used a for loop to add actors into the world. now, in a totally separate actor class, i'm trying to have it where when i click on one of these objects, a prompt shows up asking how many objects the player wants. I've tried so many different methods of defining the object to be clicked, half of which compile right, yet absolutely nothing happens when i click on them. Am i missing some important step or am i just going about this all wrong?
This is the code from MyWorld where the array is
and this is whats in the shopping cart class, where everything is being put together to EVENTUALLY get a total cost, but if i cant get clicks to work thats gonna be far from possible
public class MyWorld extends greenfoot.World { public static Actor[] items; /** * Constructor for objects of class MyWorld. * */ public MyWorld() { // Create a new world with 10x8 cells with a cell size of 60x60 pixels. super(10, 8, 60); //actor array Actor[] items = new Actor[10]; items[0] = new burger(); items[1] = new fries(); items[2] = new pizza(); //price array double[]prices= {3.69,1.55,2.99}; //for loop for world display for(int i=0; i<3; i++) { showText("$"+prices[i], 1,(i+1)); addObject(items[i], 0,(i+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() { pay pay = new pay(); addObject(pay,1,6); } }
public class shoppingCart extends Actor { int quantity = 0; double totalPrice = 0; Actor burger = MyWorld.items[0]; Actor fries = MyWorld.items[1]; Actor pizza = MyWorld.items[2]; /** * Act - do whatever the shoppingCart wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { Greenfoot.getMouseInfo(); if(Greenfoot.mouseClicked(burger)) { quantity =Integer.parseInt(Greenfoot.ask("Enter quantity:")); } } }