[英]I'd like to select an Image View with one click and then add a duplicated image view to another view with a second click.
For our purposes, let's think of it as a chess game.出于我们的目的,让我们将其视为一种国际象棋游戏。 So I touch the queen and click it, then I touch the square that I'd like to move the queen to and the queen moves to that square.所以我触摸皇后并点击它,然后我触摸我想要将皇后移动到的方格,然后皇后移动到那个方格。
I think this is a pretty simple task, but I've searched high and low for an answer but yet to find one.我认为这是一项非常简单的任务,但我已经四处寻找答案,但还没有找到。
Original I was using an OnTouchListener and Drag and Drop, but it will work much better with OnClick so that the user clicks twice to move the object.原来我使用的是 OnTouchListener 和拖放,但它会更好地与 OnClick 一起使用,以便用户单击两次以移动对象。 (I think) (我认为)
Thanks for the help.谢谢您的帮助。
Setup an OnClickListener and a variable to hold the selected field.设置一个 OnClickListener 和一个变量来保存所选字段。 onClick, check if there is already a field selected, if not, store the clicked field in the variable. onClick,检查是否已经有选择的字段,如果没有,将点击的字段存储在变量中。 If there is already a selected field stored, move the piece from the stored field to the clicked field and clear the variable to allow a new move.如果已经存储了一个选定的字段,将块从存储的字段移动到单击的字段并清除变量以允许新的移动。 You can apply your game logic/rules in the second branch too.您也可以在第二个分支中应用您的游戏逻辑/规则。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.