My favorites | Sign in
Project Home Downloads Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package org.anddev.andengine.examples;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.background.ColorBackground;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.util.FPSLogger;
import org.anddev.andengine.extension.svg.adt.ISVGColorMapper;
import org.anddev.andengine.extension.svg.adt.SVGDirectColorMapper;
import org.anddev.andengine.extension.svg.opengl.texture.atlas.bitmap.SVGBitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BuildableBitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.source.IBitmapTextureAtlasSource;
import org.anddev.andengine.opengl.texture.atlas.buildable.builder.BlackPawnTextureBuilder;
import org.anddev.andengine.opengl.texture.atlas.buildable.builder.ITextureBuilder.TextureAtlasSourcePackingException;
import org.anddev.andengine.opengl.texture.region.BaseTextureRegion;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;
import org.anddev.andengine.util.Debug;

import android.graphics.Color;

/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga
*
* @author Nicolas Gramlich
* @since 13:58:12 - 21.05.2011
*/
public class SVGTextureRegionExample extends BaseExample {
// ===========================================================
// Constants
// ===========================================================

private static final int CAMERA_WIDTH = 720;
private static final int CAMERA_HEIGHT = 480;

private static final int SIZE = 128;

private static final int COUNT = 12;
private static final int COLUMNS = 4;
private static final int ROWS = (int)Math.ceil((float)COUNT / COLUMNS);

// ===========================================================
// Fields
// ===========================================================

private Camera mCamera;
private BuildableBitmapTextureAtlas mBuildableBitmapTextureAtlas;
private BaseTextureRegion[] mSVGTestTextureRegions;

// ===========================================================
// Constructors
// ===========================================================

// ===========================================================
// Getter & Setter
// ===========================================================

// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================

@Override
public Engine onLoadEngine() {
this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera));
}

@Override
public void onLoadResources() {
this.mBuildableBitmapTextureAtlas = new BuildableBitmapTextureAtlas(1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
SVGBitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");

this.mSVGTestTextureRegions = new BaseTextureRegion[COUNT];
int i = 0;
this.mSVGTestTextureRegions[i++] = SVGBitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBuildableBitmapTextureAtlas, this, "chick.svg", 16, 16);
this.mSVGTestTextureRegions[i++] = SVGBitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBuildableBitmapTextureAtlas, this, "chick.svg", 32, 32);
this.mSVGTestTextureRegions[i++] = SVGBitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBuildableBitmapTextureAtlas, this, "chick.svg", 64, 64);
this.mSVGTestTextureRegions[i++] = SVGBitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBuildableBitmapTextureAtlas, this, "chick.svg", 128, 128);
this.mSVGTestTextureRegions[i++] = SVGBitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBuildableBitmapTextureAtlas, this, "badge.svg", 16, 16);
this.mSVGTestTextureRegions[i++] = SVGBitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBuildableBitmapTextureAtlas, this, "badge.svg", 64, 64);
this.mSVGTestTextureRegions[i++] = SVGBitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBuildableBitmapTextureAtlas, this, "badge.svg", 128, 128, new ISVGColorMapper() {
@Override
public Integer mapColor(final Integer pColor) {
if(pColor == null) {
return null;
} else {
/* Swap blue and green channel. */
return Color.argb(0, Color.red(pColor), Color.blue(pColor), Color.green(pColor));
}
}
});
this.mSVGTestTextureRegions[i++] = SVGBitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBuildableBitmapTextureAtlas, this, "badge.svg", 256, 256, new ISVGColorMapper() {
@Override
public Integer mapColor(final Integer pColor) {
if(pColor == null) {
return null;
} else {
/* Swap red and green channel. */
return Color.argb(0, Color.green(pColor), Color.red(pColor), Color.blue(pColor));
}
}
});
this.mSVGTestTextureRegions[i++] = SVGBitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBuildableBitmapTextureAtlas, this, "pacdroid.svg", 64, 64, 2, 2);
this.mSVGTestTextureRegions[i++] = SVGBitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBuildableBitmapTextureAtlas, this, "pacdroid.svg", 256, 256, 2, 2);
final SVGDirectColorMapper angryPacDroidSVGColorMapper = new SVGDirectColorMapper();
angryPacDroidSVGColorMapper.addColorMapping(0xA7CA4A, 0xEA872A);
angryPacDroidSVGColorMapper.addColorMapping(0xC1DA7F, 0xFAA15F);
this.mSVGTestTextureRegions[i++] = SVGBitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBuildableBitmapTextureAtlas, this, "pacdroid.svg", 256, 256, angryPacDroidSVGColorMapper, 2, 2);
this.mSVGTestTextureRegions[i++] = SVGBitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBuildableBitmapTextureAtlas, this, "pacdroid_apples.svg", 256, 256, 2, 2);

try {
this.mBuildableBitmapTextureAtlas.build(new BlackPawnTextureBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(1));
} catch (final TextureAtlasSourcePackingException e) {
Debug.e(e);
}

this.mEngine.getTextureManager().loadTexture(this.mBuildableBitmapTextureAtlas);
}

@Override
public Scene onLoadScene() {
this.mEngine.registerUpdateHandler(new FPSLogger());

final Scene scene = new Scene();
scene.setBackground(new ColorBackground(0.5f, 0.5f, 0.5f));

for(int i = 0; i < COUNT; i++) {
final int row = i / COLUMNS;
final int column = i % COLUMNS;

final float centerX = this.mCamera.getWidth() / (COLUMNS + 1) * (column + 1);
final float centerY = this.mCamera.getHeight() / (ROWS + 1) * (row + 1);

final float x = centerX - SIZE * 0.5f;
final float y = centerY - SIZE * 0.5f;
final BaseTextureRegion baseTextureRegion = this.mSVGTestTextureRegions[i];
if(baseTextureRegion instanceof TextureRegion) {
final TextureRegion textureRegion = (TextureRegion)baseTextureRegion;
scene.attachChild(new Sprite(x, y, SIZE, SIZE, textureRegion));
} else if(baseTextureRegion instanceof TiledTextureRegion) {
final TiledTextureRegion tiledTextureRegion = (TiledTextureRegion)baseTextureRegion;
final AnimatedSprite animatedSprite = new AnimatedSprite(x, y, SIZE, SIZE, tiledTextureRegion);
animatedSprite.animate(500);
scene.attachChild(animatedSprite);
}
}

return scene;
}

@Override
public void onLoadComplete() {

}

// ===========================================================
// Methods
// ===========================================================

// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}

Change log

dea4a6fe72f9 by Nicolas Gramlich <ngraml...@zynga.com> on Aug 2, 2011   Diff
Adaptions to AndEngine changes.Added
TexturePackerExample. (Waiting for public
non-beta version of TexturePacker before
pushing).
Go to: 
Project members, sign in to write a code review

Older revisions

eef5877c2fc4 by Nicolas Gramlich <ngraml...@zynga.com> on Jul 27, 2011   Diff
Added copyright notice where missing.
ac7a595d9d6f by Nicolas Gramlich <ngraml...@zynga.com> on Jul 15, 2011   Diff
Merge with b5142cccd04c60b538952eb1c06
63926a938606e.
2b26f37114e5 by NicolasGramlich on Jul 14, 2011   Diff
Updated examples due to Texture
refactoring.
Added PVRTextureExample.
Damn, this should have been on the
CompressedTexture
All revisions of this file

File info

Size: 8376 bytes, 171 lines
Powered by Google Project Hosting