سؤال

My full code here

I'm learning Android development and I'm trying to create a simple word-search game. First, I created a LetterTile class, it represents one letter on the screen and this class have the method to draw itself.

Then I created a LetterMap class, which is a matrix of LetterTile (if we use LetterMap(6, 6) it will draw on screen a matrix 6x6 of LetterTile).

Now what I want to do is, when I touch one of the LetterTile object, I can do something with it. At this moment, I can't do that because in the MainGamePanel I initialize the LetterMap object, not LetterTile object.

You can see in my code that if I initialize LetterTile object, I just use the onTouchEvent to handle the problem, but now I don't know how to do with the LetterMap

Did I do something wrong? Or my approach to this game is not correct?

Any help would be appreciated. Thanks!

هل كانت مفيدة؟

المحلول

Sorry I didn't compile your code before. Now I did this and looked a little more detail in it.

  1. When I uncomment your onTouchEvent of your MainPanel and add a LetterTile I can't control the touchEvent as you describe it (I set a breakpoint to the onTouchEvent of you LetterTile, but the debugger doesn't jump to it).

  2. I think you have to deal this scenario with Views. Because they give you all the methods you need and so you don't have to implement them on your own. Sorry that I can't solve your problem.

A good beginning is the android tutorial for custom views.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top