Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Joncom

It would be nice if ig.Image.draw() contained flipX and flipY parameters.

Currently only drawTile() has it, which is handy... but I've had to inject() the same feature into draw() when I don't want to be restricted to using a whole tile.

EDIT

If anybody is interested in how this is done, I found this useful:

ig.Image.inject({
	draw: function( targetX, targetY, sourceX, sourceY, width, height, flipX, flipY ) {
		if( !this.loaded ) { return; }
		
		var scale = ig.system.scale;
		sourceX = sourceX ? sourceX * scale : 0;
		sourceY = sourceY ? sourceY * scale : 0;
		width = (width ? width : this.width) * scale;
		height = (height ? height : this.height) * scale;
		
		var scaleX = flipX ? -1 : 1;
		var scaleY = flipY ? -1 : 1;
		
		if( flipX || flipY ) {
			ig.system.context.save();
			ig.system.context.scale( scaleX, scaleY );
		}
		
		ig.system.context.drawImage( 
			this.data, sourceX, sourceY, width, height,
			ig.system.getDrawPos(targetX) * scaleX - (flipX ? width : 0), 
			ig.system.getDrawPos(targetY) * scaleY - (flipY ? height : 0),
			width, height
		);

		if( flipX || flipY ) {
			ig.system.context.restore();
		}
		
		ig.Image.drawCount++;
	},
});

1 decade ago by Arantor

Do note that the only time you'll ever need to manually do this is for cases where you're drawing images that are neither tiles not entities (since you can set flip.x and flip.y for entities and it'll draw them appropriately flipped, as well as rotated should you so desire)

(For entity purposes it's implemented via the animation sheets, which internally use drawTile)

I guess it might be useful for some HUD cases but generally I'd just pre-prepare the assets to save processing power at drawtime...
Page 1 of 1
« first « previous next › last »