Hi,
I am making a simple game which involves moving a character around the screen. In my main class I have declared a member class which extends Canvas as follows:
In my main class constructor I then create an instance of myCanvas as follows:Code:public class myCanvas extends Canvas { public void paint (Graphics g) { // Paint stuff } // end paint method } // end member class myCanvas
keyCanvas = new myCanvas();
This works fine and I can issue the command keyCanvas.repaint(); to repaint the screen.
My question is this.. Is it possible to access my keyCanvas device from a subclass? For example I have created a subclass called food, which extends Thread. When this thread is started it generates a random number.
When this random number is a certain value I would like to paint a food sprite to the main display for the games hero to collect! Is it possible to access my keyCanvas directly from the food class?
Or would it be better to create a method in my food class which returns the random value to the main class and then have my main class draw the food sprite when the required random number is received?
Thanks in advance for any help,
Phil

Reply With Quote


