Hey Everyone, I'm new to the framework. I was wondering how I could get a game working with a second controller. I'm pretty certain I've only seen examples that work with only the keyboard or the game bad. If I could get something really simple going like getting the left mouse button to fire in Demo 2 (the asteroids demo), that would be great.
Thanks, Joey |
Just take a look at the Boy/controllers
Specifically for the mouse, you need to repeat everything that is done with KeyboardListener now with MouseListener, in Demo2.cpp e Demo2.h
Just to test it out, I used this simplified method for mouseButtonDown, based on the keyDown method:
void Demo2::mouseButtonDown(Boy::Mouse *mouse, Boy::Mouse::Button button, int clickCount)<br />{<br /><br /> // when spacebar is hit and the gun is armed:<br /> if (!mGameOver && mShip!=NULL)<br /> {<br /> // add a bullet:<br /> BoyLib::Vector2 vel = rotate(BoyLib::Vector2(0.0f,-BULLET_SPEED),-deg2rad(mShip->mRot));<br /> mBullets.push_back(new Body(BULLET, mShip->mPos.x, mShip->mPos.y, vel.x, vel.y));<br /><br /> // make a sound:<br /> Boy::Environment::playSound("SOUND_FIRE");<br /><br /> // gun is no longer armed:<br /> mGunArmed = false;<br /> }<br />}
Don't forget to "implement" the other abstract methods from MouseListener:
void Demo2::mouseMove(Boy::Mouse *mouse);<br /> void Demo2::mouseButtonUp(Boy::Mouse *mouse, Boy::Mouse::Button button);<br /> void Demo2::mouseWheel(Boy::Mouse *mouse, int wheelDelta);<br /> void Demo2::mouseEnter(Boy::Mouse *mouse);<br /> void Demo2::mouseLeave(Boy::Mouse *mouse);
I hope this helps somebody |