Project

General

Profile

« Previous | Next » 

Revision ec4987d4

Added by Leszek Koltunski almost 2 years ago

'Stars' animation: support totalStars up to 5 digits long, i.e. up to 99999.

View differences:

src/main/java/org/distorted/overlays/OverlayStars.java
34 34
import org.distorted.library.type.Dynamic1D;
35 35
import org.distorted.library.type.Dynamic2D;
36 36
import org.distorted.library.type.Dynamic3D;
37
import org.distorted.library.type.Dynamic4D;
38 37
import org.distorted.library.type.Static1D;
39 38
import org.distorted.library.type.Static2D;
40 39
import org.distorted.library.type.Static3D;
......
47 46

  
48 47
public class OverlayStars extends OverlayGeneric implements EffectListener
49 48
{
50
   private static final int DUR_APP =  1000;
51
   private static final int DUR_MOV =  4000;
52
   private static final int DUR_GLO =  2000;
53

  
54
   private static final int[] colors = new int[] {0,0,1,  1,0,1,  1,0,0,  1,1,0,  0,1,0,  1,1,1}; // blue, pink, red, yellow, green, white
55
   private static final int INDEX = 5;
49
   private static final int DUR_APP =  1500;
50
   private static final int DUR_MOV =  3500;
51
   private static final int DUR_GLO =   600;
56 52

  
57 53
   private ListenerOverlay mListener;
58 54
   private DistortedNode mNodeFalling, mNodeCentral;
......
64 60
   private int mBmpW, mBmpH;
65 61
   private float mWidth, mHeight;
66 62
   private Random mRandom;
67
   private long mMoveID, mGlowID, mAlphaID;
63
   private long mMoveID, mGlow1ID, mGlow2ID, mAlphaID;
68 64
   private int mTotalStars, mNewStars;
69 65
   private FragmentEffectAlpha mAlpha;
70 66
   private Dynamic1D mAlphaStrength;
71 67
   private boolean mIncrease;
68
   private float mTextHeight;
72 69

  
73 70
///////////////////////////////////////////////////////////////////////////////////////////////////
74 71

  
......
150 147

  
151 148
///////////////////////////////////////////////////////////////////////////////////////////////////
152 149

  
153
   private void createBitmap(Resources res)
150
   private float computeQuotientAndTextHeight(int total)
151
      {
152
      if( total>=10000 )
153
         {
154
         mTextHeight = 0.610f;
155
         return 0.16f;
156
         }
157
      if( total>= 1000 )
158
         {
159
         mTextHeight = 0.625f;
160
         return 0.20f;
161
         }
162
      if( total>=  100 )
163
         {
164
         mTextHeight = 0.640f;
165
         return 0.26f;
166
         }
167

  
168
      mTextHeight = 0.655f;
169
      return 0.28f;
170
      }
171

  
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173

  
174
   private void createBitmap(Resources res, int total)
154 175
      {
155 176
      mStarBitmap = BitmapFactory.decodeResource(res, R.drawable.star);
156 177
      mBmpW = mStarBitmap.getWidth();
157 178
      mBmpH = mStarBitmap.getHeight();
158 179
      mCountBitmap = Bitmap.createBitmap(mBmpW,mBmpH,Bitmap.Config.ARGB_8888);
159 180
      mCountCanvas = new Canvas(mCountBitmap);
181

  
182
      float quotient = computeQuotientAndTextHeight(total);
183

  
160 184
      mPaint = new Paint();
161 185
      mPaint.setColor(0xff000000);
162
      mPaint.setTextSize(mBmpH*0.28f);
186
      mPaint.setTextSize(mBmpH*quotient);
163 187
      mPaint.setAntiAlias(true);
164 188
      mPaint.setTextAlign(Paint.Align.CENTER);
165 189
      }
......
232 256
      String txt = ""+numStars;
233 257
      mCountBitmap.eraseColor(0x00000000);
234 258
      mCountCanvas.drawBitmap(mStarBitmap,0,0,null);
235
      mCountCanvas.drawText(txt,mBmpW*0.5f,mBmpH*0.64f,mPaint);
259
      mCountCanvas.drawText(txt,mBmpW*0.5f,mBmpH*mTextHeight,mPaint);
236 260
      mTexture.setTexture(mCountBitmap);
237 261
      }
238 262

  
......
244 268
      mScreen = screen;
245 269
      mListener= listener;
246 270
      DataStars stars = (DataStars)data;
247
      mTotalStars = stars.getTotal();
271
      mTotalStars = 7;//stars.getTotal();
248 272
      mNewStars   = stars.getNew();
249 273
      Resources res = stars.getResources();
250 274
      mWidth = mScreen.getWidth();
......
252 276
      mIncrease = mNewStars>0;
253 277
      if( !mIncrease ) mNewStars = -mNewStars;
254 278

  
255
      createBitmap(res);
279
      createBitmap(res, mTotalStars);
256 280
      mNodeFalling = createNodeFalling(mIncrease);
257 281
      mNodeFalling.enableDepthStencil(InternalOutputSurface.NO_DEPTH_NO_STENCIL);
258 282
      mScreen.attach(mNodeFalling);
259 283
      mNodeCentral = createNodeCentral(mTotalStars);
260 284
      mNodeCentral.glDepthMask(false);
261
      mNodeCentral.enableDepthStencil(InternalOutputSurface.NO_DEPTH_NO_STENCIL);
262 285
      mScreen.attach(mNodeCentral);
263 286

  
264 287
      return 0;
265 288
      }
266 289

  
290
///////////////////////////////////////////////////////////////////////////////////////////////////
291

  
292
   private PostprocessEffectGlow constructGlow(boolean firstPhase)
293
      {
294
      Dynamic2D haloRadius = new Dynamic2D(DUR_GLO,0.5f);
295
      Static2D point0 = new Static2D( 0, 0);
296
      Static2D point1 = new Static2D(15,50);
297

  
298
      if( firstPhase )
299
         {
300
         haloRadius.add(point0);
301
         haloRadius.add(point1);
302
         }
303
      else
304
         {
305
         haloRadius.add(point1);
306
         haloRadius.add(point0);
307
         }
308

  
309
      Static4D color = new Static4D(1,1,1,0.5f);
310

  
311
      PostprocessEffectGlow glow = new PostprocessEffectGlow(haloRadius,color);
312
      glow.setQuality(EffectQuality.MEDIUM);
313
      glow.notifyWhenFinished(this);
314

  
315
      return glow;
316
      }
317

  
267 318
///////////////////////////////////////////////////////////////////////////////////////////////////
268 319

  
269 320
   public void effectFinished(long id)
270 321
      {
271 322
      if( id==mMoveID )
272 323
         {
273
         Dynamic2D haloRadius = new Dynamic2D(DUR_GLO,1.0f);
274
         haloRadius.add(new Static2D( 0, 0));
275
         haloRadius.add(new Static2D(15,50));
276
         haloRadius.add(new Static2D( 0, 0));
277

  
278
         Dynamic4D color= new Dynamic4D(DUR_GLO,1.0f);
279
         Static4D P1    = new Static4D(colors[3*INDEX],colors[3*INDEX+1], colors[3*INDEX+2], 0.0f);
280
         Static4D P2    = new Static4D(colors[3*INDEX],colors[3*INDEX+1], colors[3*INDEX+2], 0.5f);
281
         color.add(P1);
282
         color.add(P2);
283
         color.add(P1);
284

  
285
         PostprocessEffectGlow glow = new PostprocessEffectGlow(haloRadius,color);
286
         glow.setQuality(EffectQuality.MEDIUM);
287
         mGlowID = glow.getID();
288
         glow.notifyWhenFinished(this);
324
         PostprocessEffectGlow glow = constructGlow(true);
325
         mGlow1ID = glow.getID();
289 326
         DistortedEffects effects = mNodeCentral.getEffects();
290 327
         effects.apply(glow);
328
         }
329
      if( id==mGlow1ID )
330
         {
291 331
         renderStars(mTotalStars+(mIncrease ? mNewStars : -mNewStars));
332
         PostprocessEffectGlow glow = constructGlow(false);
333
         mGlow2ID = glow.getID();
334
         DistortedEffects effects = mNodeCentral.getEffects();
335
         effects.abortById(mGlow1ID);
336
         effects.apply(glow);
292 337
         }
293
      if( id==mGlowID )
338
      if( id==mGlow2ID )
294 339
         {
340
         DistortedEffects effects = mNodeCentral.getEffects();
341
         effects.abortById(mGlow2ID);
295 342
         createAlphaEffect(false);
296 343
         mAlphaID = mAlpha.getID();
297 344
         mAlpha.notifyWhenFinished(this);
345
         effects.apply(mAlpha);
298 346
         }
299 347
      if( id==mAlphaID )
300 348
         {

Also available in: Unified diff