com.badlogic.gdx.graphics.g2d.Sprite Java Examples

The following examples show how to use com.badlogic.gdx.graphics.g2d.Sprite. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClientDoor.java    From seventh with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param game
 * @param pos
 */
public ClientDoor(ClientGame game, Vector2f pos) {
    super(game, pos);

    this.bounds.setSize(64, 64);
    
    this.rotation = new SmoothOrientation(0.05);
    this.rotation.setOrientation(0);
    this.frontDoorHandle = new Vector2f();
    this.frontHingePos = new Vector2f();
    this.rearDoorHandle = new Vector2f();
    this.rearHingePos = new Vector2f();
    
    this.sprite = new Sprite(Art.doorImg);
    this.sprite.setOrigin(0, Art.doorImg.getRegionHeight()/2);
}
 
Example #2
Source File: TalosAssetProvider.java    From talos with Apache License 2.0 6 votes vote down vote up
private Sprite findSpriteOrLoad (String assetName) {
	final Sprite region = atlas.createSprite(assetName);
	if (region == null) {
		//Look in all paths, and hopefully load the requested asset, or fail (crash)
		//if has extension remove it
		if(assetName.contains(".")) {
			assetName = assetName.substring(0, assetName.lastIndexOf("."));
		}
		FileHandle file = findFile(assetName);
		if (file == null || !file.exists()) {
			//throw new GdxRuntimeException("No region found for: " + assetName + " from provider");
			// try the tracker first
			file = TalosMain.Instance().FileTracker().findFileByName(assetName + ".png");
			if(file == null) {
				return null;
			}
		}
		Texture texture = new Texture(file);
		Sprite textureRegion = new Sprite(texture);
		atlas.addRegion(assetName, textureRegion);
		return textureRegion;
	}
	return region;
}
 
Example #3
Source File: Skin.java    From gdx-skineditor with Apache License 2.0 6 votes vote down vote up
public <T> T get(String name, Class<T> type) {
	if (name == null)
		throw new IllegalArgumentException("name cannot be null.");
	if (type == null)
		throw new IllegalArgumentException("type cannot be null.");

	if (type == Drawable.class)
		return (T) getDrawable(name);
	if (type == TextureRegion.class)
		return (T) getRegion(name);
	if (type == NinePatch.class)
		return (T) getPatch(name);
	if (type == Sprite.class)
		return (T) getSprite(name);

	ObjectMap<String, Object> typeResources = resources.get(type);
	if (typeResources == null)
		throw new GdxRuntimeException("No " + type.getName() + " registered with name: " + name);
	Object resource = typeResources.get(name);
	if (resource == null)
		throw new GdxRuntimeException("No " + type.getName() + " registered with name: " + name);
	return (T) resource;
}
 
Example #4
Source File: TextureDropModuleWrapper.java    From talos with Apache License 2.0 6 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
    super.read(json, jsonData);

    filePath = jsonData.getString("filePath", null);
    regionName = jsonData.getString("regionName", null);

    // hack for older version to patch broken files (we should do version transition logic and move it there later)
    if(jsonData.has("fileName")) {
        filePath = jsonData.getString("fileName");
        regionName = filePath;
        if(filePath.contains(".")) {
            regionName =  regionName.substring(0, regionName.lastIndexOf("."));
        } else {
            filePath = filePath + ".png";
        }
    }

    final TalosAssetProvider assetProvider = TalosMain.Instance().TalosProject().getProjectAssetProvider();
    final Sprite textureRegion = assetProvider.findAsset(regionName, Sprite.class);

    setModuleRegion(regionName, textureRegion);
    dropWidget.setDrawable(new TextureRegionDrawable(textureRegion));
}
 
Example #5
Source File: ClientEntity.java    From killingspree with MIT License 6 votes vote down vote up
public void drawAll(Sprite sprite, SpriteBatch batch, float x, float y) {
    sprite.setPosition(x, y);
    sprite.draw(batch);
    if (x > WorldRenderer.VIEWPORT_WIDTH / 2) {
        sprite.setPosition(x - WorldRenderer.VIEWPORT_WIDTH, y);
    } else {
        sprite.setPosition(x + WorldRenderer.VIEWPORT_WIDTH, y);
    }
    sprite.draw(batch);
    
    if (position.y > WorldRenderer.VIEWPORT_HEIGHT / 2) {
        sprite.setPosition(x, y - WorldRenderer.VIEWPORT_HEIGHT);
    } else {
        sprite.setPosition(x, y + WorldRenderer.VIEWPORT_HEIGHT);
    }
    sprite.draw(batch);
}
 
Example #6
Source File: ClientBomb.java    From killingspree with MIT License 6 votes vote down vote up
public ClientBomb(short id, float x, float y, WorldRenderer renderer) {
    super(id, x, y, renderer);
    markForDispose = false;
    sprite = new Sprite(AssetLoader.instance.getTexture("sprites/bomb.png"));
    sprite.setSize(ServerBomb.RADIUS + 5, 
            ServerBomb.RADIUS + 5);
    sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2);
    sprite.setPosition(x  - sprite.getWidth() / 2,
            y  - sprite.getHeight() / 2);
    deadTimer = 0f;
    Texture explodeTexture = AssetLoader.instance.
            getTexture("sprites/explosion.png");
    explode = new Animation(0.03f, TextureRegion.split(explodeTexture,
            explodeTexture.getWidth()/7, explodeTexture.getHeight())[0]);
    
}
 
Example #7
Source File: SpriteAccessor.java    From xibalba with MIT License 6 votes vote down vote up
@Override
public int getValues(Sprite target, int tweenType, float[] returnValues) {
  switch (tweenType) {
    case ALPHA:
      returnValues[0] = target.getColor().a;
      return 1;
    case XY:
      returnValues[0] = target.getX();
      returnValues[1] = target.getY();
      return 2;
    case COLOR:
      returnValues[0] = target.getColor().r;
      returnValues[1] = target.getColor().g;
      returnValues[2] = target.getColor().b;
      return 3;
    case SCALE:
      returnValues[0] = target.getScaleX();
      returnValues[1] = target.getScaleY();
      return 4;
    default:
      return -1;
  }
}
 
Example #8
Source File: PanzerTankSprite.java    From seventh with GNU General Public License v2.0 6 votes vote down vote up
@Override
    protected void renderTurret(float rx, float ry, float turretAngle, Canvas canvas, Camera camera, float alpha) {
//        rx += 35f;
//        ry += 25f;
        

        rx += 15f;
        ry -= 25f;
        
        rx += 43f;
        ry += 25f;
        
        float originX = 89f;        
        Sprite turretSprite = isDestroyed() ? tankTurretDamaged : tankTurret;
        float originY = 65f;//turretSprite.getRegionHeight()/2f;
                
        turretSprite.setRotation(turretAngle);
        turretSprite.setOrigin(originX, originY);
        turretSprite.setPosition(rx,ry);        
        
        canvas.drawSprite(turretSprite);
    }
 
Example #9
Source File: TankTrackMarks.java    From seventh with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 
 */
public TankTrackMarks(int size) {
    if(size<=0) {
        throw new IllegalArgumentException("Size can not be zero!");
    }
    
    this.tracks = new TankTrack[size];
    for(int i = 0; i < tracks.length;i++) {
        this.tracks[i] = new TankTrack();
    }
    
    
    this.trackMarkSprite = new Sprite(Art.tankTrackMarks);        
    this.shader = MarkEffectShader.getInstance().getShader();
    
    shader.begin();
    {                
        //shader.setUniformi("u_texture", 0);
        shader.setUniformi("mark", 1);
        shader.setUniformf("resolution", SeventhGame.DEFAULT_MINIMIZED_SCREEN_WIDTH, SeventhGame.DEFAULT_MINIMIZED_SCREEN_HEIGHT);

    }
    shader.end();
}
 
Example #10
Source File: CarHighlighter.java    From uracer-kotd with Apache License 2.0 6 votes vote down vote up
public CarHighlighter () {
	sprite = new Sprite();
	sprite.setRegion(Art.cars.findRegion("selector"));
	isBusy = false;
	isActive = false;
	followedCar = null;
	isTracking = false;
	alpha = 1;

	bfScale = new BoxedFloat(1);
	bfRot = new BoxedFloat(0);
	bfAlpha = new BoxedFloat(0);
	bfGreen = new BoxedFloat(1);
	bfRed = new BoxedFloat(1);
	bfBlue = new BoxedFloat(1);
	bfRenderState = new BoxedFloat(0);
	prevState = null;
	renderState = null;
	interpolateState = false;
}
 
Example #11
Source File: TrackProgress.java    From uracer-kotd with Apache License 2.0 6 votes vote down vote up
public TrackProgress () {
	lblAdvantage = new HudLabel(FontFace.CurseWhiteBig, "", false);
	lblAdvantageShown = false;
	lblAdvantage.setAlpha(0);

	texMask = Art.texCircleProgressMask;

	shProgress = ShaderLoader.fromFile("progress", "progress");

	sprAdvantage = new Sprite(Art.texCircleProgress);
	sprAdvantage.flip(false, true);
	flipped = false;

	sprProgress = new Sprite(Art.texRadLinesProgress);
	sprProgress.flip(false, true);
}
 
Example #12
Source File: DriftBar.java    From uracer-kotd with Apache License 2.0 6 votes vote down vote up
public DriftBar () {
	seconds = 0;

	labelSeconds = new HudLabel(FontFace.CurseRedYellowNew, "s", false);
	labelSeconds.setAlpha(0);

	//
	texHalf = Art.texCircleProgressHalf;
	texHalfMask = Art.texCircleProgressHalfMask;

	w = texHalf.getWidth();
	h = texHalf.getHeight();
	offX = w / 2;
	offY = h / 2;
	shDriftSecs = ShaderLoader.fromFile("progress", "progress");

	// drift seconds
	sprDriftSecs = new Sprite(texHalf);
	sprDriftSecs.flip(false, true);

	// drift strength
	driftStrength = new WindowedMean((int)(1 / 0.25f));
	sprDriftStrength = new Sprite(texHalf);
}
 
Example #13
Source File: TextureUtil.java    From seventh with GNU General Public License v2.0 6 votes vote down vote up
public static void setFlips(Sprite sprite, boolean isFlippedHorizontal, boolean isFlippedVert, boolean isFlippedDiagnally) {
    if(sprite==null) return;
    
    if(isFlippedDiagnally) {
        if(isFlippedHorizontal && isFlippedVert) {
            sprite.flip(true, false);
            sprite.rotate(-270f);                                
        }
        else if(isFlippedHorizontal) {
            sprite.rotate(-270f);
        }
        else if(isFlippedVert) {
            sprite.rotate(-90f);
        }
        else {
            sprite.flip(false, true);
            sprite.rotate(-270f);
        }
    }
    else {
        sprite.flip(isFlippedHorizontal, isFlippedVert);
    }
}
 
Example #14
Source File: ClientBullet.java    From killingspree with MIT License 5 votes vote down vote up
public ClientBullet(short id, float x, float y, WorldRenderer renderer) {
    super(id, x, y, renderer);
    markForDispose = false;
    sprite = new Sprite(AssetLoader.instance.getTexture("sprites/bullet.png"));
    sprite.setSize(ServerArrow.RADIUS * 4 , 
            ServerArrow.RADIUS * 1.5f);
    sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2);
    sprite.setPosition(x  - sprite.getWidth() / 2,
            y  - sprite.getHeight() / 2);
    renderer.audioPlayer.shoot();
}
 
Example #15
Source File: VisSpeller.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws the provided grid to the spritebatch
 *
 * @param batch
 * @param grid
 */
private void drawGrid(Sprite[][] grid) {
	Gdx.gl.glClearColor(0, 0, 0, 1);
	Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
	batch.begin();

	batch.disableBlending();
	for (int x = 0; x < 6; x++) {
		for (int y = 0; y < 5; y++) {
			grid[x][y].draw(batch);
		}
	}
	batch.end();
}
 
Example #16
Source File: FluidSimulatorSPH.java    From fluid-simulator-v2 with Apache License 2.0 5 votes vote down vote up
private void createWorld() {
		dropRadius = 0.1f + dropRadiusK;
		dropRadiusPixel = (int) (dropRadius * PARTICLE_SIZE);
		dropRadiusPixel2 = dropRadiusPixel * dropRadiusPixel;
		if (IS_DESKTOP) {
//			dropTexture = new Texture("data/fluid_drop_red_64.png");
			dropTexture = new Texture("data/fluid_drop_64.png");
			dropTexture2 = new Texture("data/fluid_drop_blue_64.png");
			dropSprite = new Sprite(dropTexture);
			dropSprite.setSize(dropRadiusPixel, dropRadiusPixel);
		}
		if (IS_DESKTOP) {
			disposableParticles = new ArrayList<Particle>(SIZE);
		}
		defaultShader = new ShaderProgram(Gdx.files.internal("data/shaders/default.vert").readString(), 
				Gdx.files.internal("data/shaders/default.frag").readString());
		if (!defaultShader.isCompiled()) {
			Gdx.app.log("SHADER_LOG", "couldn't compile scene shader: " + defaultShader.getLog());
		}
		immediateRenderer = new ImmediateModeRenderer20(50000, false, true, 0);

		// On Android populate directly
		if (!IS_DESKTOP) {
			for (float j = INITIAL_HEIGHT + hpadding + 2; j < WORLD_HEIGHT - 2; j += 1.0f) {
				for (float i = -WORLD_WIDTH / 3; i < WORLD_WIDTH / 3; i += 1.0f) {
					particles.add(new Particle(i, j));
					tempParticle = particles.get(particles.size() - 1);
					tempParticle.type = (emitType);
					if (particles.size() >= ANDROID_SIZE)
						return;
				}
			}
		}
	}
 
Example #17
Source File: ClientTestPlayer.java    From killingspree with MIT License 5 votes vote down vote up
public ClientTestPlayer(short id, float x, float y, WorldRenderer renderer) {
    super(id, x, y, renderer);
    markForDispose = false;
    Texture texture = AssetLoader.instance.getTexture("sprites/explosion.png");
    sprite = new Sprite(texture);
    
    walk = new Animation(0.05f, TextureRegion.split(texture,
            texture.getWidth()/7, texture.getHeight())[0]);
    walk.setPlayMode(Animation.PlayMode.LOOP);
    
    walkDuration = 0;
}
 
Example #18
Source File: TextureUtil.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Resizes the image
     *
     * @param image
     * @param width
     * @param height
     * @return
     */
    public static Sprite resizeImage(TextureRegion image, int width, int height) {
        Sprite sprite = new Sprite(image);
        sprite.setSize(width, height);        
//        TextureRegion region = new TextureRegion(image);
//        region.setRegionWidth(width);
//        region.setRegionHeight(height);
        return sprite;
    }
 
Example #19
Source File: FadingSprite.java    From TerraLegion with MIT License 5 votes vote down vote up
public FadingSprite(Sprite sprite, float x, float y, float minAmount, float maxAmount, float subAmount, float speed, float alpha) {
	super(x, y);
	this.sprite = sprite;
	this.alpha = alpha;
	sprite.setAlpha(alpha);
	sprite.setPosition(x, y);
	this.minAmount = minAmount;
	this.maxAmount = maxAmount;
	this.subAmount = subAmount;
	this.speed = speed;
}
 
Example #20
Source File: Art.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Releases all the textures
 */
public static void destroy() {
    try {
        
        /*
         * Iterate through all of the static fields,
         * free the Sprite's, TextureRegion's, and Model's
         */            
        Field[] fields = Art.class.getFields();
        for(Field field : fields) {
            field.setAccessible(true);
            
            Class<?> type = field.getType();
            Object value = field.get(null);
            
            if(value != null) {
                if(type.equals(Sprite.class)) {
                    free( (Sprite)value );
                }
                else if(type.equals(TextureRegion.class)) {
                    free( (TextureRegion)value );
                }
                else if(type.equals(TextureRegion[].class)) {
                    free( (TextureRegion[])value );
                }
                else if(type.equals(Model.class)) {
                    free( (Model)value );
                }
            }
        }
    }
    catch(Exception e) {
        Cons.println("Problem freeing the textures: " + e);
    }
}
 
Example #21
Source File: Hud.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
private void drawGrenadeIcons(Canvas canvas, int numberOfGrenades) {
    Sprite sprite = this.localPlayer.getEntity().isSmokeGrenades() ? Art.smokeGrenadeIcon : Art.fragGrenadeIcon;
    
    int imageWidth = sprite.getRegionWidth();

    canvas.drawImage(sprite, 10, canvas.getHeight() - sprite.getRegionHeight() - 20, 0xffffff00);
    canvas.setFont("Consola", 14);
    canvas.boldFont();                
    RenderFont.drawShadedString(canvas, "x " + numberOfGrenades, imageWidth+20, canvas.getHeight() - 30, 0xffffff00);
    
}
 
Example #22
Source File: GdxCanvas.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void drawSprite(Sprite sprite) {
    if(!isBegun) batch.begin();        
    sprite.setColor(1,1,1, this.compositeAlpha);
    sprite.draw(batch);        
    if(!isBegun) batch.end();
}
 
Example #23
Source File: GdxCanvas.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void drawSprite(Sprite sprite, int x, int y, Integer color) {
    if(!isBegun) batch.begin();        
    if(color!=null) {
        Color c = setTempColor(color);
        sprite.setColor(c);            
    } else sprite.setColor(1,1,1, this.compositeAlpha);
    sprite.setPosition(x, y);
    sprite.draw(batch);        
    if(!isBegun) batch.end();
}
 
Example #24
Source File: SceneTheme.java    From Radix with MIT License 5 votes vote down vote up
public void init() {
    this.labelFont = new BitmapFont();

    this.buttonBgTex = new Texture(Gdx.files.internal("textures/gui/guiButtonBackground.png"));
    this.buttonBgPressTex = new Texture(Gdx.files.internal("textures/gui/guiButtonBackground-pressed.png"));
    this.buttonBgDisabledTex = new Texture(Gdx.files.internal("textures/gui/guiButtonBackground-disabled.png"));

    SpriteDrawable buttonBgSprite = new SpriteDrawable(new Sprite(buttonBgTex));
    SpriteDrawable buttonBgPressSprite = new SpriteDrawable(new Sprite(buttonBgPressTex));
    SpriteDrawable buttonBgDisabledSprite =new SpriteDrawable(new Sprite(buttonBgDisabledTex));
    this.buttonStyle = new ImageTextButtonStyle(buttonBgSprite, buttonBgPressSprite, buttonBgDisabledSprite, labelFont);
}
 
Example #25
Source File: ResourceManager.java    From TerraLegion with MIT License 5 votes vote down vote up
public Sprite loadSprite(String id, String file, float scaleX, float scaleY) {
	Sprite sprite = new Sprite(new Texture(Gdx.files.internal(file)));
	sprite.getTexture().setFilter(TextureFilter.Linear, TextureFilter.Nearest);
	sprite.setScale(scaleX, scaleY);
	sprite.setOrigin(0, 0);
	sprites.put(id, sprite);
	return sprite;
}
 
Example #26
Source File: Crosshair.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
public static Sprite create() {
	int w = View.width() / 100;
	int h = w;
	Pixmap pix = new Pixmap(w, h, Pixmap.Format.RGBA8888);
	pix.setColor(1f, 1f, 1f, 0.8f);
	pix.drawLine(w/2, 0, w/2, h);
	pix.drawLine(0, h/2, w, h/2);
	pix.setColor(0f, 0f, 0f, 0f);
	pix.drawPixel(w/2, h/2);
	Texture tex = new Texture(pix);
	Sprite sprite = new Sprite(tex);
	return sprite;
	// TODO we don't dispose anything, this is just a temporary crosshair
}
 
Example #27
Source File: TextureModule.java    From talos with Apache License 2.0 5 votes vote down vote up
public void setRegion (String regionName, Sprite region) {
    this.regionName = regionName;
    
    if (region != null) {
        userDrawable.setDrawable(new TextureRegionDrawable(region));
    }
}
 
Example #28
Source File: FadingSprite.java    From TerraLegion with MIT License 5 votes vote down vote up
public FadingSprite(Sprite sprite, float x, float y, float minAmount, float maxAmount, float subAmount, float speed) {
	super(x, y);
	this.sprite = sprite;
	alpha = 1f;
	sprite.setPosition(x, y);
	sprite.setAlpha(alpha);
	this.minAmount = minAmount;
	this.maxAmount = maxAmount;
	this.subAmount = subAmount;
	this.speed = speed;
}
 
Example #29
Source File: GdxCanvas.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void drawSprite(Sprite sprite, float x, float y, Integer color) {
    if(!isBegun) batch.begin();        
    if(color!=null) {
        Color c = setTempColor(color);
        sprite.setColor(c);            
    } else sprite.setColor(1,1,1, this.compositeAlpha);
    sprite.setPosition(x, y);
    sprite.draw(batch);        
    if(!isBegun) batch.end();
}
 
Example #30
Source File: MapLoader.java    From Bomberman_libGdx with MIT License 5 votes vote down vote up
protected Sprite createGroundSprite() {
    TextureRegion textureRegion = tileTextureAtlas.findRegion("ground");

    Sprite sprite = new Sprite();
    sprite.setRegion(textureRegion);
    sprite.setBounds(0, 0, 1, 1);

    return sprite;
}