How to access a field/method of the sketch from MainActivity?

edited May 2 in Android Mode

I have public void init_game() in public class colors_game extends PApplet What do I have to do to access public void init_game() from public class MainActivity? Thanks in advance.

Answers

  • @ddann88===

    what version of Android mode are you using? - What version of P5?

  • edited May 2

    @akenaton To be more precise, I have to say that I imported my project to Android Studio.

    I am using onTap() function for getting touch events but on some devices there is a big failure rate (some touches are not taken into account, sometimes you have to touch 2-3 times somewhere). On my tablet it works fine, but not also on my smartphone.

    Because of that, I was thinking to use the standard "public boolean onTouchEvent" in MainActivity, where I would call a method of my sketch.

    I don't know the versions right now, but if necessary I will tell you soon.

  • edited May 2 Answer ✓

    init_game() is a method member of class colors_game.

    In order to access that member, the variable holding the reference of an object of datatype colors_game needs to be of datatype colors_game too.

    Alternatively, you can temporarily turn that variable into datatype colors_game using the (cast) operator: ( (colors_game) variable ).init_game();

  • It works, I am grateful for your help.

Sign In or Register to comment.