2
votes

I have a sprite, which I draw with:

sprite.draw(spriteBatch);

This works.... I have two spites showing the same, but with different resolution...

Let's say x1 = h:100px, x2= h:200px

In the very wrapper class of the sprite I have a method like this:

public static void setSclae(float newScale, Sprite sprite) {
    // sprite.scale(newScale - sprite.getScaleX());
    sprite.setScale(newScale);
}

(I tried both, both didn't work) Documentation: http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/Sprite.html#setScale(float)

On creation of the wrapper class I call the function like this:

setScale(setSide/(setWidth ? this.sprite.getBoundingRectangle().width : this.sprite.getBoundingRectangle().height));

setWidth => boolean (Do you want to set the height or the width??) this. sprite is a sprite. Origin @(0,0)

The problem is: I want to set the height, no matter which sprite comes in, to 50px...

For x1: setScale(50/100) -> 0.5f

For x2: setScale(50/200) -> 0.25f

Why the hell does this piese of code not work??

Thanks for helping out

Yours,

Florian

PS: Here the constructor of the wrapper class:

 public Drawable(Sprite sprite, Vector2 position, Anchor anchor, float setSide, boolean setWidth, boolean flipH, boolean flipV) {
    this.sprite = new Sprite(sprite);
    this.sprite.setOrigin(0, 0);
    setPosition(anchor, position.x, position.y);
    setScale(setSide / (setWidth ? this.sprite.getBoundingRectangle().width : this.sprite.getBoundingRectangle().height));
    this.sprite.flip(flipV, flipH);
}
1

1 Answers

0
votes

I will answer it myself. How I solved it? I implemented my own "Sprites" class, using TexTureRegion. You might not need everything. Pastebin: http://pastebin.com/1Y25HFBm The IGameObject interface folows. [You do not need the IIntersect interface...

import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public interface IGameObject {

public static enum Anchor {TopLeft, MiddleLeft, LowLeft, TopMiddle, MiddleMiddle, LowMiddle, TopRight, MiddleRight, LowRight}

public void Update(GameTime.GameTimeArgs gameTimeArgs);

public void Draw(SpriteBatch spriteBatch);

public void setPosition(Anchor a, float x, float y);

public void setScale(float newScale);

public String toString();
}

Hope that helps :D

Yours,

Florian