Skip to content

Commit 7a8890a

Browse files
Width/height are not required for animations to show, all objects have initial animation which is just iterates throught all frames. So SpriteAnimation can work even without any animations declared. window.flash.soundMuted = true / false added, sound can be muted globally.
1 parent 1bab504 commit 7a8890a

File tree

16 files changed

+164
-86
lines changed

16 files changed

+164
-86
lines changed

AssetsManager.jar

-5.63 MB
Binary file not shown.
-41 Bytes
Binary file not shown.
Binary file not shown.

assets manager sources/src/com/flashjs/assetsmanager/Main.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ static void copyFileToMP3(File source) throws IllegalArgumentException, InputFor
114114

115115
AudioAttributes audio = new AudioAttributes();
116116
audio.setCodec("libmp3lame");
117-
audio.setBitRate(new Integer(96000));
117+
audio.setBitRate(new Integer(64000));
118118
audio.setChannels(new Integer(2));
119-
audio.setSamplingRate(new Integer(44100));
119+
audio.setSamplingRate(new Integer(22050));
120120

121121
EncodingAttributes attrs = new EncodingAttributes();
122122
attrs.setFormat("mp3");
@@ -132,9 +132,9 @@ static void copyFileToOgg(File source) throws IllegalArgumentException, InputFor
132132

133133
AudioAttributes audio = new AudioAttributes();
134134
audio.setCodec("libvorbis");
135-
audio.setBitRate(new Integer(128000));
135+
audio.setBitRate(new Integer(64000));
136136
audio.setChannels(new Integer(2));
137-
audio.setSamplingRate(new Integer(44100));
137+
audio.setSamplingRate(new Integer(22050));
138138

139139
EncodingAttributes attrs = new EncodingAttributes();
140140
attrs.setFormat("ogg");

flash.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,10 @@ ns.Matrix2D = Matrix2D;
18121812
}
18131813

18141814
p.play = function(){
1815+
if (flash.soundMuted === true) {
1816+
return;
1817+
}
1818+
18151819
this.audio = this.context.createBufferSource();
18161820
this.gain = this.context.createGainNode();
18171821
this.audio.connect(this.gain);
@@ -1924,6 +1928,9 @@ ns.Matrix2D = Matrix2D;
19241928
}
19251929

19261930
p.play = function(){
1931+
if (flash.soundMuted === true) {
1932+
return;
1933+
}
19271934
this.audio.play();
19281935
}
19291936

@@ -2019,6 +2026,9 @@ ns.Matrix2D = Matrix2D;
20192026
}
20202027

20212028
p.play = function(){
2029+
if (flash.soundMuted === true) {
2030+
return;
2031+
}
20222032
this._audio.loop = this.loop;
20232033
if (this._audio.paused){
20242034
if (this._audio.loop && this.codec === 'ogg'){
@@ -2128,11 +2138,15 @@ ns.Matrix2D = Matrix2D;
21282138
}
21292139

21302140
image.onload = (function(arg){
2131-
if (callback !== undefined) callback(arg);
2141+
if (callback !== undefined) {
2142+
callback(arg);
2143+
}
21322144
}).bind(this);
21332145

21342146
image.onerror = function(arg){
2135-
if (errorCallback !== undefined) errorCallback(arg);
2147+
if (errorCallback !== undefined) {
2148+
errorCallback(arg);
2149+
}
21362150
}
21372151

21382152
if (false){
@@ -2145,7 +2159,7 @@ ns.Matrix2D = Matrix2D;
21452159
}
21462160

21472161
ImageLoader.checkLoaderType = function(URL, options){
2148-
var extension = (getFileExtension(URL));
2162+
var extension = (w.getFileExtension(URL));
21492163
if ((extension === 'jpg') || (extension === 'png') || (extension === 'gif')){
21502164
return true;
21512165
}

flashdom.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,10 @@ if (flash.cssTransformFunction === undefined) {
16111611
}
16121612

16131613
p.play = function(){
1614+
if (flash.soundMuted === true) {
1615+
return;
1616+
}
1617+
16141618
this.audio = this.context.createBufferSource();
16151619
this.gain = this.context.createGainNode();
16161620
this.audio.connect(this.gain);
@@ -1723,6 +1727,9 @@ if (flash.cssTransformFunction === undefined) {
17231727
}
17241728

17251729
p.play = function(){
1730+
if (flash.soundMuted === true) {
1731+
return;
1732+
}
17261733
this.audio.play();
17271734
}
17281735

@@ -1818,6 +1825,9 @@ if (flash.cssTransformFunction === undefined) {
18181825
}
18191826

18201827
p.play = function(){
1828+
if (flash.soundMuted === true) {
1829+
return;
1830+
}
18211831
this._audio.loop = this.loop;
18221832
if (this._audio.paused){
18231833
if (this._audio.loop && this.codec === 'ogg'){
@@ -1927,11 +1937,15 @@ if (flash.cssTransformFunction === undefined) {
19271937
}
19281938

19291939
image.onload = (function(arg){
1930-
if (callback !== undefined) callback(arg);
1940+
if (callback !== undefined) {
1941+
callback(arg);
1942+
}
19311943
}).bind(this);
19321944

19331945
image.onerror = function(arg){
1934-
if (errorCallback !== undefined) errorCallback(arg);
1946+
if (errorCallback !== undefined) {
1947+
errorCallback(arg);
1948+
}
19351949
}
19361950

19371951
if (false){
@@ -1944,7 +1958,7 @@ if (flash.cssTransformFunction === undefined) {
19441958
}
19451959

19461960
ImageLoader.checkLoaderType = function(URL, options){
1947-
var extension = (getFileExtension(URL));
1961+
var extension = (w.getFileExtension(URL));
19481962
if ((extension === 'jpg') || (extension === 'png') || (extension === 'gif')){
19491963
return true;
19501964
}

lib/flash.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/flashdom.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/display-canvas/SpriteSheet.js

+74-65
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,67 @@
11
/*
2-
* SpriteSheet is a part of FlashJS engine
3-
*
4-
* http://flashjs.com
5-
*
6-
* Copyright (c) 2011 - 2012 pixelsresearch.com,
7-
*/
2+
* SpriteSheet is a part of FlashJS engine
3+
*
4+
* http://flashjs.com
5+
*
6+
* Copyright (c) 2011 - 2013 pixelsresearch.com,
7+
*/
88

99
(function(w){
10-
var SpriteSheet = function(image, width, height, total, animationsData){
11-
this.data = image;
10+
var SpriteSheet = function(image, width, height, total, animationsData){
11+
this.data = image;
1212

1313
this.frames = [];
1414
this.flippedFrames = [];
1515
this.animations = {};
1616

1717
this._frameWidth = width;
18-
this._frameHeight = height;
19-
this._totalFrames = total;
20-
this._animationsData = animationsData;
21-
22-
this.initAnimations();
23-
24-
if (image !== undefined){
25-
if (image.constructor == Array){
26-
this.fillFramesFromImagesArray();
27-
} else {
28-
this.fillFramesFromSpritesheet();
29-
}
30-
}
31-
}
32-
33-
p = SpriteSheet.prototype;
34-
35-
p.data = {};
36-
37-
p._frameWidth = 0;
38-
p._frameHeight = 0;
39-
p._totalFrames = 0;
40-
41-
p.fillFramesFromSpritesheet = function(){
42-
var rows = Math.round(this.data.width / this._frameWidth);
43-
var columns = Math.round(this.data.height / this._frameHeight);
44-
45-
for (var c = 0; c < columns; c++){
46-
for (var r = 0; r < rows; r++){
47-
if (this.frames.length <= this._totalFrames){
48-
var canvas = document.createElement("canvas");
49-
50-
canvas.width = this._frameWidth;
51-
canvas.height = this._frameHeight;
52-
53-
var context = canvas.getContext("2d");
54-
context.drawImage(this.data, this._frameWidth * r, this._frameHeight * c,this._frameWidth,this._frameHeight,0,0,this._frameWidth,this._frameHeight);
55-
this.frames.push(canvas);
56-
}
57-
}
58-
}
59-
}
60-
61-
p.fillFramesFromImagesArray = function(){
62-
this.frames = this.data;
63-
}
18+
this._frameHeight = height;
19+
this._totalFrames = total;
20+
this._animationsData = animationsData;
21+
22+
this.initAnimations();
23+
24+
if (image !== undefined){
25+
if (image.constructor == Array){
26+
this.fillFramesFromImagesArray();
27+
} else {
28+
this.fillFramesFromSpritesheet();
29+
}
30+
}
31+
}
32+
33+
var p = SpriteSheet.prototype;
34+
35+
p.data = {};
36+
37+
p.defaultAnimationName = 'default';
38+
p._frameWidth = 0;
39+
p._frameHeight = 0;
40+
p._totalFrames = 0;
41+
42+
p.fillFramesFromSpritesheet = function(){
43+
var rows = Math.round(this.data.width / this._frameWidth);
44+
var columns = Math.round(this.data.height / this._frameHeight);
45+
46+
for (var c = 0; c < columns; c++){
47+
for (var r = 0; r < rows; r++){
48+
if (this.frames.length <= this._totalFrames){
49+
var canvas = document.createElement("canvas");
50+
51+
canvas.width = this._frameWidth;
52+
canvas.height = this._frameHeight;
53+
54+
var context = canvas.getContext("2d");
55+
context.drawImage(this.data, this._frameWidth * r, this._frameHeight * c,this._frameWidth,this._frameHeight,0,0,this._frameWidth,this._frameHeight);
56+
this.frames.push(canvas);
57+
}
58+
}
59+
}
60+
}
61+
62+
p.fillFramesFromImagesArray = function(){
63+
this.frames = this.data;
64+
}
6465

6566
p.fillFlippedFrames = function(){
6667
for (var i = 0; i < this.frames.length; i++){
@@ -85,17 +86,25 @@
8586
return undefined;
8687
}
8788

88-
p.initAnimations = function(){
89-
for(var animationName in this._animationsData) {
90-
this.animations[animationName] = {
91-
"name":animationName,
92-
"startFrame":this._animationsData[animationName].startFrame,
93-
"endFrame":this._animationsData[animationName].endFrame,
94-
"interval":this._animationsData[animationName].interval,
89+
p.initAnimations = function(){
90+
for(var animationName in this._animationsData) {
91+
this.animations[animationName] = {
92+
"name":animationName,
93+
"startFrame":this._animationsData[animationName].startFrame,
94+
"endFrame":this._animationsData[animationName].endFrame,
95+
"interval":this._animationsData[animationName].interval,
9596
"makeFlip":this._animationsData[animationName].makeFlip,
96-
"looped":this._animationsData[animationName].looped};
97-
}
98-
}
97+
"looped":this._animationsData[animationName].looped};
98+
}
99+
100+
this.animations[this.defaultAnimationName] = {
101+
endFrame: this._totalFrames,
102+
interval: 50,
103+
looped: 1,
104+
makeFlip: 0,
105+
startFrame: 1
106+
};
107+
}
99108

100-
w.flash.cloneToNamespaces(SpriteSheet, 'SpriteSheet');
109+
w.flash.cloneToNamespaces(SpriteSheet, 'SpriteSheet');
101110
})(window);

src/loading/AnimationLoader.js

+24-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* http://flashjs.com
55
*
6-
* Copyright (c) 2011 - 2012 pixelsresearch.com,
6+
* Copyright (c) 2011 - 2013 pixelsresearch.com,
77
*/
88

99
(function (w) {
@@ -12,9 +12,10 @@
1212
this.url = URL || w.webkitURL;
1313
this.options = options;
1414
this.callback = callback;
15-
this.spriteSheet = new SpriteSheet(undefined, options.width * options.scale, options.height * options.scale, options.framesTotal, options.animations);
1615
this.context = context;
1716
this.frames = [];
17+
this.spriteSheet = {};
18+
this.createSpritesheet();
1819

1920
if (URL[URL.length - 1] === "/") {
2021
this.addAssetsToLoader();
@@ -79,6 +80,18 @@
7980
this.framesToLoad--;
8081
this.frames[item.frameNumber] = item.data;
8182

83+
if (this.spriteSheet._frameWidth === undefined || this.spriteSheet._frameHeight === undefined) {
84+
if (this.options.width === undefined) {
85+
this.options.width = item.data.width;
86+
this.spriteSheet._frameWidth = this.options.width;
87+
}
88+
89+
if (this.options.height === undefined) {
90+
this.options.height = item.data.height;
91+
this.spriteSheet._frameHeight = this.options.height;
92+
}
93+
}
94+
8295
if (this.framesToLoad === 0) {
8396
this.spriteSheet.data = this.frames;
8497
this.spriteSheet.fillFramesFromImagesArray();
@@ -87,9 +100,15 @@
87100
}
88101
}
89102

90-
AnimationLoader.checkLoaderType = function (URL, options) {
91-
return ((getFileExtension(URL) === '') || (options.animations !== undefined));
103+
p.createSpritesheet = function() {
104+
if (this.options.framesTotal === undefined) {
105+
throw new Error('Asset`s ' + this.options.id + ' framesTotal property is undefined');
106+
}
107+
this.spriteSheet = new SpriteSheet(undefined, (this.options.width * this.options.scale) || undefined, (this.options.height * this.options.scale) || undefined, this.options.framesTotal, this.options.animations);
92108
}
93109

94-
w.flash.cloneToNamespaces(AnimationLoader, 'AnimationLoader');
110+
AnimationLoader.checkLoaderType = function (URL, options) {
111+
var extension = getFileExtension(URL);
112+
return ((extension === '') || (options.animations !== undefined));
113+
}
95114
})(window);

src/loading/ImageLoader.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@
2323
}
2424

2525
image.onload = (function(arg){
26-
if (callback !== undefined) callback(arg);
26+
if (callback !== undefined) {
27+
callback(arg);
28+
}
2729
}).bind(this);
2830

2931
image.onerror = function(arg){
30-
if (errorCallback !== undefined) errorCallback(arg);
32+
if (errorCallback !== undefined) {
33+
errorCallback(arg);
34+
}
3135
}
3236

3337
if (false){
@@ -40,7 +44,7 @@
4044
}
4145

4246
ImageLoader.checkLoaderType = function(URL, options){
43-
var extension = (getFileExtension(URL));
47+
var extension = (w.getFileExtension(URL));
4448
if ((extension === 'jpg') || (extension === 'png') || (extension === 'gif')){
4549
return true;
4650
}

src/media/APISound.js

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
}
5656

5757
p.play = function(){
58+
if (flash.soundMuted === true) {
59+
return;
60+
}
61+
5862
this.audio = this.context.createBufferSource();
5963
this.gain = this.context.createGainNode();
6064
this.audio.connect(this.gain);

0 commit comments

Comments
 (0)