diff --git a/GameEngine/resources/button.png b/GameEngine/resources/button.png new file mode 100644 index 0000000..9d84a62 --- /dev/null +++ b/GameEngine/resources/button.png Binary files differ diff --git a/GameEngine/src/main/java/gameEngine/entites/gameComponents/MoveImage.java b/GameEngine/src/main/java/gameEngine/entites/gameComponents/MoveImage.java index a1930e4..a12310a 100644 --- a/GameEngine/src/main/java/gameEngine/entites/gameComponents/MoveImage.java +++ b/GameEngine/src/main/java/gameEngine/entites/gameComponents/MoveImage.java @@ -4,6 +4,8 @@ import gameEngine.input.*; import gameEngine.views.Window; +import java.awt.*; + import static org.lwjgl.glfw.GLFW.*; import static org.lwjgl.opengl.GL11.*; @@ -37,6 +39,11 @@ TextMesh textmesh = gameObject.getComponent(TextMesh.class); textmesh.setText("popopo"); } + if(Input.GetKeyDown(GLFW_KEY_U)){ + GameObject gameObject = (GameObject) entity; + TextMesh textmesh = gameObject.getComponent(TextMesh.class); + textmesh.setColor(Color.RED); + } if (Input.GetKey(GLFW_KEY_W)) { float y = entity.transform.position.y; diff --git a/GameEngine/src/main/java/gameEngine/entites/gameComponents/TextMesh.java b/GameEngine/src/main/java/gameEngine/entites/gameComponents/TextMesh.java index 457ca67..0907f40 100644 --- a/GameEngine/src/main/java/gameEngine/entites/gameComponents/TextMesh.java +++ b/GameEngine/src/main/java/gameEngine/entites/gameComponents/TextMesh.java @@ -15,17 +15,19 @@ private Entity parent; // 親のオブジェクトを持つ public String text; public int textSize; + public java.awt.Color color; private int spriteWidth = 1; // サイズとは無関係 private int spriteHeight = 1; // サイズとは無関係 // コンストラクタ - public TextMesh(Entity parent, String text, int textSize) { + public TextMesh(Entity parent, String text, int textSize, java.awt.Color color) { this.parent = parent; this.text = text; this.textSize = textSize; - Font font = new Font(new java.awt.Font(SANS_SERIF, PLAIN, textSize),true); + this.color = color; + Font font = new Font(new java.awt.Font(SANS_SERIF, PLAIN, textSize),true, color); fontTexture = font.getTexture(); fontGlyphs = font.getGlyphs(); fontHeight = font.getFontHeight(); @@ -35,6 +37,7 @@ this.parent = newParent; this.text = original.text; this.textSize = original.textSize; + this.color = original.color; this.fontGlyphs = original.fontGlyphs; this.fontTexture = original.fontTexture; this.fontHeight = original.fontHeight; @@ -69,11 +72,19 @@ if(newTextSize < 3 || newTextSize > 127) return; this.textSize = newTextSize; - Font font = new Font(new java.awt.Font(SANS_SERIF, PLAIN, textSize), true); + Font font = new Font(new java.awt.Font(SANS_SERIF, PLAIN, textSize), true, color); this.fontTexture = font.getTexture(); this.fontGlyphs = font.getGlyphs(); this.fontHeight = font.getFontHeight(); + renderText(); + } + public void setColor(java.awt.Color newColor){ + this.color = newColor; + Font font = new Font(new java.awt.Font(SANS_SERIF, PLAIN, textSize), true, color); + this.fontTexture = font.getTexture(); + this.fontGlyphs = font.getGlyphs(); + this.fontHeight = font.getFontHeight(); renderText(); } diff --git a/GameEngine/src/main/java/gameEngine/scenes/Scene.java b/GameEngine/src/main/java/gameEngine/scenes/Scene.java index 8901587..7a4b25d 100644 --- a/GameEngine/src/main/java/gameEngine/scenes/Scene.java +++ b/GameEngine/src/main/java/gameEngine/scenes/Scene.java @@ -56,8 +56,8 @@ String newId = Integer.toString(entitiesLength); GameObject newGameObject = new GameObject(newId); addEntity(newId, newGameObject); - newGameObject.addComponent(new Mesh(newGameObject, Mesh.MeshType.SPRITE, "GameEngine/resources/0.png")); - newGameObject.addComponent(new TextMesh(newGameObject, "Hello World",32)); + newGameObject.addComponent(new Mesh(newGameObject, Mesh.MeshType.SPRITE, "GameEngine/resources/button.png")); + newGameObject.addComponent(new TextMesh(newGameObject, "Hello World",32, java.awt.Color.BLACK)); newGameObject.setName("NewEntity" + newId); }); } diff --git a/GameEngine/src/main/java/gameEngine/views/Font.java b/GameEngine/src/main/java/gameEngine/views/Font.java index bc97d89..ee5720c 100644 --- a/GameEngine/src/main/java/gameEngine/views/Font.java +++ b/GameEngine/src/main/java/gameEngine/views/Font.java @@ -40,12 +40,12 @@ * @param font The AWT Font * @param antiAlias Wheter the font should be antialiased or not */ - public Font(java.awt.Font font, boolean antiAlias) { + public Font(java.awt.Font font, boolean antiAlias, Color color) { glyphs = new HashMap<>(); - createFontTexture(font, antiAlias); + createFontTexture(font, antiAlias, color); } - private void createFontTexture(java.awt.Font font, boolean antiAlias) { + private void createFontTexture(java.awt.Font font, boolean antiAlias, Color color) { texture = new Texture(); /* Loop through the characters to get charWidth and charHeight */ int imageWidth = 0; @@ -58,7 +58,7 @@ continue; } char c = (char) i; - BufferedImage ch = createCharImage(font, c, antiAlias); + BufferedImage ch = createCharImage(font, c, antiAlias, color); if (ch == null) { /* If char image is null that font does not contain the char */ continue; @@ -84,7 +84,7 @@ continue; } char c = (char) i; - BufferedImage charImage = createCharImage(font, c, antiAlias); + BufferedImage charImage = createCharImage(font, c, antiAlias, color); if (charImage == null) { /* If char image is null that font does not contain the char */ continue; @@ -146,7 +146,7 @@ * @param antiAlias Wheter the char should be antialiased or not * @return Char image */ - private BufferedImage createCharImage(java.awt.Font font, char c, boolean antiAlias) { + private BufferedImage createCharImage(java.awt.Font font, char c, boolean antiAlias, Color color) { /* Creating temporary image to extract character size */ BufferedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); @@ -174,7 +174,7 @@ } g.setFont(font); - g.setPaint(Color.RED); //色指定部分 + g.setPaint(color); //色指定部分 g.drawString(String.valueOf(c), 0, metrics.getAscent()); g.dispose(); return image;