implement crosshair
This commit is contained in:
@@ -23,7 +23,7 @@ window.Minecraft = class {
|
||||
this.pickedBlock = 1;
|
||||
|
||||
// Create current screen and overlay
|
||||
this.ingameOverlay = new IngameOverlay();
|
||||
this.ingameOverlay = new IngameOverlay(this.window);
|
||||
this.currentScreen = null;
|
||||
|
||||
// Initialize
|
||||
|
||||
@@ -7,4 +7,20 @@ window.Gui = class {
|
||||
stack.globalAlpha = alpha;
|
||||
}
|
||||
|
||||
drawTexture(stack, texture, x, y, width, height, alpha = 1.0) {
|
||||
this.drawSprite(stack, texture, 0, 0, 256, 256, x, y, width, height, alpha);
|
||||
}
|
||||
|
||||
drawSprite(stack, texture, spriteX, spriteY, spriteWidth, spriteHeight, x, y, width, height, alpha = 1.0) {
|
||||
stack.globalAlpha = alpha;
|
||||
stack.drawImage(texture, spriteX, spriteY, spriteWidth, spriteHeight, x, y, width, height);
|
||||
stack.globalAlpha = 1.0;
|
||||
}
|
||||
|
||||
loadTexture(path) {
|
||||
let img = new Image();
|
||||
img.src = path;
|
||||
return img;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,19 @@
|
||||
window.IngameOverlay = class extends Gui {
|
||||
|
||||
constructor(window) {
|
||||
super();
|
||||
this.window = window;
|
||||
|
||||
this.textureCrosshair = this.loadTexture("icons.png");
|
||||
}
|
||||
|
||||
render(stack, mouseX, mouseY, partialTicks) {
|
||||
this.drawRect(stack, 0, 0, 500, 500, '#0000FF');
|
||||
this.renderCrosshair(stack, this.window.width / 2, this.window.height / 2)
|
||||
}
|
||||
|
||||
renderCrosshair(stack, x, y) {
|
||||
let size = 15 * 4;
|
||||
this.drawSprite(stack, this.textureCrosshair, 0, 0, 15, 15, x - size / 2, y - size / 2, size, size, 0.6);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -70,6 +70,7 @@ window.WorldRenderer = class {
|
||||
|
||||
// Get context stack of 2d canvas
|
||||
this.stack2d = this.canvas2d.getContext('2d');
|
||||
this.stack2d.imageSmoothingEnabled = false;
|
||||
|
||||
// Create texture from rendered graphics.
|
||||
this.frameBuffer = new THREE.Texture(this.canvas2d)
|
||||
@@ -110,6 +111,10 @@ window.WorldRenderer = class {
|
||||
let cameraChunkZ = Math.floor(player.z >> 4);
|
||||
this.renderChunks(cameraChunkX, cameraChunkZ);
|
||||
|
||||
// Clear frame buffer for 2d screen
|
||||
this.stack2d.clearRect(0, 0, this.window.width, this.window.height);
|
||||
this.frameBuffer.needsUpdate = true;
|
||||
|
||||
// Render in-game overlay
|
||||
let mouseX = this.minecraft.window.mouseX;
|
||||
let mouseY = this.minecraft.window.mouseY;
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 644 B |
Reference in New Issue
Block a user