示例#1
0
  /** Initializes an sprite with an image filepath, and a rect. The offset will be (0,0). */
  public CCSprite(String filepath, CGRect rect) {
    assert filepath != null : "Invalid filename for sprite";

    CCTexture2D texture = CCTextureCache.sharedTextureCache().addImage(filepath);
    if (texture != null) {
      init(texture, rect);
    }
  }
示例#2
0
  /**
   * Initializes an sprite with a CGImageRef and a key The key is used by the CCTextureCache to know
   * if a texture was already created with this CGImage. For example, a valid key
   * is: @"sprite_frame_01". If key is nil, then a new texture will be created each time by the
   * CCTextureCache.
   *
   * @since v0.99.0
   */
  public CCSprite(Bitmap image, String key) {
    assert image != null : "Invalid CGImageRef for sprite";

    // XXX: possible bug. See issue #349. New API should be added
    CCTexture2D texture = CCTextureCache.sharedTextureCache().addImage(image, key);

    CGSize size = texture.getContentSize();
    CGRect rect = CGRect.make(0, 0, size.width, size.height);

    init(texture, rect);
  }
示例#3
0
  /**
   * Initializes an sprite with an image filepath. The rect used will be the size of the image. The
   * offset will be (0,0).
   */
  public CCSprite(String filepath) {
    assert filepath != null : "Invalid filename for sprite";

    CCTexture2D texture = CCTextureCache.sharedTextureCache().addImage(filepath);
    if (texture != null) {
      CGRect rect = CGRect.make(0, 0, 0, 0);
      rect.size = texture.getContentSize();
      init(texture, rect);
    } else {
      ccMacros.CCLOGERROR("CCSprite", "Unable to load texture from file: " + filepath);
    }
  }
示例#4
0
  protected CCParticleSpiral(int p) {
    super(p);

    // duration
    duration = kCCParticleDurationInfinity;

    // Gravity Mode
    emitterMode = kCCParticleModeGravity;

    // Gravity Mode: gravity
    this.setGravity(CGPoint.zero());

    // Gravity Mode: speed of particles
    setSpeed(150);
    setSpeedVar(0);

    // Gravity Mode: radial
    setRadialAccel(-380);
    setRadialAccelVar(0);

    // Gravity Mode: tagential
    setTangentialAccel(45);
    setTangentialAccelVar(0);

    // angle
    angle = 90;
    angleVar = 0;

    // emitter position
    CGSize winSize = CCDirector.sharedDirector().winSize();
    this.setPosition(CGPoint.ccp(winSize.width / 2, winSize.height / 2));
    posVar = CGPoint.zero();

    // life of particles
    life = 12;
    lifeVar = 0;

    // size, in pixels
    startSize = 20.0f;
    startSizeVar = 0.0f;
    endSize = kCCParticleStartSizeEqualToEndSize;

    // emits per second
    emissionRate = totalParticles / life;

    // color of particles
    startColor.r = 0.5f;
    startColor.g = 0.5f;
    startColor.b = 0.5f;
    startColor.a = 1.0f;
    startColorVar.r = 0.5f;
    startColorVar.g = 0.5f;
    startColorVar.b = 0.5f;
    startColorVar.a = 0.0f;
    endColor.r = 0.5f;
    endColor.g = 0.5f;
    endColor.b = 0.5f;
    endColor.a = 1.0f;
    endColorVar.r = 0.5f;
    endColorVar.g = 0.5f;
    endColorVar.b = 0.5f;
    endColorVar.a = 0.0f;

    setTexture(CCTextureCache.sharedTextureCache().addImage("fire.png"));

    // additive
    setBlendAdditive(false);
  }
示例#5
0
 /**
  * purges the cache. It releases the retained instance.
  *
  * @since v0.99.0
  */
 public static void purgeSharedTextureCache() {
   if (_sharedTextureCache != null) {
     _sharedTextureCache.removeAllTextures();
   }
 }