added NodeText

This commit is contained in:
DaniTheSkunk 2022-12-13 03:24:55 +00:00
parent 2aec5c4981
commit 6f66d7391f
3 changed files with 39 additions and 14 deletions

View File

@ -7,6 +7,7 @@ import com.danitheskunk.skunkworks.audio.nodes.Node;
import com.danitheskunk.skunkworks.audio.nodes.SamplePlayer;
import com.danitheskunk.skunkworks.audio.nodes.TTS;
import com.danitheskunk.skunkworks.backends.gl.Gamepad;
import com.danitheskunk.skunkworks.gfx.Color;
import com.danitheskunk.skunkworks.gfx.IRenderContext;
import com.danitheskunk.skunkworks.gfx.ITexture;
import com.danitheskunk.skunkworks.gfx.font.IFont;
@ -161,21 +162,12 @@ public abstract class BaseGame {
if(currentFrameTime >= 1.0 / 60.0) {
rootNode.tick();
update(1.0 / 60.0);
/*
var rc3d = window.renderStart3D();
render3D(rc3d);
window.renderFinish3D(rc3d);
var rc = window.renderStart();
renderPre(rc);
rootNode.render(rc);
render(rc);
window.renderFinish(rc);
window.runScaler();
*/
var p3d = window.getPipeline3D();
var p2d = window.getPipeline2D();
window.startFrame();
p3d.startFrame();
//todo: should be transparent but bugged
p3d.getRenderContext().clear(Color.BLACK);
render3D(p3d.getRenderContext());
p3d.finishFrame();
p2d.startFrame();

View File

@ -1,22 +1,28 @@
package com.danitheskunk.skunkworks;
import com.danitheskunk.skunkworks.audio.ISample;
import com.danitheskunk.skunkworks.gfx.font.FontTileset;
import com.danitheskunk.skunkworks.nodes.NodeSprite;
import com.danitheskunk.skunkworks.nodes.NodeText;
import org.lwjgl.glfw.GLFW;
public class TestNode extends BaseGame {
private final ISample kick;
private final NodeSprite sprite;
private final NodeText text;
float[] axes;
public TestNode() {
super(new Vec2i(1280, 720), "Skunkworks");
kick = loadSample("demoassets/kick.wav");
var font = window.loadFontTileset("fonts/ega-8x14.png");
text = new NodeText(font, "Hello World!");
sprite = new NodeSprite();
sprite.setTexture(loadTexture("demoassets/test.png"));
sprite.setTexture(loadTexture("demoassets/card.png"));
sprite.setPos(new Vec2f(100, 100));
rootNode.add(sprite);
//rootNode.add(sprite);
rootNode.add(text);
//doThing();
}
@ -31,7 +37,7 @@ public class TestNode extends BaseGame {
@Override
protected void update(double delta) {
sprite.setPos(new Vec2f(640 + 640 * gamepad.getAxis(0), 360 + 360 * gamepad.getAxis(1)));
text.setPos(new Vec2f(640 + 640 * gamepad.getAxis(0), 360 + 360 * gamepad.getAxis(1)));
if(gamepad.getButtonPressed(0)) {
playSample(kick);
}

View File

@ -0,0 +1,27 @@
package com.danitheskunk.skunkworks.nodes;
import com.danitheskunk.skunkworks.gfx.IRenderContext;
import com.danitheskunk.skunkworks.gfx.font.IFont;
public class NodeText extends Node {
private IFont font;
private String text;
public NodeText(IFont font, String text) {
this.font = font;
this.text = text;
}
@Override
public void render(IRenderContext rc) {
rc.drawString(getAbsolutePos().toVec2i(), text, font);
}
public void setFont(IFont font) {
this.font = font;
}
public void setText(String text) {
this.text = text;
}
}