Java - Creating a 2D tile map in a panel using Graphics2D Rectangles?

后端 未结 2 1935
臣服心动
臣服心动 2021-02-04 22:41

I\'m trying to simulate a battle in a really basic program, but since this is my first time with a big program in Java I\'m pretty much clueless on how to proceed. I was thinkin

2条回答
  •  迷失自我
    2021-02-04 23:15

    I think you're going about learning java the wrong way to be honest. If that's what you're trying to do by learning from these tutorials.

    I personally don't have exprience in doing tile maps but there are some things missing that I can see from reading your code.

    Usually when I look at tile map code I see a 2D array of numbers, in your case it would be a 2D Array of numbers ranging from 1 - 10 placed in random indexes. From what I understand you're doing in the code you displayed is you're just assigning an image to a number and adding them to your blocks array.

    Issue with that is, since there is no 2D array to actually visualize the map you are creating, all you're doing is creating an array is a bunch of Rectangles with backgrounds.

    Another issue I can't make sense of is the fact you have your map area set to 720 indexes which is basically a field with, I don't know 27 images by 27 images will be your x and y value in those ints you created. leaving you with a JPanel divided up into the invisible tile map grid you are trying to create.

    Based on what number is in the index of the 2D Array I was talking about earlier, the background will be filled in with the corresponding image.

    About the OpenGL or Graphics 2D issue: It doesn't matter what graphics library you use, the issue is how you code it. OpenGL is pretty advanced for a beginner to jump into (especially 2D, from my experience), it's a 3D library so even though 2D is possible, it's kinda hard. Learn some of the Java API before you go into any next step.

    Hope I helped, or made sense O_o again I've never done tile maps so I'm responding to the code you posted.

提交回复
热议问题