I can not change the name of my opacity.Its change.Its change? - xtk

Would anyone know how to change the name of the menu opacity to a name of my choice in Slice?
Thank's.

This can be done with the .name function of dat.gui.
gui.add(volume, 'opacity').name('Transparency');

That's a dat.gui question and not really related to XTK. Basically you have to create a wrapper object:
var settings = {
transparency: 1.0
}
transparency would be your new name.
Then, you define the controller using the settings object
var opacityController = lhgui.add(settings, 'transparency', 0, 1);
And in the callback, adjust the XTK opacity value:
opacityController.onChange(function() {
mesh.opacity = settings.transparency;
});

Related

Change color of a Gtk::Entry stored in a specific variable

I am looking for a way to change the color of a Gtk::Entry that is stored in a specific variable. I am using the CSS way to specify the color of an Entry and I have found this code which changes the color of all entries in the application but this is not exactly what I am looking for:
styleContext = get_style_context();
provider = Gtk::CssProvider::create();
styleContext->add_provider_for_screen(Gdk::Screen::get_default(), provider,
GTK_STYLE_PROVIDER_PRIORITY_USER);
provider->load_from_data(".entry { background: red; }");
You can get the style context for that particular Gtk::Entry, it can look someting like:
auto style_context = entryWidget.get_style_context();
try {
auto red_background = Gtk::CssProvider::create();
red_background->load_from_data(" entry { background: red; } ");
style_context->add_provider(red_background, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
} catch (Gtk::CssProviderError& err) {
std::cerr << err.what() << "\n";
}
Sometimes it is tricky to have the style apply to the widget. If this is the case, try changing the selector from tag entry to *.
The API docs suggests it is possible use an id selector in the css and apply the css-provider to the parent Window. I have not been able to make this work.

Override open variable for class in Swift and SpriteKit for use in XCode's ActionEditor

I'm trying to make small platformer game, just in learning purposes. I've tried to animate character with array of SKTextures like this:
let animation: SKAction = SKAction.animate(
with: frames.map {
let texture : SKTexture = SKTexture(imageNamed: $0)
texture.filteringMode = SKTextureFilteringMode.nearest
return texture
},
timePerFrame: 0.15
)
frames variable is array of SKTextures. I've used map to set filtering mode for each texture. This works fine and dandy, but than i've discovered that i can create animations (actions) in ActionEditor in XCode with AnimateWithTextures action. And here lies my problem. This is much more efficient, but i can't change filtering mode for textures in animation in ActionEditor. I've looked into SKTexture class and saw this:
open class SKTexture : NSObject, NSCopying, NSCoding {
...
/**
The filtering mode the texture should use when not drawn at native size. Defaults to SKTextureFilteringLinear.
*/
open var filteringMode: SKTextureFilteringMode
...
}
If i'm not mistaken open means that i can override variable, but i don't know how. I want to set default value of filteringMode to SKTextureFilteringMode.nearest for all SKTextures so ActionEditor will use textures with texture filtering set to nearest neighbor.
Also if you know how to set filtering mode for textures in specific action – i would like to know how to do it too. Thanks
you can create a function to setup the animation for you, and create an extension to SKTexture with your custom init, and when your ready just call it to your node.
extension SKTexture { // Declare this extension outside your class decleration
convenience init(customImageNamed: String) {
self.init(imageNamed: customImageNamed)
self.filteringMode = .nearest
}
}
func setupAnimationWithPrefix(_ prefix: String, start: Int, end: Int, timePerFrame: TimeInterval) -> SKAction{
var textures = [SKTexture]()
for i in start...end{
textures.append(SKTexture(customImageNamed: "\(prefix)\(i)"))
}
return SKAction.animate(with: textures, timePerFrame: timePerFrame)
}
if you have 10 images named image1, image2, image3 ect..then this is how you would use this function
func runAction(){
let action = setupAnimationWithPrefix("image", start: 1, end: 10, timePerFrame: 0.1)
yourNode.run(action)
} // you can change timePerFrame to your liking i find 0.1 sec per frame the best
Unfortunately you can't override a variable without subclassing it, that is to do something like
class MyTexture: SKTexture {
from there, you could override the variable:
override var filteringMode: SKTextureFilteringMode {
get {
return .nearest
}
set {
}
}
That should work, but now you can't change the filtering mode, ever (without going through a bunch of hooplah).
So the more apt way would be to set the default value via the initializer, but SKTexture has no public designated initializers, so that option is out of the window.
So your best bet is going to be the convenience init extension by Arie, or just make a plain function that returns a new texture:
func nearestTexture(imageNamed name: String) -> SKTexture {
let newTex = SKTexture(imageNamed: name)
newTex.filteringMode = .nearest
return newTex
}
let texture: SKTexture = nearestTexture(imageNamed: "lol")
ActionEditor is still very limited in features, you are going to have to write some kind of code behind to allow for texture filtering. If you do not plan on scaling your sprites (Note I said sprite, not scene, these are two different behaviors), then I would not even worry about texture filtering, the time difference would be negligible.

Set a variable as the ID of a clicked div, then modify that variable to select a different div

I have multiple images and when I click on one I want the code to set that specific images ID ("image_select_1") as a variable. I then want to modify that variable by removing the text "select" (with underscores on either side of it) from the middle of it so the variable becomes "image1". Then use that variable to target a different DIV and fade it in. Here the is the code I have however it's of course, not working.
var foo;
$('.game_selection_image').click(function() {
foo = $(this).attr("id");
foo = foo.replace("_select_","");
$("#" + foo).fadeIn(500);
});
Any help would be greatly appreciated, thank you :)
Watch your variables
$("div.game_selection_image").click(function(e) {
var foo = $(this).attr("id");
foo = foo.replace("_select_","");
$('#' + foo).fadeIn(500);
});

how to access objectAtIndex:indexpath.row xcode?

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:
(NSInteger)component {
if(thePickerView == self.countryPicker){
self.countryLbl.text = [self.responseArray objectAtIndex:row];
}
}
- (IBAction)countryDoneBtn:(id)sender {
// Picker first row selected on done button
[self.countryLbl setText:[NSString stringWithFormat:#"%#", [self.responseArray
objectAtIndex:[self.countryPicker selectedRowInComponent:0]]]];
[self myViewDown:self.countryView];
[self.durationView removeFromSuperview];
//[post selectState:[self.responseArray objectAtIndex:row ]];
}
i want to do this "[post selectState:[self.responseArray objectAtIndex:row]];"
but can't access "objectAtIndex:row" here in this "- (IBAction)countryDoneBtn:(id)sender"
method.
Please friend help me how can i access the row from this IBAction
Thanks in advance need your help i'm new in iphone development
The row variable is not available because the row you are looking for is only passed in the delegate method didSelectRow:inComponent of the picker view.
Based on you are trying to do, you can still get the selected row of the picker with the method selectedRowInComponent, which you have already used to set the text of the countryLbl.
So, just use the same method to get the object from your responseArray:
NSInteger selectedRow = [self.countryPicker selectedRowInComponent:0];
[post selectState:[self.responseArray objectAtIndex:selectedRow]];

How do I refresh a TMS layer in OpenLayers?

I have a TMS layer that looks something like this:
var v = 1;
my_tms = new OpenLayers.Layer.TMS(
"My TMS",
"my_mapserver.php?v="+my_var+"&",
{ transparent: 'true', type:'png', getURL:get_my_url }
);
Where my_mapserver.php returns map tiles according to the value of v.
The app allows users to change v, and I simply want to refresh the my_tms layer, however, so far the only way I can get it to refresh is by destroying the map and recreating it.
I thought I could just do something like this:
v = 2;
my_tms = new OpenLayers.Layer.TMS(
"My TMS",
"my_mapserver.php?v="+my_var+"&",
{ transparent: 'true', type:'png', getURL:get_my_url }
);
my_tms.redraw();
However, these tiles are not getting requested when I redraw().
Any help is appreciated.
As TMS layers inherits from Grid layer you could try to call clearGrid() method to remove all existing tiles and then spiralTileLoad() to load new ones.
layer.redraw();, OpenLayers.Strategy.Refresh and clearGrid() didn't help me in reloading tiles of OpenLayers.Layer.TMS layer in OpenLayers 2.13.1, but helped:
layer.mergeNewParams({});