New: TextureSourceDecorator

  ... information about changes and new features of AndEngine,

New: TextureSourceDecorator

Postby Nicolas Gramlich » Fri Aug 06, 2010 8:03 pm

Hello Community,

today I added the so called TextureSourceDecorators.

In the example below actually a implementation of the a abstract class TextureSourceDecorators called OutlineTextureSourceDecorator i used. What this class does it to draw a 1px colored line to the edge of the Texture right before it is sent to the GPU.
Without OutlineTextureSourceDecorator:
no_outlinetexturesourcedecorator.png
No OutlineTextureSourceDecorator.
no_outlinetexturesourcedecorator.png (114.65 KiB) Viewed 1448 times

With OutlineTextureSourceDecorator
with_outlinetexturesourcedecorator.png
With OutlineTextureSourceDecorator.
with_outlinetexturesourcedecorator.png (134.25 KiB) Viewed 1448 times


While I think this is primarily useful for debugging purposes as you can influence the appearance of Textures through code.

I can also think of some useful things to do with it, like add some color-highlight to a sprite. For example think of a RTS (Real-Time-Strategdy) game where the tanks have a little team-color-indicator or so. So you wouldn't have to put tank-sprites in all possible team-colors into your project.


Code-wise this is very simple. Where you had sth like this before:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. this.mBoxFaceTextureRegion = TextureRegionFactory.createFromAsset(this.mTexture, this, "gfx/face_box.png", 0, 0);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4

You'd now do this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. this.mBoxFaceTextureRegion = TextureRegionFactory.createFromSource(this.mTexture, new OutlineTextureSourceDecorator(new AssetTextureSource(this, "gfx/face_box.png"), Color.RED), 0, 0);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Changeset: http://code.google.com/p/andengine/sour ... 78bf768aee

Best Regards,
Nicolas
Nicolas Gramlich
Site Admin
 
Posts: 1734
Joined: Mon Jun 07, 2010 6:20 pm
Location: Schriesheim, Germany

Re: New: TextureSourceDecorator

Postby manoelramon » Sat Dec 18, 2010 8:19 am

Hi Nicolas,

Just a dumb question...If I create a Shape based on an Rectangle, when I insert on scene the rectangle is filled. Is possible to create a shape rectangle but painting only the boarders (no fill) ?

I know we can draw borders using Canvas, but I am not sure regarding rectangles shapes.

Regards,
Ramon
manoelramon
 
Posts: 12
Joined: Sat Nov 27, 2010 12:18 am

Re: New: TextureSourceDecorator

Postby Nicolas Gramlich » Sun Dec 19, 2010 11:41 am

Hi Ramon,

yes, the easiest way to do this is to wrap an OutlineTextureSourceDecorator around an EmptyTextureSourceDecorator.

Best Regards,
Nicolas
Nicolas Gramlich
Site Admin
 
Posts: 1734
Joined: Mon Jun 07, 2010 6:20 pm
Location: Schriesheim, Germany


Return to Updates

Who is online

Users browsing this forum: No registered users and 3 guests