Yes here I go again, stuck! Damn I wish I had more understanding of C++ so I could just figure it all out by myself using the docs of which I wished each and everyone had a simple example on the top the “Class Reference” page.
My first JUCE project a game is coming along fine, I have added sound effects, and now need simple keyboard input to allow 1-2 players to control a graphics shape.
I started an Audio Application from Projucer. I have the main.cpp mostly left as is, and keeping everything in the MainComponent cpp and header files.
I header I got;
class MainComponent : public AudioAppComponent,
public HighResolutionTimer,
public ChangeListener,
public MixerAudioSource,
public KeyListener
{
public:
//==============================================================================
MainComponent();
~MainComponent();
//==============================================================================
bool keyPressed(const KeyPress& k, Component* c) override;
...
and in cpp I got;
MainComponent::MainComponent()
{
...
addKeyListener(this);
setWantsKeyboardFocus(true);
grabKeyboardFocus();
}
and further down I got;
bool MainComponent::keyPressed(const KeyPress& k, Component* c)
{
if (k.getTextCharacter() == 'x') {
// Update variable determining players horizontal position on screen
x -= 1;
}
return false;
}
My project compiles fine, but it seems keyPressed is never reached. Perhaps addKeyListener(this)
needs to go in main.cpp but I can’t figure out how exactly to do that.