コード例 #1
0
 private void loadImage(ParticleEmitter emitter) {
   final String imagePath = emitter.getImagePath();
   String imageName = new File(imagePath.replace('\\', '/')).getName();
   try {
     FileHandle file;
     if (imagePath.equals("particle.png")) file = Gdx.files.classpath(imagePath);
     else file = Gdx.files.absolute(imagePath);
     emitter.setSprite(new Sprite(new Texture(file)));
   } catch (GdxRuntimeException ex) {
     ex.printStackTrace();
     EventQueue.invokeLater(
         new Runnable() {
           public void run() {
             JOptionPane.showMessageDialog(
                 ParticleEditor.this, "Error loading image:\n" + imagePath);
           }
         });
     emitter.setImagePath(null);
   }
 }
コード例 #2
0
 public ImageIcon getIcon(ParticleEmitter emitter) {
   ParticleData data = particleData.get(emitter);
   if (data == null) particleData.put(emitter, data = new ParticleData());
   String imagePath = emitter.getImagePath();
   if (data.icon == null && imagePath != null) {
     try {
       URL url;
       File file = new File(imagePath);
       if (file.exists()) url = file.toURI().toURL();
       else {
         url = ParticleEditor.class.getResource(imagePath);
         if (url == null) return null;
       }
       data.icon = new ImageIcon(url);
     } catch (MalformedURLException ex) {
       ex.printStackTrace();
     }
   }
   return data.icon;
 }
コード例 #3
0
    public void render() {
      int viewWidth = Gdx.graphics.getWidth();
      int viewHeight = Gdx.graphics.getHeight();

      float delta = Gdx.graphics.getDeltaTime();

      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

      if ((pixelsPerMeter.getValue() != pixelsPerMeterPrev)
          || (zoomLevel.getValue() != zoomLevelPrev)) {
        if (pixelsPerMeter.getValue() <= 0) {
          pixelsPerMeter.setValue(1);
        }

        worldCamera.setToOrtho(
            false, viewWidth / pixelsPerMeter.getValue(), viewHeight / pixelsPerMeter.getValue());
        worldCamera.zoom = zoomLevel.getValue();
        worldCamera.update();
        effect.setPosition(worldCamera.viewportWidth / 2, worldCamera.viewportHeight / 2);
        zoomLevelPrev = zoomLevel.getValue();
        pixelsPerMeterPrev = pixelsPerMeter.getValue();
      }

      spriteBatch.setProjectionMatrix(worldCamera.combined);

      spriteBatch.begin();
      spriteBatch.enableBlending();
      spriteBatch.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

      if (bgImage != null) {
        bgImage.setPosition(
            viewWidth / 2 - bgImage.getWidth() / 2, viewHeight / 2 - bgImage.getHeight() / 2);
        bgImage.draw(spriteBatch);
      }

      activeCount = 0;
      boolean complete = true;
      for (ParticleEmitter emitter : effect.getEmitters()) {
        if (emitter.getSprite() == null && emitter.getImagePath() != null) loadImage(emitter);
        boolean enabled = isEnabled(emitter);
        if (enabled) {
          if (emitter.getSprite() != null) emitter.draw(spriteBatch, delta);
          activeCount += emitter.getActiveCount();
          if (!emitter.isComplete()) complete = false;
        }
      }
      if (complete) effect.start();

      maxActive = Math.max(maxActive, activeCount);
      maxActiveTimer += delta;
      if (maxActiveTimer > 3) {
        maxActiveTimer = 0;
        lastMaxActive = maxActive;
        maxActive = 0;
      }

      if (mouseDown) {
        // gl.drawLine(mouseX - 6, mouseY, mouseX + 5, mouseY);
        // gl.drawLine(mouseX, mouseY - 5, mouseX, mouseY + 6);
      }

      spriteBatch.setProjectionMatrix(textCamera.combined);

      font.draw(spriteBatch, "FPS: " + Gdx.graphics.getFramesPerSecond(), 5, 15);
      font.draw(spriteBatch, "Count: " + activeCount, 5, 35);
      font.draw(spriteBatch, "Max: " + lastMaxActive, 5, 55);
      font.draw(spriteBatch, (int) (getEmitter().getPercentComplete() * 100) + "%", 5, 75);

      spriteBatch.end();

      // gl.drawLine((int)(viewWidth * getCurrentParticles().getPercentComplete()), viewHeight - 1,
      // viewWidth, viewHeight -
      // 1);
    }