New Code For 2D sprite.

edited February 2013 in Development
My friend modify the library file and allow the use of 2D sprite in the jquery.gamequery-0.7.0.js

Around line 230-240
ANIMATION_GRID:		  64,


Around line 200
under the "var defaults = {", add in :
				columnsCount:  0,
rowHeight: 0,
startFrame: 0


And then at the bottom of "// "public" attributes:", add in :
			this.columnsCount  = options.columnsCount;
this.rowHeight = options.rowHeight;
this.startFrame = options.startFrame;

Around line 390-400
Add in the else-if code for the animation.
//CUSTOM FUNCTION
else if((gameQuery.animation.type & $.gameQuery.ANIMATION_GRID) && (gameQuery.animation.numberOfFrame > 1)) {
 
 
var column = (gameQuery.animation.startFrame + gameQuery.currentFrame) % gameQuery.animation.columnsCount;
var row = Math.floor((gameQuery.animation.startFrame + gameQuery.currentFrame) / gameQuery.animation.columnsCount);
 
//console.log(column + " " + row);
$(this).css("background-position",""+(-gameQuery.animation.offsetx-gameQuery.animation.delta*column)+"px "+(-gameQuery.animation.offsety-gameQuery.animation.rowHeight*row)+"px");
 
}

Comments

  • edited February 2013
    For Usage:
    var IrvineAnimation = new $.gameQuery.Animation({ 
    imageURL: "FF8Sprites.png",
    numberOfFrame: 12,
    delta: 50,
    rowHeight: 64,
    startFrame: 0,
    columnsCount: 3,
    rate: 120,
    offsetx: 0,
    offsety: 258,
    type: $.gameQuery.ANIMATION_GRID | $.gameQuery.ANIMATION_PINGPONG});


    The new build function is still associate well with other function.
    The calculation need to capture more information.
    rowHeight : it's the row height for each sprite display
    startFrame : the startFrame is to determine where sprite frame start. It can optimize the use of sprite in the sprite sheet.
    columnCount : capture the number of column in the sprite sheet.
  • edited February 2013
    Hope this can help :)
    Hope the developer can put this code in, for the next update.
Sign In or Register to comment.