Skip to content

Commit fabd6c6

Browse files
authored
Merge pull request #50 from MassiveHeights/v0.6.x-dev
v0.5.8-stable
2 parents 3f1c5ea + c018d1b commit fabd6c6

37 files changed

+850
-277
lines changed

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
Black Engine: Changelog
22
=======================
33

4+
# v0.5.8
5+
### New features
6+
- Added `useHiDPR` property to control render quality on high DPI screens
7+
- Added ability to draw rounded rectangle
8+
- Added ability to load custom asset in AssetManager using CustomAsset
9+
- Added gradient and pattern support for Graphics
10+
11+
### Changes
12+
- Changed empty clip rectangle to clip everything instead of nothing
13+
- Improved anchor performance
14+
15+
### Bug Fixes
16+
- Fixed Orientation Lock still works when disabled
17+
- Fixed many GCC comments
18+
- Fixed bug causing colored sprite to render incorrectly
19+
- Fixed slice9grid not working as expected on colored sprites
20+
- Fixed bug causing Arcade physics to not cleanup colliders after removing objects from stage
21+
- Fixed Arcade physics units to be always within stage
22+
- Fixed clip rect not working on TextField
23+
- Fixed `getTextures` returning null for backed vectors
24+
- Fixed BVG quadratic curve math
25+
- Fixed many BVG rendering bugs and glitches
26+
- Fixed anchors not working in some cases
27+
428
# v0.5.7
529
### Changes
630
- Changed license to Simplified BSD!!!

build.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"src/assets/loaders/FontFaceAssetLoader.js",
5454

5555
"src/assets/Asset.js",
56+
"src/assets/CustomAsset.js",
5657
"src/assets/TextureAsset.js",
5758
"src/assets/JSONAsset.js",
5859
"src/assets/XMLAsset.js",
@@ -88,6 +89,10 @@
8889
"src/display/DisplayObject.js",
8990
"src/display/GraphicsData.js",
9091
"src/display/Graphics.js",
92+
"src/display/GraphicsPath.js",
93+
"src/display/GraphicsGradient.js",
94+
"src/display/GraphicsLinearGradient.js",
95+
"src/display/GraphicsPattern.js",
9196
"src/display/GraphicsCommand.js",
9297
"src/display/GraphicsCommandType.js",
9398
"src/display/CapsStyle.js",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "black",
3-
"version": "0.5.7",
3+
"version": "0.5.8",
44
"description": "",
55
"main": "dist/black-es6-module.js",
66
"directories": {},

src/Black.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ class Black extends MessageDispatcher {
119119
/** @private @type {Array<number>} */
120120
this.mFrameTimes = [];
121121

122+
/** @private @type {boolean} */
123+
this.mUseHiDPR = Device.isMobile;
124+
122125
this.__bootViewport();
123126

124127
this.__update = this.__update.bind(this);
@@ -331,6 +334,7 @@ class Black extends MessageDispatcher {
331334
/**
332335
* @private
333336
* @param {number} timestamp
337+
* @param {boolean} forceUpdate
334338
* @return {void}
335339
*/
336340
__update(timestamp, forceUpdate) {
@@ -703,6 +707,26 @@ class Black extends MessageDispatcher {
703707
return this.mSplashScreen;
704708
}
705709

710+
711+
/**
712+
* Gets/sets whenever driver should be created with high DPR support.
713+
* NOTE: Cannot be changed at runtime.
714+
*
715+
* @returns {boolean}
716+
*/
717+
get useHiDPR() {
718+
return this.mUseHiDPR;
719+
}
720+
721+
/**
722+
* @ignore
723+
* @param {boolean} value
724+
* @returns {void}
725+
*/
726+
set useHiDPR(value) {
727+
this.mUseHiDPR = value;
728+
}
729+
706730
/**
707731
* `Black.magic`! Got it? Got it?!?! Same as `Math.random()` but much cooler.
708732
*

src/animation/Interpolation.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Interpolation {
1212
*
1313
* @param {Array} v The input array of values to interpolate between.
1414
* @param {number} k The percentage of interpolation, between 0 and 1.
15+
* @param {function(number):number} lerpFunction Interpolation function.
1516
* @return {number} The interpolated value
1617
*/
1718
static linear(v, k, lerpFunction = null) {

src/animation/Tween.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Tween extends Component {
1717
* @param {Object} values The values to tween.
1818
* @param {number} [duration=0.25] Duraction in seconds.
1919
* @param {Object|null} [properties=null] Tween properties Object.
20+
* @param {Object|null} [plugins=null] Interpolation plugins object
2021
*/
2122
constructor(values, duration = 0.250, properties = null, plugins = null) {
2223
super();

src/assets/AssetManager.js

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class AssetManager extends MessageDispatcher {
7272
/** @private @type {Object.<string, BitmapFontData>} */
7373
this.mBitmapFonts = {};
7474

75+
/** @private @type {Object.<string, CustomAsset>} */
76+
this.mCustomAssets = {};
77+
7578
/** @private @type {AssetManagerState} */
7679
this.mState = AssetManagerState.NONE;
7780

@@ -226,6 +229,16 @@ class AssetManager extends MessageDispatcher {
226229
this.mQueue.push(new FontAsset(name, '', false));
227230
}
228231

232+
/**
233+
* Adds custom asset to the loading queue.
234+
*
235+
* @param {Asset} asset
236+
*/
237+
enqueueCustomAsset(asset) {
238+
this.__validateState();
239+
this.mQueue.push(asset);
240+
}
241+
229242
/**
230243
* Starts loading all enqueued assets.
231244
*
@@ -287,11 +300,17 @@ class AssetManager extends MessageDispatcher {
287300
else if (item.constructor === BVGAsset) {
288301
this.mGraphicsData[item.name] = item.data;
289302

290-
const bakedTextures = item.bakeTextures();
291-
Object.keys(bakedTextures).forEach(name => name !== item.name && this.__validateName(name));
292-
Object.assign(this.mVectorTextures, bakedTextures);
293-
}
294-
else {
303+
const bakedTextures = /** @type {BVGAsset} */ (item).bakeTextures();
304+
305+
for (let name in bakedTextures) {
306+
if (!bakedTextures.hasOwnProperty(name)) continue;
307+
308+
name !== item.name && this.__validateName(name);
309+
this.mVectorTextures[name] = bakedTextures[name];
310+
}
311+
} else if (item instanceof CustomAsset) {
312+
this.mCustomAssets[item.name] = item.data;
313+
} else {
295314
Debug.error(`[AssetManager] Unable to handle asset type ${item}.`);
296315
}
297316

@@ -423,24 +442,32 @@ class AssetManager extends MessageDispatcher {
423442
// collect single textures
424443
for (let key in this.mTextures)
425444
if (re.test(key))
426-
names.push({name: key, atlas: null});
445+
names.push({ name: key, atlas: null, isBakedVector: false });
446+
447+
for (let key in this.mVectorTextures)
448+
if (re.test(key))
449+
names.push({ name: key, atlas: null, isBakedVector: true });
427450

428451
// collect textures from all atlases
429452
for (let key in this.mAtlases) {
430453
let atlas = this.mAtlases[key];
431454

432455
for (let key2 in atlas.subTextures)
433456
if (re.test(key2))
434-
names.push({name: key2, atlas: atlas});
457+
names.push({ name: key2, atlas: atlas, isBakedVector: false });
435458
}
436459

437460
AtlasTexture.naturalSort(names, 'name');
438461

439462
for (let i = 0; i < names.length; i++) {
440463
let ao = names[i];
441464

442-
if (ao.atlas == null)
443-
out.push(this.mTextures[ao.name]);
465+
if (ao.atlas === null) {
466+
if (ao.isBakedVector === true)
467+
out.push(this.mVectorTextures[ao.name]);
468+
else
469+
out.push(this.mTextures[ao.name]);
470+
}
444471
else
445472
out.push(ao.atlas.mSubTextures[ao.name]);
446473
}
@@ -508,6 +535,16 @@ class AssetManager extends MessageDispatcher {
508535
return this.mJsons[name];
509536
}
510537

538+
/**
539+
* Returns Object parsed from `CutsomAsset` by given name.
540+
*
541+
* @param {string} name The name of the asset.
542+
* @return {Object} Returns object or null.
543+
*/
544+
getCustomAsset(name) {
545+
return this.mCustomAssets[name];
546+
}
547+
511548
__validateState() {
512549
Debug.assert(this.mState === AssetManagerState.NONE || this.mState === AssetManagerState.FINISHED, 'Illegal state.');
513550
}

src/assets/BVGAsset.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,16 @@ class BVGAsset extends Asset {
6363

6464
if (this.mBakeChildren && namesToBake.length === 0) {
6565
const traverse = nodes => {
66+
nodes = /** @type {Array<GraphicsData>} */(nodes);
67+
6668
if (nodes.length === 0) return;
6769

6870
for (let i = 0, l = nodes.length; i < l; i++) {
6971
if (nodes[i].name) {
7072
namesToBake.push(nodes[i].name);
7173
}
7274

73-
traverse(nodes[i].mNodes);
75+
traverse(/** @type {Array<GraphicsData>} */(nodes[i].mNodes));
7476
}
7577
};
7678

@@ -90,9 +92,10 @@ class BVGAsset extends Asset {
9092
}
9193

9294
const graphics = new Graphics(node, name !== this.mGraphicsData.name);
93-
const renderTexture = new CanvasRenderTexture(graphics.width, graphics.height, Black.driver.renderScaleFactor);
95+
const dpr = 1 / Black.driver.renderScaleFactor;
96+
const renderTexture = new CanvasRenderTexture(graphics.width, graphics.height, 1);
9497

95-
Black.driver.render(graphics, renderTexture, new Matrix());
98+
Black.driver.render(graphics, renderTexture, new Matrix().scale(dpr, dpr));
9699

97100
textures[name] = renderTexture;
98101
}

src/assets/CustomAsset.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* This is abstract class for custom user assets. For example CustomAsset can be used to load video or other data files.
3+
*
4+
* @fires Asset#error
5+
* @fires Asset#complete
6+
*
7+
* @cat assets
8+
* @extends Asset
9+
*/
10+
/* @echo EXPORT */
11+
class CustomAsset extends Asset { }

src/assets/loaders/ImageAssetLoader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class ImageAssetLoader extends AssetLoader {
2323
*/
2424
load() {
2525
this.mImageElement.src = this.mUrl;
26-
this.mImageElement.onload = () => { this.onLoad(); }
27-
this.mImageElement.onerror = () => { this.onError(); }
26+
this.mImageElement.onload = () => this.onLoad();
27+
this.mImageElement.onerror = () => this.onError();
2828
this.mData = this.mImageElement;
2929
}
3030

0 commit comments

Comments
 (0)