我想开始制作一个2d视频游戏,我找到了一个java教程。然而,我想使用kotlin,因为我听说它更好,我是java和kotlin编程的新手,我需要把这个
Graphics2d g2 = Graphics2D(g)
在科特林,我无论如何都没有通过搜索找到。
如果你想知道(但我认为这无关紧要)JPanel类文件在这里:
import java.awt.Color
import java.awt.Dimension
import java.awt.Graphics
import java.awt.Graphics2D
import javax.swing.JPanel
class GamePanel : JPanel(), Runnable{
//Screen settings
var originalTileSize = 16
var scale = 3
var tileSize = originalTileSize * scale
var maxScreenCol = 16
var maxScreenRow = 12
var gameThread = Thread()
var screenWidth = maxScreenCol * tileSize // 768
var screenHeight = maxScreenRow * tileSize // 576 TO CHANGE????
init {
this.setPreferredSize(Dimension(screenWidth, screenHeight))
this.setBackground(Color.BLACK)
this.setDoubleBuffered(true)
}
// Game Thread code
public fun startGameThread(){
gameThread = Thread(this)
gameThread.start()
}
// run the game loop
public override fun run(){
while (gameThread != null){
update()
repaint()
}
}
public fun update(){
// Nothing for now
}
public override fun paintComponent(g : Graphics) {
super.paintComponent(g)
Graphics2D g2 = Graphics2D(g)
}
}