onaluf / gameQuery

a javascript game engine with jQuery
http://gamequeryjs.com
633 stars 161 forks source link

Contribution to the gamequery #13

Open jarodium opened 12 years ago

jarodium commented 12 years ago

Hello selim

I would like to contribute some code to gamequery. Maybe it is not the time but I hope you find it useful for the tilemap editor tool.

Here is the code

var templ_dir = "BASE SITE DIRECTORY"; var templ_imgs = templ_dir+"SPRITE DIRECTORY"; var sprDelta = 32; //default sprite delta ( for use on tilemap, since all animations have the same delta ) var animations = [];

//this sets up a simple sprite into the animations array function setupSprite(image,offsetx,offsety) { animations.push(new $.gameQuery.Animation({ imageURL: templ_imgs+image, type: $.gameQuery.ANIMATION_ONCE, numberOfFrame: 1, delta: sprDelta, rate: 30, offsetx: offsetx, offsety: offsety }));

}

//this allows to setup a building matrix on the animations array function setupSpriteBuilding(image,startX,startY) { //this needs some work, because this assumes that the building is composed by 9 tiles, on a 3 rows and 2 colums //anyway the buildings can be organized in various layouts in the spritesheet. for(i=0;i<2; i++) { for(j=0; j<3; j++) { setupSprite(image,startX+(sprDelta_j),startY+(sprDelta_i)); } } }

you call'em like this:

setupSprite('TileA5.png',0,32); setupSprite('TileA5.png',0,64);

setupSpriteBuilding('edificios.png',192,64);

I'm working on how to make map placement easier, but i'll get there as soon as I can.

Best regards jarodium

Munsio commented 10 years ago

Hey there,

At first, thanks for such a great DOM based game Framework.

I made a little Timer plugin you can find it here: https://github.com/MrTool/gameQuery-plugins