ShapeRenderer doesn't render when using Skins - libgdx

My shapes drawn by shape renderer does not show when I use skins. The shape is drawn inside the actor using an instance of ShapeRenderer. I think this is caused by the skin because I tried adding an empty table and the shapes show, but if I add an instance of a skin the shapes does not show.
This code is from the libgdx tests in github:
Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
Label nameLabel = new Label("Name:", skin);
Table t1 = new Table();
t1.setFillParent(true);
t1.add(nameLabel);
stage.addActor(t1);

you need to .end() the SpriteBatch befor using the ShapeRender.begin() after the ShapeRender.end() you need to call SpriteBatch.begin() in your actor. Else you do have 2 concurenting batches.
actor.draw(SpriteBatch batch, float delta){
batch.end();
ShapeRender.begin(Some Typee);//start it with your shapetype
//drawing stuff with the shaperender
ShapeRender.end();//dont forget to end it
batch.begin(); //need to be started again for the next actors to be dawn
}
An empty table shouldnt be a problem.

Related

Collision detection kit with FlashPunk

I start creating my flash game using Flashpunk, for collisions i didn't want to use hitboxes because i had images (PNG) with transparent parts in them so i decided to use Collision Detection Kit, i have a problem when creating the collision list, it takes a display object as a parameter and doesn't accept flash punk spritemaps, i tried to cast the spritemap to a flash display object but it's not working, is there a way to use the CDK with flashpunk ?
override public function begin():void
{
_player = new Player(100, 100);// Entity
initCollision(_player.sprPlayer);// The Entity Spritemap
}
private function initCollision(player:Spritemap):void {
collisionChecker = new CollisionList(player); // Problem here
}
Well, you could create an empty BitmapData with the same width & height of your Spritemap and then "render" it to that BitmapData, like so:
var bmd:BitmapData = new BitmapData(64, 64, true, 0);
var sprite:Spritemap = _player.sprPlayer;
sprite.render(bmd, new Point(0,0), new Point(0,0));
collisionChecker = new CollisionList(bmd);
That should draw the spritemap's current frame to a BitmapData which you could then use for the CollisionList. The code above is an example that only demonstrates how to do this. For your actual code, it would be better to avoid constantly initializing new variables during your collision detection.

Libgdx Group Size Issue

To make my question clearer , I created a simple test class as below.
`public void create () {
stage = new Stage();
// GP
Texture texture1 = new Texture(Gdx.files.internal("data/badlogic.jpg"));
TextureRegion tr = new TextureRegion(texture1);
Image image = new Image(tr);
Group gp = new Group();
ImageButton ib = new ImageButton(new Image(tr).getDrawable());
ib.setSize(90, 256);
gp.addActor(ib);
gp.setPosition(0, 0);
stage.addActor(gp);
gp.debugAll();
}`
The size of badlogic logo is 256*256. I set it to 90*256 in the test.But the outcome looks like this http://imgsrc.baidu.com/forum/w%3D580/sign=fb0e4402d21373f0f53f6f97940e4b8b/0958c32397dda1448779b0cbb1b7d0a20df486e2.jpg
If i set the image size before sending it to imagebutton, then it will rendered as 256*256 ,the full original size. This function is so simple. I can not figure out where is going wrong.
First of all, last update of Libgdx project is 1.4.1: http://libgdx.badlogicgames.com/download.html
The problem is the Drawable object that you are sending to the ImageButton, if you want to change the size of the Image or Texture before adding it to the ImageButton (so you will solve the problem asked), you will just need to use the .setBounds() method
I write down a little example:
1. Initialize Image object with your image file:
`Image image = new Image( new Texture ( Gdx.Files.internal("yourPathFile.png") ) );`
2. .setBounds() javadoc: (x coordinate, y coordinate, width of the image, height of the image)
image.setBounds(0f, 0f, 50f, 60f)
then you can send the image to the ImageButton object as Drawable.
`ImageButton myButton = new ImageButton(image.getDrawable());'
That's all.
Here you have some constructors of ImageButton object from the Libgdx official javadoc.
See also:
Release versions: http://libgdx.badlogicgames.com/releases/
ImageButton javadoc: http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/ImageButton.html

Away3d aplying texture/ matterial issues

Hello i try to texture a sphere with a png but it apply the texture wrong and messes it up.
i cant find any way to move it around and play with the texture/material untill it will be set correctly.
i want to create a soccer ball and to apply it a ball texture
This is my code i use to create the material and apply it
Thanks
[Embed(source=”../assets/Ball.png”)]
public static var TheBallTextureClass:Class;
public var TheBallMaterial:TextureMaterial;
var theball:Mesh;
TheBallTexture = new BitmapTexture(new TheBallTextureClass().bitmapData);
TheBallMaterial = new TextureMaterial(Cast.bitmapTexture(TheBallTexture));
TheBallMaterial.smooth = true;
TheBallMaterial.repeat = true;
theball = new Mesh(new SphereGeometry(30), _ballMaterial);
That's because the UV Mapping of the SphereGeometry is weird and is not made for a pattern like the soccer ball.
I suggest you to create the sphere in 3ds max and unwrap it there.
EDIT:
If you want you can edit UV mapping of SphereGeometry inside Away3D:
Create a SubClass of SphereGeometry and override "buildUVs(target:CompactSubGeometry)" creating your own set of UVs.

libGDX stage draw me mirrored text

I use Stage in libGDX for drawing GUI and adding listeners to controls in my game.
But when I draw text on ImageTextButton I get mirrored text as displayed on image below.
Can some help me and tell me how to draw normal text, not mirrored ?
stage = new Stage(Constants.VIEWPORT_GUI_WIDTH, Constants.VIEWPORT_GUI_HEIGHT);
stage.clear();
....
ImageTextButtonStyle imageTextButtonStyle = new ImageTextButtonStyle();
imageTextButtonStyle.font = Assets.instance.fonts.defaultSmall;
ImageTextButton imageTextButton = new ImageTextButton("ddsds", imageTextButtonStyle);
imageTextButton.setBackground( gameUISkin.getDrawable("fil_coins"));
imageTextButton.setPosition(50, 600);
imageTextButton.setHeight(85);
imageTextButton.setWidth(183);
stage.addActor(imageTextButton);
....
public void render (float deltaTime) {
stage.act(deltaTime);
stage.draw();
}
Thanks
Edit:
Button images are shown correct, only text has mirrored view
As #Springrbua suggest me in comment below, my bitmap font was flipped when creating.
defaultSmall = new BitmapFont(Gdx.files.internal("images/font.fnt"), true);
should be
defaultSmall = new BitmapFont(Gdx.files.internal("images/font.fnt"), false);
Even it's not case here it may be useful for someone - if font size parameter is set to negative value, text will be rendered upside-down (Y-scale).

How to handle resume for libGDX Image with Pixmap texture

I have a com.badlogic.gdx.scenes.scene2d.ui.Image that is built from a Pixmap. The Pixmap is only one pixel because I'm using it to build an Image that functions as a background that can fade in and out.
Pixmap pmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
pmap.setColor(1.0f, 1.0f, 1.0f, 1.0f);
pmap.drawPixel(0, 0);
bgImage = new Image(new Texture(pmap));
pmap.dispose();
bgImage.setSize(MyGame.VIRUAL_WIDTH, MyGame.VIRUAL_HEIGHT);
bgImage.getColor().a = 0.0f;
bgImage.addAction(Actions.sequence(Actions.fadeIn(1.0f),Actions.delay(3.0f),Actions.fadeOut(1.0f)));
stage.addActor(bgImage);
It works great but my concern is that the game might be paused while the actions are taking place. I assume the actions will continue upon resuming so I need to keep the same Image but the underlying Pixmap is not managed and therefore needs to be recreated upon resume. I'm having trouble figuring out how to reattach the Texture/Pixmap to the Image. Building the Pixmap itself is easy but getting an existing Image to use it is the problem.
My solution was as follows
Assume Pixmap pixmap = ...
TextureData texData = new PixmapTextureData(pixmap, Format.RGBA8888, false, false, true);
Texture texture = new Texture(texData);
Image image = new Image(texture);
The last flag in PixmapTextureData is "managed". It runs on mine.
You can check out the first portion of the following link to see what is managed and what is not. http://www.badlogicgames.com/wordpress/?p=1513
There is no setTexture method on an Image. Looking at the Image(Texture) constructor it wraps the texture in a drawable region:
this(new TextureRegionDrawable(new TextureRegion(texture)));
So you can do something similar and use the Image.setDrawable method to change the drawable object used. Something like this:
bgImage.setDrawable(new TextureRegionDrawable(new TextureRegion(new Texture(pmap))));
I think you can probably reuse the TextureRegion and all of its containers (so after generating a new pixmap, just wrap it in a Texture and push that into the saved TextureRegion from before the pause.