mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 15:23:44 +08:00
add docs, change perf test
This commit is contained in:
parent
a81f9ec1f9
commit
d726c5d6f3
2
konva.js
2
konva.js
@ -11412,6 +11412,7 @@
|
|||||||
Text.prototype.getTextWidth = function () {
|
Text.prototype.getTextWidth = function () {
|
||||||
return this.textWidth;
|
return this.textWidth;
|
||||||
};
|
};
|
||||||
|
// TODO: deprecate and remove the method
|
||||||
/**
|
/**
|
||||||
* get height of one line of text
|
* get height of one line of text
|
||||||
* @method
|
* @method
|
||||||
@ -11421,6 +11422,7 @@
|
|||||||
Text.prototype.getTextHeight = function () {
|
Text.prototype.getTextHeight = function () {
|
||||||
return this.textHeight;
|
return this.textHeight;
|
||||||
};
|
};
|
||||||
|
// TODO: make it public?
|
||||||
Text.prototype._getTextSize = function (text) {
|
Text.prototype._getTextSize = function (text) {
|
||||||
var _context = getDummyContext(), fontSize = this.fontSize(), metrics;
|
var _context = getDummyContext(), fontSize = this.fontSize(), metrics;
|
||||||
_context.save();
|
_context.save();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "konva",
|
"name": "konva",
|
||||||
"version": "3.0.0",
|
"version": "2.6.0",
|
||||||
"author": "Anton Lavrenov",
|
"author": "Anton Lavrenov",
|
||||||
"files": [
|
"files": [
|
||||||
"README.md",
|
"README.md",
|
||||||
|
@ -275,6 +275,7 @@ export class Text extends Shape {
|
|||||||
getTextWidth() {
|
getTextWidth() {
|
||||||
return this.textWidth;
|
return this.textWidth;
|
||||||
}
|
}
|
||||||
|
// TODO: deprecate and remove the method
|
||||||
/**
|
/**
|
||||||
* get height of one line of text
|
* get height of one line of text
|
||||||
* @method
|
* @method
|
||||||
@ -284,6 +285,8 @@ export class Text extends Shape {
|
|||||||
getTextHeight() {
|
getTextHeight() {
|
||||||
return this.textHeight;
|
return this.textHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: make it public?
|
||||||
_getTextSize(text) {
|
_getTextSize(text) {
|
||||||
var _context = getDummyContext(),
|
var _context = getDummyContext(),
|
||||||
fontSize = this.fontSize(),
|
fontSize = this.fontSize(),
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<!DOCTYPE HTML>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<style>
|
<style>
|
||||||
@ -6,14 +6,13 @@
|
|||||||
margin: 0px;
|
margin: 0px;
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id='container'></div>
|
<div id="container"></div>
|
||||||
<script src='../../dist/konva-dev.js'></script>
|
<script src="../../konva.js"></script>
|
||||||
<script src='http://www.html5canvastutorials.com/lib/stats/stats.js'></script>
|
<script src="http://www.html5canvastutorials.com/lib/stats/stats.js"></script>
|
||||||
<script defer='defer'>
|
<script defer="defer">
|
||||||
var lastTime = 0;
|
var lastTime = 0;
|
||||||
|
|
||||||
var width = window.innerWidth;
|
var width = window.innerWidth;
|
||||||
@ -41,7 +40,7 @@
|
|||||||
var stage = new Konva.Stage({
|
var stage = new Konva.Stage({
|
||||||
container: 'container',
|
container: 'container',
|
||||||
width: width - 10,
|
width: width - 10,
|
||||||
height: height - 10,
|
height: height - 10
|
||||||
});
|
});
|
||||||
layer = new Konva.FastLayer();
|
layer = new Konva.FastLayer();
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
@ -80,13 +79,11 @@
|
|||||||
isAdding = false;
|
isAdding = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
document.addEventListener('touchstart', onTouchStart, true);
|
document.addEventListener('touchstart', onTouchStart, true);
|
||||||
document.addEventListener('touchend', onTouchEnd, true);
|
document.addEventListener('touchend', onTouchEnd, true);
|
||||||
|
|
||||||
function _handleTextureLoaded(event) {
|
function _handleTextureLoaded(event) {
|
||||||
for (var i = 0; i < startBunnyCount; i++)
|
for (var i = 0; i < startBunnyCount; i++) {
|
||||||
{
|
|
||||||
var bunny = new Konva.Image({
|
var bunny = new Konva.Image({
|
||||||
image: wabbitTexture,
|
image: wabbitTexture,
|
||||||
transformsEnabled: 'position',
|
transformsEnabled: 'position',
|
||||||
@ -95,15 +92,11 @@
|
|||||||
y: 10
|
y: 10
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bunny.speedX = Math.random() * 10;
|
bunny.speedX = Math.random() * 10;
|
||||||
bunny.speedY = (Math.random() * 10) - 5;
|
bunny.speedY = Math.random() * 10 - 5;
|
||||||
|
|
||||||
bunnys.push(bunny);
|
bunnys.push(bunny);
|
||||||
// bunny.cache();
|
|
||||||
layer.add(bunny);
|
layer.add(bunny);
|
||||||
bunny.cache();
|
|
||||||
|
|
||||||
layer.draw();
|
layer.draw();
|
||||||
}
|
}
|
||||||
@ -122,8 +115,7 @@
|
|||||||
if (isAdding) {
|
if (isAdding) {
|
||||||
// add 10 at a time :)
|
// add 10 at a time :)
|
||||||
|
|
||||||
for (var i = 0; i < amount; i++)
|
for (var i = 0; i < amount; i++) {
|
||||||
{
|
|
||||||
var bunny = new Konva.Image({
|
var bunny = new Konva.Image({
|
||||||
image: wabbitTexture,
|
image: wabbitTexture,
|
||||||
transformsEnabled: 'position',
|
transformsEnabled: 'position',
|
||||||
@ -131,13 +123,9 @@
|
|||||||
y: 0
|
y: 0
|
||||||
});
|
});
|
||||||
bunny.speedX = Math.random() * 10;
|
bunny.speedX = Math.random() * 10;
|
||||||
bunny.speedY = (Math.random() * 10) - 5;
|
bunny.speedY = Math.random() * 10 - 5;
|
||||||
// bunny.cache();
|
|
||||||
bunnys.push(bunny);
|
bunnys.push(bunny);
|
||||||
layer.add(bunny);
|
layer.add(bunny);
|
||||||
bunny.cache();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
@ -149,38 +137,29 @@
|
|||||||
bunny.setX(bunny.getX() + bunny.speedX);
|
bunny.setX(bunny.getX() + bunny.speedX);
|
||||||
bunny.setY(bunny.getY() + bunny.speedY);
|
bunny.setY(bunny.getY() + bunny.speedY);
|
||||||
bunny.speedY += gravity;
|
bunny.speedY += gravity;
|
||||||
if (bunny.getX() > maxX - wabbitTexture.width)
|
if (bunny.getX() > maxX - wabbitTexture.width) {
|
||||||
{
|
|
||||||
bunny.speedX *= -1;
|
bunny.speedX *= -1;
|
||||||
bunny.setX(maxX - wabbitTexture.width);
|
bunny.setX(maxX - wabbitTexture.width);
|
||||||
}
|
} else if (bunny.getX() < minX) {
|
||||||
else if (bunny.getX() < minX)
|
|
||||||
{
|
|
||||||
bunny.speedX *= -1;
|
bunny.speedX *= -1;
|
||||||
bunny.setX(minX);
|
bunny.setX(minX);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bunny.getY() > maxY - wabbitTexture.height)
|
if (bunny.getY() > maxY - wabbitTexture.height) {
|
||||||
{
|
|
||||||
bunny.speedY *= -0.85;
|
bunny.speedY *= -0.85;
|
||||||
bunny.setY(maxY - wabbitTexture.height);
|
bunny.setY(maxY - wabbitTexture.height);
|
||||||
if (Math.random() > 0.5)
|
if (Math.random() > 0.5) {
|
||||||
{
|
|
||||||
bunny.speedY -= Math.random() * 6;
|
bunny.speedY -= Math.random() * 6;
|
||||||
}
|
}
|
||||||
}
|
} else if (bunny.getY() < minY) {
|
||||||
else if (bunny.getY() < minY)
|
|
||||||
{
|
|
||||||
bunny.speedY = 0;
|
bunny.speedY = 0;
|
||||||
bunny.setY(minY);
|
bunny.setY(minY);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
layer.drawScene();
|
layer.drawScene();
|
||||||
requestAnimationFrame(update);
|
requestAnimationFrame(update);
|
||||||
stats.end();
|
stats.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue
Block a user