[Solved]How to access AppState from Control

Use Case:
Pong Scoring
I have a GameAppState that extends AbstractAppState
It has two variables (int) to keep score of playerOneScore and playerTwoScore along with get and setters

I have a BallControl that extends AbstractControl

In the ball Control I am checking to see if the ball gets past one of the paddles
If so I want to update the value with GameAppState.setPlayerOne(GameAppState.getPlayerOne()+1)

My Question is
How do I access a AppState from a Control. Do I just keep a reference to the AppState when I create the Control or is there a better option?

Yes.

Also, yes… but it involves a proper game design that keeps the game state separate from the visualization. (ie: a rewrite of what you’ve done)

main.getStateManager().getState(GameAppState.class).setPlayerOne()

I ended up making a new GameData class and passing a reference of that from the GameAppState to the BallControl.

@thetoucher not sure what “main” represents in your code example

Thanks for the info

It,s maybe a referrence of Application.

I keep a reference to the Main class in many of my classes, then I use ‘main’ as my central access point to get to my objects.

got it thanks