Hi, I'm using JSFML a 2.2 SFML port for Java.
I've been trying to make a class that extends BasicTransformable and implements the Drawable interface.
I am trying to make something similar as a VB.net Panel control.
This class named "Panel" has a Sprite, a RectangleShape, a float for Opacity and many other. So far, I've been able to make a setOpacity method that changes the opacity of the background image (the sprite's texture), change the color of the background color (the RectangleShape's Color) as well as many other features.
I wasn't able to change the size of the Panel since the sprite does not have a setSize() method. (Yes, I know I can use the setScale(target_size/current_size)) but this will not function correctly when the current size is (0,0) because it will be dividing a number by 0.
When I set a texture to a sprite and then use sprite.getGlobalBound.width (or height), I get a value of 0 even when I can visually see the sprite on the screen.
public class Panel() extends...
{ private Vector2f size
; private Texture texture
; public Panel() { ...
} public void setSize
(float x,
float y
) { this.
size = new Vector2f
(x,y
); sprite.
setScale(this.
size.
x / sprite.
getGlobalBounds().
width,
this.
size.
y / sprite.
getGlobalBounds().
height); rectangleShape.
setSize(getSize
()); } public void setImage
(ConstTexture texture
) { this.
texture = (Texture
) texture
; this.
texture.
setSmooth(true); //Not Important. //if(optionalShader.isPresent()) { //optionalShader.get().setParameter("texture", this.texture); //} //Sets a texture to sprite and resizes the sprite. The sprite.
setTexture(texture,
true); //Stretches the resized sprite to the Panel's size. sprite.
setScale((float)getSize
().
x / this.
texture.
getSize().
x,
(float)getSize
().
y / this.
texture.
getSize().
y); }} So how should I correctly implement a proper setSize() method on sfml?
I want the texture to always stretch to the size of the panel. so that is why I have a sprite.setScale() at the end of the setImage() method.
PS.I can read c++ code as well.