问题
I am trying to add a button which when pressed shares the high score of the user to the chosen app (facebook, twitter, messaging etc...)
I have been searching online and I just could not find a clear tutorial on how to do this. It may be because I am not so familiar with the terms such as bindings etc.. so I cannot understand these advanced tutorials. Can anyone explain clearly how I could do this?
Thanks!
p.s it would be great for the share button to work for both android and iOS
回答1:
For Facebook, check out gdx-facebook.
It's a cool project that integrates libgdx
with Facebook's API. I discovered it recently, and so far so good.
Please note: There seems to be some gradle
issues with this project when using Eclipse IDE. I've been using it with Android Studio, and it's working fine.
回答2:
You'll need to have a binding on the user interacting with the button which uses the API of the corresponding service to make a post. It's sufficiently complicated and there are so many ways of doing it that I don't suspect you'll find any one answer to this problem.
The basic part of reacting on a tap or a click will look something like this:
ClickListener shareFacebook = new ClickListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
//Interacting with the facebook API here
}
}
shareButton.addListener(shareFacebook)
In this example, the ClickListener is a listener-type object which will react to the following events happening: enter, exit, touchDown, touchDrag, and touchUp. The binding is the function which we define inside the listener. So if we define a function for touchDown, then whenever someone touches or clicks on the the entity we attach this to, the function we define there will run.
Similarly for the other events: enter on the mouse moving into the element's clickable region, exit on the mouse moving out of the element's clickable region, touchDrag on the mouse moving while being pressed, and touchUp on the mouse being released.
来源:https://stackoverflow.com/questions/32673189/adding-share-button-to-libgdx-for-android-and-ios