I want to create a UI window in libgdx where the top part (the part containing the title and which allows you to drag the window) has a different background color from the rest of the window. I can only set the background color for the entire window, is it possible to change it for just this top part?
Code so far:
WindowStyle windowStyle = new WindowStyle(new BitmapFont(), Color.WHITE, skin.newDrawable("white", Color.BLACK));
Window window = new Window("test", windowStyle);
window.setMovable(true);
window.padTop(20);
stage.addActor(window);
window.setPosition(100, 100);
window.setSize(500, 300);
The top bar for UI Windows in libgdx uses the same texture as the whole window. In order to change the color for the top bar the underlying texture file will need to be modified. libgdx treats it as a whole and there is no built-in way to specify separate colors for each component of a window.
There are other ways, but they are non-trivial and requires writing your own widget class to replicate most of the behavior of the built-in Window class.
Related
I've created a table with scened2d that contains buttons, but i have many issues with thoses buttons.
First issue is scaling, whenever i try to set a button's with and height an issue appear
when i set it with :
table.add(btn).with(100).height(30);
or
btnStyle.up.setMinWidth(80);
btnStyle.up.setMinHeight(40);
btnStyle.down.setMinWidth(80);
btnStyle.down.setMinHeight(40);
the button is correctly scaled but the background is acting weird
But if i don't set their with and height, their background are normal but the buttons are way too big
Second issue, the buttons don't "work" as i can't click on then (nothing change)
here is the code
// style
final Skin skin = new Skin(Gdx.files.internal("skin/glassy-ui.json"));
final BitmapFont font = skin.getFont("font");
final TextButton.TextButtonStyle btnStyle = new TextButton.TextButtonStyle();
btnStyle.font = font;
btnStyle.up = skin.getDrawable("button");
btnStyle.down = skin.getDrawable("button-down");
btnStyle.up.setMinWidth(80);
btnStyle.up.setMinHeight(40);
btnStyle.down.setMinWidth(80);
btnStyle.down.setMinHeight(40);
// buttons
Textbutton btn = new TextButton("some text", btnStyle);
how can i scale my buttons correctly and what could cause the buttons to stop working ?
(there is already a question about buttons scaling but it didn't helped much)
For getting the clicks on the button, you have to add a ChangeListener.
The assets you are using as button background are too big, or their padding is too big. Use the Skin Composer to get a preview for your skin.
With the buttons not working, did you remember to call setInputProcessor on your stage?
I am working on a flash sound mixer application with multiple sound channels, and I am having trouble with the lights beside the volume knob.
Is there a way to hide just a part of an image?
On the image below, image-2 is on top of image-1 to create some kind of volume level indicator effect, and how much of image-2 is shown depends on the value of the volume.
image-url: http://s30.postimg.org/r3ow1g5bl/volume_lights_level.png
I've tried by just reducing the height of image-2, but it looks awful and distorted.
Is there something in flash that works closely the same as CSS's behavior.
example: I'll just make image-2 a background of a shape, and when I reduce the shape's height, the image-background does not get distorted or changes it's height as well.
By searching for solutions, I have come across the mask property, but I don't quite understand how it works, and most of the examples shown are images placed inside circles.
Is the mask property applicable in this situation?
I'm quite new to flash so I don't know a lot of things yet.
You can indeed use a mask.
How to programmatically create your mask
Put an occurrence of your image named myImage on the stage, and put over this occurrence a mask named myMask with the same dimensions. You can apply myMask mask to myImage using it's mask property like below:
Main Timeline
myImage.mask = myMask;
function mouseMoveHandler(e:MouseEvent):void {
myMask.height = myImage.y - e.stageY;
}
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
You have just to adapt this code to your animation, in the function where you click your button.
I got it working now, many THANKS #VC.One. heres how I did it.
Imported img-2 to stage, converted it into symbol(type:Movie Clip), assigned instance name: img2_mc.
I created a new layer for the mask, drawn a rectangle using rectangle tool, converted it also to symbol(type:Movie Clip), assigned instance name: mask_mc.
Then applied the mask to img2_mc.
/* the code */
img2_mc.mask = mask_mc;
function onEnterFrame(event:Event):void{
var volumeKnob_y = volSliderKnobOn.y + 12; // adjust it to the center of the knob
mask_mc.height = volumeKnob_y;
}
I am developing a flex screen, in which i have a canvas, above to that there will be a button, by clicking that button we can create panels dynamically.My problem is if a panel was manually dragged and kept in the position where new panel to be created then new panel have to be created somewhere else that means not above any other panels.
How to achieve this..Pls give me any solution.Thanks
my first idea is that you keep array of created panels. while creating new panel, you should check in this list if any panel colides with the one you created (get x and y position and width, height and check if it kolides or not)
tou can also create new component based on canvas and override its addChild method.
I need to show a popup layer on a scene, creating a semi-transparent background layer that will also prevent touch events propagation. I am using the latest cocos2d-x v. 3.0-alpha-0.
What I want to achieve is a popup layer that fully handles touches (eg. buttons, menu items, scroll views, etc.), laying on a background layer (for design purposes), that covers the current scene. All items in the scene should not respond to touches any more.
Is this achievable using the new EventDispatcher class? I've been able to disable all touches to the main scene, but all instances of MenuItem that live in the scene are still touchable and active.
How can I achieve this? And, also, how can I create a touch listener that prevents all touches to the main scene but not to the popup?
You can disable menu items by setting setDisable property of menuitems to false.
Example
_menuItem->setEnabled(false);
For Layers use setTouchEnabled property
_backGroungLayer->setTouchEnabled(false);
Make sure that popup layer is not child of layer you want to disable.
To disable all items in menus do this
Suppose _menu contain various menuitems.
CCARRAY_FOREACH(_menu->getChildren(), item)
{
item.isEnabled=NO;
}
if you want to disable selected items just give them tags.There is no need to make any list.
I had the same problem and solved it with mm. It was dirty, but it worked:
Create a button using ccui.button.
Set the button size to your screen size.
Add this button as a background to your popup layer.
This will prevent any thing behind it being clicked.
By default, all CCMenu's have a set priority (kCCMenuHandlerPriority = -128) in cocos2d 2.1. So in a class (usually a CCNode descendant) that wants to swallow everything and preempt anything i do like in this dialog sequencer example below :
- (void)onEnter {
backdrop_.visible = self.isBackDropShown;
MPLOG(#"Adding self as a swallower touch delegate, above the rest of the planet.");
[[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self priority:_dialogTouchPriority swallowsTouches:YES];
for (CCMenu *mn in _menus) {
mn.touchPriotity = _dialogTouchPriority -1 ;
}
[super onEnter];
}
where _dialogTouchPriority is kCCMenuHandlerPriority-1 by default. It will be served before everything 'below'. It is a bad hack (cocos2d internals could be changed and break this), i know , but bullet proof. Use carefully, make certain you only ever have one of these in your scene.
HI,
I want to implement tweener effects in my application, but I have a rectangle,
shape = new Shape();
shape.graphics.beginFill(0xF9F9F9);
shape.graphics.drawRect(200,80,700,450);
shape.graphics.endFill();
account_label.label ="Accounts";
account_label.setPosition(200,530);
account_label.width =140;
personal_details_label.label ="Personal Details";
personal_details_label.setPosition(340,530);
personal_details_label.width=180;
the above code shows my rectangle and two buttons,
Intially Accounts Form was selected by default, when i click PersonalDetails button i have to show the screen change effect (From Right to Left that means Personal DetailsForm is moving from right to left ) within that rectangle. Is this possible ?
I'm a fan of tweensy, but you can do this with most tweening engines easily
Tweensy.to(shape, {x:-100}, 2.0);
Tweensy.onComplete = animationComplete; //optional
The important part to consider when working with animations is timing. Either disable buttons or setup a proper fallbacks. The animations can take a few seconds and if the user can restart the animation, or if objects aren't cleared or initialized properly you can run into some issues.