gpt4 book ai didi

java - 我想放置一个触摸事件来开始我的游戏

转载 作者:太空宇宙 更新时间:2023-11-04 13:34:13 25 4
gpt4 key购买 nike

有人知道我应该使用什么代码来让我的 Android 游戏在触摸事件上启动吗?我尝试查看教程,但我不明白,因为我不习惯 Java。

public boolean onTouchEvent(MotionEvent) {
startgame;
return false;
}

XML:

<RelativeLayout xmlns:android="schemas.android.com/apk/res/android"; 
xmlns:tools="schemas.android.com/tools";
android:layout_width="match_parent" android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity" android:background="@drawable/start"
android:touchscreenBlocksFocus="false" android:id="@+id/">
</RelativeLayout>

最佳答案

如果正在运行,您可以使用 MouseListener。

import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
import javax.awt.event.*;

...

In some method-
panel.addMouseListener(new MouseListener()){
public void mouseClicked(){
//code here
}
public void mouseEntered(){
//code here
}
public void mouseExited(){
//code here
}
public void mouseReleased(){
//code here
}
public void mousePressed(){
//code here
}
}

面板是jPanel

编辑:没关系。 OP 说他正在制作一个 Android 应用程序

关于java - 我想放置一个触摸事件来开始我的游戏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31860994/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com