Giter Club home page Giter Club logo

Comments (7)

kozie avatar kozie commented on September 4, 2024

Offtopic:

Coffee, code and Cats ^_^ well whattaya know :)

from canvasquery.

rezoner avatar rezoner commented on September 4, 2024

To be honest - I've never noticed it's empty. I've been using Playground (or its derivatives) for 3 years now - and I never been tempted to use keypress. I am willing to implement it if you tell me what do you expect it to do :) If it's obsolete I will remove it within next iteration.

Also I will be stressing this in every thread - I am soon splitting CanvasQuery and Playground into two different repos and domains. Playground will get a cleaner structure for source code and ability to bind renderer of your choice.

from canvasquery.

RoryDuncan avatar RoryDuncan commented on September 4, 2024

I imagine it would just have the same functionality as 'keydown' or 'keyup', so nothing special to it's circumstance. The keypress event is valuable for when the user holds a key, as that's what brought me here.

    if (e.which >= 48 && e.which <= 90) var keyName = String.fromCharCode(e.which).toLowerCase();
    else var keyName = this.keycodes[e.which];

    if (this.keys[keyName]) return;

    this.keypressEvent.key = keyName;
    this.keypressEvent.original = e;

    this.keys[keyName] = true;

    this.trigger("keypress", this.keypressEvent);

    if (this.preventDefault && document.activeElement === document.body) {
      e.returnValue = false;
      e.keyCode = 0;
      e.preventDefault();
      e.stopPropagation();
    }

from canvasquery.

rezoner avatar rezoner commented on September 4, 2024

The only real life usage for keypress I can think of is when implementing a canvas based GUI (input, edit) that behaves like just any other system wise input element.

Since the delay and interval is configurable by system/user it cannot be trusted gameplay wise.

TL;DR; I will add the functionality - all in all it's just pushing the event forward :)

from canvasquery.

RoryDuncan avatar RoryDuncan commented on September 4, 2024

Hmm, I didn't realize that those were system configured.
In my case that changes everything, as I was meaning to use it for gameplay.

Does this mean to emulate a hold event someone should create their own handler based on keydown and keyup events -and is a 'keyhold' event something that would be valuable to have in playground? Backtrack me, if i missed something important.. 😀

from canvasquery.

rezoner avatar rezoner commented on September 4, 2024

Let's assume we are implementing a shooting functionality for player.

Overly simplified approach should look like this:

keydown: function() {
  this.player.shooting = true;
},

keyup: function() {
  this.player.shooting = false;
}
Player.prototype.step = function(delta) { 

  if(this.shooting && this.cooldown <= 0) {
    this.fire();
    this.cooldown = this.baseCooldown;
  }

  this.cooldown -= delta;

}

If you feel like lazy - you can even skip event handling and just check if desired key is pressed:

Player.prototype.step = function(delta) { 

  if(app.keyboard.keys.space && this.cooldown <= 0) 

  /* ... */

}

from canvasquery.

RoryDuncan avatar RoryDuncan commented on September 4, 2024

Ah, I see. Your second example seems exceptionally convenient for that purpose. Thanks for the help :)

from canvasquery.

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.