Comments (7)
Offtopic:
Coffee, code and Cats ^_^ well whattaya know :)
from canvasquery.
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.
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.
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.
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.
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.
Ah, I see. Your second example seems exceptionally convenient for that purpose. Thanks for the help :)
from canvasquery.
Related Issues (20)
- Are colors broken right now? HOT 2
- Demos or tutorials? HOT 1
- Version 0.9.1 HOT 1
- drawSprite missing HOT 1
- text size HOT 1
- Logitech Universal Reciever is incorrectly recognised as a gamepad HOT 1
- Old browsers compatibility requestAnimationFrame HOT 2
- preventContextMenu not working HOT 1
- Sprites in Playground HOT 15
- Align HOT 8
- drawAtlasFrame() does not use x,y HOT 1
- Touchend is unreliable in multitouch HOT 4
- Integrating Playground with THREE.js
- Plugins in Playground HOT 1
- Mouselock Movement-Delta unprecise and IExplorer incompatible
- npm and browserify support HOT 14
- swapping color palettes
- cq.loadImages can not to use!
- Flip Sprite HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from canvasquery.