Comments (9)
For sure, thanks for the suggestion. Aside from needing to finish unit tests, I'm not sure what the API should look like for this. Let me know if you have any suggestions. The main option I'm considering is adding Two.Sprite
.
from two.js.
Yes, it's a good idea adding Two.Sprite, even in sight of a future implementation of Two.AnimatedSprite.
rect.image = two.makeSprite('images/sprite.png');
rect.animation = two.makeAnimatedSprite(sprites, 100); // sprites is a Two.Sprite array, 100 is the delay between sprites switch
You can give a look to sprite.js too.
from two.js.
Hi.
I started using two.js today and have been trying to make a pretty simple game. With the current build, do you have any advice for a way which I can get background images to work as OP requested?
I have added a pattern definition to the SVG element, but when I try to set the polygon's fill to URL() it seems to get ignored. Any advice?
Thanks
from two.js.
Hey @feenr, sorry for the delay. There is a stop-gap. It requires editing the source of two.js if you're okay with that? In addition this hack only works for the canvas renderer. You can see a version of two.js that has this running here: https://github.com/chrisdelbuck/tribeca/blob/master/app/scripts/third-party/two.js
Basically, every polygon has an image
attribute added. You can see this added on line 4492. It also adds width
and height
properties which are inappropriately named and used as the offset positioning for the image in order to make it centered on the rectangle. This notifies the canvas renderer to render out the image not the normal fill / stroke line 3368. An example of this use case would look something like this:
var img = document.createElement('img');
img.onload = function() {
var sprite = two.makeRectangle(two.width / 2, two.height / 2, 50, 50);
sprite.image = img;
sprite.width = sprite.height = 25;
};
img.src = 'image.png';
Now take this with a grain-of-salt because this solution was produced over a hackathon and has a lot of issues that I probably can't help you with. But, I thought I'd share it nonetheless. Good luck!
from two.js.
Hi jonobr1,
Thanks for the reply. So far I have been working exclusively with the SVG renderer. I actually found a solution for what I was trying to do. I didn't realize earlier that there was an SVG Image tag, so I just replaced my polygon with a group and added an image.
Keep up the good work!
from two.js.
@feenr I wonder what's the detail of your solution ?
Can you please share it. I really appreciate it!
Did you use the original Two.js API only, or have you implemented some custom function into the Two.js ?
from two.js.
@vibertthio here's an early example of using images in the latest dev
branch of Two.js: https://jsfiddle.net/jonobr1/Lbu6795r/ works with SVG, Canvas, and WebGL renderers 👍
from two.js.
@jonobr1 Doooooooope!
from two.js.
Nearing completion of tests for imagery in Two.js. Closing out now that the API is squared away and will be shipping with the next release v0.7.0
.
from two.js.
Related Issues (20)
- [Question] Woscope integration HOT 3
- How to animate millions of points on browser canvas using two.js HOT 12
- wrong type in getPointAT declaration in path class HOT 2
- "Dom-less" start for just generating result svg [Enhancement] HOT 1
- Can two handle thousands of svg path elements and hundreds of thousands of points? HOT 1
- [Enhancement] Add Path.Compound Static Method
- How to check if an object is currently being hovered by the mouse whilst taking rotation into account? HOT 3
- Two.Utils.read.path throws an error HOT 3
- Smooth out lines and Round Corners HOT 2
- [Bug] WebGL Renderer Blurry HOT 5
- Partial Ellipse HOT 6
- Text `BoundingClientRect` in nested groups HOT 2
- compile error typescript[Bug] HOT 2
- svg fill-opacity [Bug] HOT 12
- Issues with Zoom and ZUI when upgrading from version 8.1.1 to 8.11 (latest) HOT 3
- creating curve path using anchors and make path not working ! HOT 2
- [Question] Best way to render ~250k polygons HOT 6
- Text Baseline in SVG Backend HOT 5
- [Bug] Negative scale does not work, with webgl mode only HOT 1
- Can i add events to shapes if renderer is Two.CanvasRenderer HOT 3
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 two.js.