• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps pass canvas to thread

9Ate7

Newbie
Hello

I am working on a simple game, and decided to use a new thread to handle a separate part of the game. Once the onCreate method is called, it simply sets the view to the Draw class.
My programs has to following:
Draw ---> Extends View, the class that draws everything
Char ---> The player, take input do something with it, DOESN'T extend view
Sprite ---> Class to loop through bunch of pictures to create an "animation", Char has a list of sprites.

Ranged --> This class will be a thread and part of Char. I would like this class to handle its own animation, it has its own variable for sprite.

I am trying to get the Ranged class to draw its own animation on the Canvas when i call the Ranged.start (after creating a new thread of this class) method in the Char.

The problem is i cannot pass in the canvas, it crashes. If i declare public canvas and try drawing to it, it crashes.

How can i draw on the same canvas as the Char class in a completely different thread.
 
Back
Top Bottom