Giter VIP home page Giter VIP logo

Comments (11)

shama avatar shama commented on August 28, 2024

@z3t0 https://developer.mozilla.org/en-US/docs/Web/Events/contextmenu

from voxel-engine.

z3t0 avatar z3t0 commented on August 28, 2024

Sorry I'm kinda new to this, could you please provide a short example? I managed to get this working with gamejs but that is giving me a few annoying bugs

from voxel-engine.

z3t0 avatar z3t0 commented on August 28, 2024

This is how I managed to get it working now.

// Controls

controls()

function controls(){

//Mouse Input
    document.body.addEventListener('mousedown', mousePressed)
    function mousePressed(event){
        switch(event.button){
            case 0: // Left mouse button
                var position = block
                if(game.getBlock(position) != 0){
                game.setBlock(position, 0)
                console.log('Break: ' + position)
                } else{
                    console.log('No Block')
                }

                break;

            case 1: // Middle mouse button
                var position = block
                var type = game.getBlock(position)
                console.log('BlockType: ' + type + ' : ' + position)
                break;

            case 2: // Right mouse button
            console.log(adjacentBlock)
                var position = adjacentBlock
                console.log(position)
                game.setBlock(position, 1)
                console.log('Placed: ' + position)

        }
    }

}

from voxel-engine.

shama avatar shama commented on August 28, 2024

Ah sorry I didn't understand your original request. contextmenu won't be useful in that case.

Here is an example which raycasts from the player's position and vector to determine the block to set (in which game is an instance of voxel-engine).

function raycast(dist) {
  dist = dist || 100
  var pos = game.cameraPosition()
  var vec = game.cameraVector()
  return game.raycastVoxels(pos, vec, dist)
}
document.addEventListener('mousedown', function(e) {
  if (e.button === 2) {
    var block = raycast()
    if (block) game.setBlock(block.position, 1)
  }
})

Also check out https://github.com/maxogden/voxel-highlight which does this and https://github.com/maxogden/voxel-hello-world/blob/master/index.js for a more in depth example.

from voxel-engine.

z3t0 avatar z3t0 commented on August 28, 2024

Thanks! I am currently using this.

hl.on('highlight-adjacent', function(voxelPos) {
    adjacentBlock = voxelPos
    game.setBlock(adjacentBlock, 1)
    console.log('Placed: ' + adjacentBlock)
});

from voxel-engine.

z3t0 avatar z3t0 commented on August 28, 2024

I was thinking of making some sort of wiki for voxel-engine and similar packages where we can put important things like this, what do you think? Also, is voxel-hello-world broken?

from voxel-engine.

shama avatar shama commented on August 28, 2024

You'd want to talk to @kumavis (as I think he is primary maintainer now?)

I'm not up to date on the current status of all the voxel- projects. I know a great deal of the effort has been move towards http://stack.gl/ and I think the plan is to circle back to the voxel- projects once the resources there are sufficient.

from voxel-engine.

z3t0 avatar z3t0 commented on August 28, 2024

@shama That sounds interesting, but as I understand it voxel-engine uses Three.js right? So wouldn't that require rewriting it in stack.gl?

from voxel-engine.

shama avatar shama commented on August 28, 2024

@z3t0 I don't think any parts of three.js need to be rewritten. We just write the modules we need and try to avoid creating too much interdependence (as that would give us the same issues we have with three.js now).

A lot of these modules (or at least the foundation) already exist:

It's a bit all over the place atm but the holes are slowly being filled in. Once they are, making voxel modules and apps will become much easier and we'll be able to do a lot more interesting work.

from voxel-engine.

deathcap avatar deathcap commented on August 28, 2024

The biggest missing piece in the ndarray/stackgl branch (#103) right now is player avatars, there isn't anything like we had in three.js ported over, afaik.

For the original question of detecting right-click, #112 has some relevant pointers. I use https://github.com/deathcap/voxel-reach to handle DOM mousedown events; https://github.com/mikolalysenko/game-shell also listens for this event and provides a polling-style interface, which I use via descriptive keybinding names in https://github.com/deathcap/voxel-keys - this plugin also handles preventing the "default" browser action for both keys and mouse actions, so you can use them uninterrupted in your game (that is, it listens for DOM keydown and contextmenu events and calls preventDefault())

from voxel-engine.

z3t0 avatar z3t0 commented on August 28, 2024

@deathcap @shama Thanks for the informative replies! We should probably create some sort of overarching wiki for the whole voxel-* project(s) because things like this are really confusing when you first start out.

P.S: This might be kinda stupid but... Is there some wiki out there I am not aware of? Because that would help a lot 😄. Otherwise I could work on building the skeleton for one and you guys could fill in the technical details?

from voxel-engine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.