I'm using amcharts4 to create large data charts (XY). I want to include two different types of bullets in it. Then these different types shall be switched on/off by the user. I managed to switch off, but not on again.
As my real usecase loads a lot(!) of data, I implemented the bullets in an unusual way to keep performance up: The bullets are disabled and then enabled with propertyfield.disabled.
var smallBullet11 = series1.bullets.push(new am4charts.LabelBullet());
smallBullet11.disabled = true;
smallBullet11.propertyFields.disabled = "hideBullet1";
As a result I can hide, but later on not show the bullets again.
Here is the full example: https://jsfiddle.net/9uwgp85s/
Click on "Hide X-Bullets" first (will work) and then "Show X-Bullets" (won't work).
Has anyone an idea how to switch the bullets on again?
Thanks for any hint!
You'll need to call show/hide on the individual bullets, for example:
function hidebullets() {
smallBullet11.clones.each(function(bullet) {
bullet.hide();
});
}
function showbullets() {
smallBullet11.clones.each(function(bullet) {
bullet.show();
});
}
You might also find the minBulletDistance property helpful in improving performance on a line chart with a ton of bullets. It allows you to specify a minimum distance between each point before a bullet is drawn; the larger the distance, the fewer the bullets that will get drawn until you zoom in. You can find more performance tips like this one here.
Related
The tiles in Azure maps are repeating for me so that one location shows twice or thrice sometimes. I tried adjusting zoom but that had no effect. How can I limit this repetition?
To make sure I understand what you are describing, when zoomed out, you are seeing two or more "worlds" and your data repeated on them. This is known as world wrap. Like a globe you can spin it infinitely horizontally. There is an option to disable this:
var map = new atlas.Map('myMap', {
//Disable world wrap.
renderWorldCopies: true,
//Your other map options.
});
Here is a live demo of this: https://azuremapscodesamples.azurewebsites.net/?sample=Render%20world%20copies
i´m trying to made a couple screens like a menu or a pause, and in these screens i want to put some "other screens", for example in my menu i want a button options and then the app slides and shows another screen with options like music/volume, or like a castlevania/megaman game when the user pause the game, some options are displayed, change the inventory, buy an hability or something like that, in this case when we try to manage the inventory the screen change an shows the information about the current inventory, so my question is how is managed this on libgdx, because i know there is a screen class but is that the way to do it?, constantly change between screens or there's another way.
This is actually what you need scene2D.
scene2d is well equipped for laying out, drawing, and handling input for game menus, HUD overlays, tools, and other UIs. The scene2d.ui package provides many actors and other utilities specifically for building UIs.
Lets assume you know about Stage which you will need to add your Actors like(buttons,textfield,input) all you have to do is implement Table, part of scene2D that contains method such as setVisible.
Lets say for example this is your log-in HUD. Now you want to hide it when a button is clicked.
Table table = new Table();
table.add(textField);
table.add(logInButton);
stage.addActor(table);
if(hideButton.isChecked())
{
table.setvisible(false)
}
else
{
table.setVisible(true)
}
This will hide all your Actors that contains in your table.
I just started out with Phaser.
I have a simple sprite in the middle of the screen, and whenever I click the sprite, I emit a particle at the clicked x,y coordinates.
My problem is that the particles are generated behind the sprite. I have tried setting z on the sprite to 1 and the emitter to 1000 without luck.
What am I missing?
var emitter = game.add.emitter(game.world.centerX, game.world.centeryY);
emitter.makeParticles('phaser');
var sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'phaser');
sprite.scale.setTo(2, 2);
sprite.inputEnabled = true;
sprite.events.onInputDown.add(function(sender, pointer){
emitter.emitX = pointer.x;
emitter.emitY = pointer.y;
emitter.emitParticle();
}, this);
http://phaser.io/sandbox/cxBVeHrx
EDIT
My actual code is based on the Phaser-ES6-Boilerplate. Even though BdRs answer solves the issue in the sandbox code, I'm not able to utilize this in my real code.
I have uploaded both the code and a running example. Hopefully someone can tell me where I have screwed things up...
Separate Phaser items don't have a z-order, instead it just depends on the order you create and add them to game. Each new sprite or emitter or group etc. will be displayed on top of all previously added items.
So, simply changing your code to something like this should work.
// first the sprite
var sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'phaser');
sprite.scale.setTo(2, 2);
// then the particles in front of sprite
var emitter = game.add.emitter(game.world.centerX, game.world.centeryY);
emitter.makeParticles('phaser');
// then maybe text in front of particles and sprite
var mytest = game.add.bitmapText(10, 20, 'myfont', 'Level 1', 16);
// etc.
Btw sprites do have a .z value but that only used when it's part of a Phaser.Group, it will then be used as the display z-order but only within that group of sprites.
By default, phaser will not sort objects that get added to any group, it will just render them in the order that they get added. In your case, you can just add the emitter to the group after you add the sprite (the group in this case is the 'game' object).
Of course, having to add objects in the drawing order is not ideal, and if you need to have them sorted dynamically, not possible.
Another way is you can sort objects within a group using the 'sort' function, in which you give it the name of a parameter to sort by, and you sort whenever you need to (in some cases, in the Update callback).
Sorting every frame can be a performance hit though, especially if you have a lot of objects. Another way you could go about this is by adding groups, sorting those groups in draw order (think of them like layers), and then adding objects to those groups in any order. Any group that needs sorting within itself you can sort as well. This way, you can choose to have (for example) a background layer not needing to be sorted but everything added to that layer will be behind every other layer.
Good answers from everybody, but you are missing that every GameObject has a depth property which serves exactly the z-index purpose. This way you do not need to rely on the order of objects creation.
There is also an official
example.
Hope this helps.
Color newColor = new Color(197,222,90);
JButton newButton;
newButton = new JButton(icon);
newButton.setBacgroundColor(newColor);
When it is pressed it changes color. How can I keep it from changing color? I have multiple buttons, so if there is solution in one or two rows please help me, and keep in mind that I'm beginner, writing some huge classes won't help me, because I have multiple buttons with different names to be affected with this.
EDIT: Solution in one line is:
UIManager.put("Button.select", newColor);
But it changes all button colors but I need another to have different a color.
EDIT2: After some research I figured out there isn't an easy solution (but it should be). How I see it I have 2 solutions, 1. is to break buttons to separate classes and set UIManager for them, and second is to make custom buttons. It is just too much work for button.
I've found nothing that can change that particular behavior on a normal JButton. The problem being, that whatever you write in your actionlistener for the button, will occur AFTER you've let go of the mousebutton, and not "while clicking".
There are workarounds, however.
My preferred choice is, to remove all graphics from the button, and then add your own images to the button's regular and pressed states. You could take a screenshot of your GUI, cut out the button, and set that image to be both states.
JButton myButton = new JButton();
// Sets button x, y, width, height. Make the size match the image.
myButton.setBounds(5, 30, 100, 30);
// Remove border-graphics.
myButton.setBorder(null);
// Remove default graphics from the button
myButton.setContentAreaFilled(false);
// Remove the focus-indicating dotted square when focused (optional)
myButton.setFocusPainted(false);
// Here, myImage is a simple BufferedImage object.
// You can set one like this, provided you have an "images" package,
// next to your main class (ex: com.somecompany.someprogram.images),
// that contains an image:
BufferedImage myImage = ImageIO.read(getClass().getResource("images/myImage.png"));
// Then we simply apply our image to both states for the button, and we're done.
myButton.setIcon(new ImageIcon(myImage));
myButton.setPressedIcon(new ImageIcon(myImage));
Obviously there are many ways to retain and load an image, but since that's not the issue here, I'll leave additional methods out of it.
There's no need to go through it all countless times, though. It should be pretty easy to write your own custom implementation of the JButton class, in which a custom constructor takes a single parameter, being the BufferedImage, and then the constructor sets it up accordingly (changes the icons). Then all you have to do when you create a new JButton, is to use your own class, and pass it an image:
JButton btn = new MyCustomJButton(myImage);
You could also easily get along with very few images. All you need is a HashMap which holds all the images, with a String as a key. Imagine you need 4 OK-buttons. You make a single image of a button with the text "OK" written on it. Then you put that image into the HashMap, like so:
myMap.put("OK", myImage);
Then you could do this when creating a button, over and over again if you'd like more:
JButton btn = new MyCustomJButton(myMap.get("OK"));
Alternatively:
Another way of achieving this, which is pretty elaborate, but probably considered "the right way", is to use ButtonUI, as presented in this answer to another post.
If the OP is referring to the temporary change of background colour on a button with an icon at the moment the mouse is pressed, the following statement does the trick:
button.setContentAreaFilled(false);
"If you wish to have a transparent button, such as an icon only button, for example, then you should set this to false."
This took me a long time to figure out. It seems to be a little known technique, perhaps since its name gives little clue as to its effect.
With only first lane we can still see that it is clicked. You need to combine those two:
button1.setContentAreaFilled(false);
button1.setEnabled(false);
and if you don't wanna in grey color you put another button under him.
panelname.add(button1,+5,+5); \\(first not clicable, not visible button, notice +5)
panelname.add(button2,-5,-5); \(-5,-5 means it is 5 points under panel)
My current understanding is that I have to assign the coordinates in the code itself instead of using the interface-builder. Is there a better way to do this?
Currently I am trying to handle a login view. It works well in portrait mode but in landscape mode few of the contents are hidden. Please suggest how to handle this.
Thanks
GuruPrasad R Gujjar.
You can handle this one of two ways. The first is what you suggested and change all of their frames, and second is to just have a separate view that is in landscape mode and switch it out on rotation.
For both cases you need to implement these two methods
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
-(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
if (toInterfaceOrientation==UIInterfaceOrientationPortrait || toInterfaceOrientation== UIInterfaceOrientationPortraitUpsideDown) {
//put the portrait orientation here
self.usernameField.frame=CGRectMake(xPortraitLocation, yPortraitLocation, xWidth, yWidth);
...
}
else{
//do the same thing with everything but for landscape mode
}
With a seperate view you just switch them out by saying self.view=self.lanscapeView or self.portraitView.
If I am going to use the first method I sometimes like to create a fake view in the interface builder so that I can put all my items in the correct locations and look under the location tab which eliminates the guess and check of assigning the numbers.
Hope this helps.