简体   繁体   English

在 java swing 中为 2d runner 游戏创建关卡

[英]creating a level for 2d runner game in java swing

I'm making a 2D runner game, I made my frames with我正在制作一个 2D 跑步游戏,我制作了我的框架

public class MainMenu2 {
    MainMenu2() throws IOException{
        JFrame Main_Menu = new JFrame("Main Menu");
        Main_Menu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        final int widthScreen = screenSize.width;
        final int heightScreen = screenSize.height;

every time I created a class I made the JFrames like that every single time, without re-calling the class or whatever.每次我创建一个类时,我每次都会像这样创建 JFrame,而无需重新调用该类或其他任何东西。 I completed the menu with buttons that connect to other classes but I need to make a level now.我用连接到其他类的按钮完成了菜单,但我现在需要制作一个关卡。 It consists on a player moving right,left and up, collisions with platforms and enemies.它包括一个玩家向右、向左和向上移动,与平台和敌人发生碰撞。 Kinda like super mario.有点像超级马里奥。 I'm a beginner in Java so I haven't found any examples that follow my structure, since they all base off from 1 JFrame.我是 Java 的初学者,所以我没有找到任何遵循我的结构的示例,因为它们都基于 1 JFrame。 I don't know how to make a tile and connect it to a class' JFrame.我不知道如何制作瓷砖并将其连接到类的 JFrame。 I'm lost I need help, thank you.我迷路了,需要帮助,谢谢。

Sound like you're confused in swing hierarchy.听起来你对摆动层次结构感到困惑。

You can use Jpanel in which You can set All tiles and then set Jpanel into Jframe.您可以使用 Jpanel,其中您可以设置所有磁贴,然后将 Jpanel 设置为 Jframe。
In short from child to parent :: Tiles --> Jpanel --> Jframe.简而言之,从孩子到父母 :: Tiles --> Jpanel --> Jframe。 (Refer the one simple example : https://coderanch.com/t/633503/java/Tiled-Based-Map-Game-Java ). (参考一个简单的例子: https : //coderanch.com/t/633503/java/Tiled-Based-Map-Game-Java )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM