I am building a playing card game with LibGdx. I am new to libgdx and have read all the tutorials and the DragAndDrop Test class of LibGdx but I cannot figure out how to implement dragAndDrop for my game?
The cards in the user hand are sources and when dragged to the table by the user and when dropped on the appropriate card on the table a calculation has to be done according to cards values if that card is a valid target and if not the dragged card should be added to the table cards and become a new target. The cards are all images. This is what I have so far but when run the source card slides to right instead of being dragged.
Can anyone please help me with this?
DragAndDrop dragNdrop = new DragAndDrop();
dragNdrop.addSource(new Source(userCard1)
{
@Override
public Payload dragStart(InputEvent event, float x,
float y,int pointer)
{
Payload payload = new Payload();
payload.setObject(userCard1);
payload.setDragActor(userCard1);
if(userhand.getCard(0).getValue() +
maidaanhand.getCard(0).getValue() == 11)
{
payload.setValidDragActor(maidaanCard1);
}
return payload;
}
});
dragNdrop.addTarget(new Target(maidaanCard1)
{
@Override
public boolean drag(Source source, Payload payload,
float x, float y, int pointer)
{
getActor();
return true;
}
@Override
public void drop(Source source, Payload payload,
float x, float y, int pointer)
{
if(userhand.getCard(0).getValue() +
maidaanhand.getCard(0).getValue() == 11)
{
userScore = 10;
}
}
});
Aucun commentaire:
Enregistrer un commentaire