Skip to content

Commit

Permalink
01/20/2012 *0.1 Build 631*
Browse files Browse the repository at this point in the history
--------------------------

* Added methods initializeAsFontMap, drawString, stringWidth to CAAT.SpriteImage. Those methods allow to
  draw strings via textured fonts. Every character will be defined besides x,y,width,height in texture,
  by xoffset, yoffset, xadvance.
* Removed unneeded actor initialization inverse matrices.
  • Loading branch information
hyperandroid committed Jan 20, 2012
1 parent 477e5d4 commit 7d35732
Show file tree
Hide file tree
Showing 16 changed files with 4,644 additions and 4,369 deletions.
6 changes: 3 additions & 3 deletions build/caat-box2d-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions build/caat-box2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Version: 0.1 build: 628
Version: 0.1 build: 632
Created on:
DATE: 2012-01-20
TIME: 02:02:22
DATE: 2012-01-21
TIME: 00:52:32
*/


Expand Down
80 changes: 40 additions & 40 deletions build/caat-css-min.js

Large diffs are not rendered by default.

95 changes: 87 additions & 8 deletions build/caat-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Version: 0.1 build: 628
Version: 0.1 build: 632
Created on:
DATE: 2012-01-20
TIME: 02:02:22
DATE: 2012-01-21
TIME: 00:52:32
*/


Expand Down Expand Up @@ -5041,16 +5041,18 @@ var cp1= proxy(

this.modelViewMatrix= new CAAT.Matrix();
this.worldModelViewMatrix= new CAAT.Matrix();
/*
this.modelViewMatrixI= new CAAT.Matrix();
this.worldModelViewMatrixI= new CAAT.Matrix();
this.tmpMatrix= new CAAT.Matrix();
*/

return this;
};

CAAT.Actor.prototype= {

tmpMatrix : null,
// tmpMatrix : null,

lifecycleListenerList: null, // Array of life cycle listener
behaviorList: null, // Array of behaviors to apply to the Actor
Expand Down Expand Up @@ -9938,12 +9940,13 @@ CAAT.RegisterDirector= function __CAATGlobal_RegisterDirector(director) {

(function() {

CAAT.SpriteImageHelper= function(x,y,w,h) {
CAAT.SpriteImageHelper= function(x,y,w,h, iw, ih) {
this.x= x;
this.y= y;
this.width= w;
this.height= h;

this.setGL( x/iw, y/ih, (x+w-1)/iw, (y+h-1)/ih );
return this;
};

Expand Down Expand Up @@ -10165,7 +10168,7 @@ CAAT.RegisterDirector= function __CAATGlobal_RegisterDirector(director) {
var u1 = u + w;
var v1 = v + h;

helper= new CAAT.SpriteImageHelper().setGL(
helper= new CAAT.SpriteImageHelper(u,v,(u1-u),(v1-v),tp.width,tp.height).setGL(
u / tp.width,
v / tp.height,
u1 / tp.width,
Expand All @@ -10179,7 +10182,7 @@ CAAT.RegisterDirector= function __CAATGlobal_RegisterDirector(director) {
sx0 = ((i % this.columns) | 0) * this.singleWidth;
sy0 = ((i / this.columns) | 0) * this.singleHeight;

helper= new CAAT.SpriteImageHelper( sx0, sy0, this.singleWidth, this.singleHeight );
helper= new CAAT.SpriteImageHelper( sx0, sy0, this.singleWidth, this.singleHeight, image.width, image.height );
this.mapInfo[i]= helper;
}
}
Expand Down Expand Up @@ -10557,9 +10560,52 @@ CAAT.RegisterDirector= function __CAATGlobal_RegisterDirector(director) {
value.x,
value.y,
value.width,
value.height
value.height,
image.width,
image.height
);

this.mapInfo[key]= helper;

// set a default spriteIndex
if ( !count ) {
this.setAnimationImageIndex( [key] );
}

count++;
}

return this;
},

/**
*
* @param image
* @param map
*/
initializeAsFontMap : function( image, map ) {
this.initialize( image, 1, 1 );

var key;
var helper;
var count=0;

for( key in map ) {
var value= map[key];

helper= new CAAT.SpriteImageHelper(
value.x,
value.y,
value.width,
value.height,
image.width,
image.height
);

helper.xoffset= typeof value.xoffset==='undefined' ? 0 : value.xoffset;
helper.yoffset= typeof value.yoffset==='undefined' ? 0 : value.yoffset;
helper.xadvance= typeof value.xadvance==='undefined' ? value.width : value.xadvance;

this.mapInfo[key]= helper;

// set a default spriteIndex
Expand All @@ -10571,6 +10617,39 @@ CAAT.RegisterDirector= function __CAATGlobal_RegisterDirector(director) {
}

return this;
},

stringWidth : function( str ) {
var i,l,w=0,charInfo;

for( i=0, l=str.length; i<l; i++ ) {
charInfo= this.mapInfo[ str.charAt(i) ];
if ( charInfo ) {
w+= charInfo.xadvance;
}
}

return w;
},

drawString : function( ctx, str, x, y ) {
var i, l, charInfo, w;

for( i=0, l=str.length; i<l; i++ ) {
charInfo= this.mapInfo[ str.charAt(i) ];
if ( charInfo ) {
w= charInfo.width;
ctx.drawImage(
this.image,
charInfo.x, charInfo.y,
w, charInfo.height,

x + charInfo.xoffset, y + charInfo.yoffset,
w, charInfo.height );

x+= charInfo.xadvance;
}
}
}


Expand Down
Loading

0 comments on commit 7d35732

Please sign in to comment.