Comments (9)
I don't think there's nothing stopping you from doing that right now? sprite.setImage( ) can take an image or canvas which you have loaded or dynamically created. Maybe I'm missing some finer details of your suggesion?
from jaws.
could a canvas be used at sprite creation? Should work the same as sprite.setImage()? For example trying to alter example 12 (replacing grass.png) I am getting "Uncaught Error: INVALID_STATE_ERR: DOM Exception 11" in sprite.js line 272:
function canvasRect(width, height, style) {
var canvas = document.createElement("canvas")
canvas.width = this.width
canvas.height = this.height
var context = canvas.getContext("2d")
context.fillStyle = this.style;
context.fillRect(0, 0, this.width, this.height);
return canvas;
};
green_block = new canvasRect(32,32,"rgb(42,255,0)");
/* Called once when a game state is activated. Use it for one-time setup code. */
this.setup = function() {
fps = document.getElementById("fps")
blocks = new jaws.SpriteList()
for(var i = 0; i < width; i++) {
for(var i2 = 0; i2 < height; i2++) {
blocks.push( new Sprite({image: green_block , x: i*32, y: i2*32}) )
}
}
from jaws.
try "return canvas.context" instead of "return canvas" .. does it work?
It should. But we could also patch setImage to detect a canvas and do that automatically for us, should be supersimple
from jaws.
if I do that it looks like it's getting hung up looking for and trying to create an asset:
Uncaught TypeError: Cannot read property '1' of null assets.js:66
jaws.Assets.getPostfix assets.js:66
jaws.Assets.getType assets.js:70
jaws.Assets.load assets.js:132
jaws.Sprite.setImage sprite.js:101
jaws.Sprite.set sprite.js:60
Sprite sprite.js:28
Example.setup example12.html:51
jaws.GameLoop.start game_loop.js:64
jaws.switchGameState core.js:248
assetsLoaded core.js:207
jaws.Assets.processCallbacks assets.js:217
jaws.Assets.assetLoaded assets.js:192
from jaws.
ok, I got confused. It should be an canvas, not a context. So your first example should work. Look at example11.html ... jaws.gfx.retroScaleImage() returns a canvas. Which I one line later send into a Sprite() constructor.
from jaws.
https://github.com/ippa/jaws/blob/master/src/gfx.js#L13 <-- retroScaleImage()
https://github.com/ippa/jaws/blob/master/examples/example11.html#L32-33 <-- jaws.Sprite() using a canvas
from jaws.
was it really work now?
from jaws.
not sure what you mean kxh?
from jaws.
I do it like this
var canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
var context = canvas.getContext("2d");
context.putImageData(jaws.context.getImageData(0,0,width,height),0,0);
var result = new jaws.Sprite({
image : canvas,
x : 80,
y : 480
});
it can`t be this
new jaws.Sprite({
image : jaws.canvas,
x : 80,
y : 480
});
from jaws.
Related Issues (20)
- Cannot rotate sprite properly HOT 6
- More SpriteSheet flexibility HOT 1
- Feature? Delete from TileMap HOT 3
- PixelMap 'tainted cross-origin data' in chrome 25 HOT 2
- Rotate viewport HOT 7
- Question: how to use jaws.Text? HOT 2
- nevermind
- Gamepad support, multiplayer considerations? HOT 3
- jaws.Assets() Arrays vs. Objects
- Question: Setting a sprite's color to an RGBA array instead of a named value
- Please replace the word "Fuchia" in your files (assets.js?) with the correct "fuchsia" (with an S). HOT 1
- Add project Jaws in Bower (A package manager for the web)
- html character encoding
- About the viewport bound HOT 2
- numpad0 keycode missing HOT 2
- Feature request: tilemap ROW and COL returned
- Sprite.setImage doesn't take into account scale_image HOT 1
- Setting the frame_direction property of an animation to -1 causes the animation to loop on the first frame. HOT 2
- jaws.Parallax.add_layer use jaws.Parallax.prototype.default_options.layers HOT 3
- Feature Request: Text Support HOT 2
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 jaws.