I'm making a prototype game that involves a menu and a main scene. And while the main scene isn't big enough that the get_tree().change_scene("res://Main.tscn") thread block is a problem, I wanted to develop a loading so that I can show this functionality working.
The issue is that the loader.poll() isn't loading all "polls" (it loads 8 out of 9).
I've looked at the docs from the Godot, and I still havet found the issue neither how to solve it.
Thanks a bunch for the help! :)
Here is the function that loads the scene
func load_scene(scene_path): #receives the path to the next scene
var loader = ResourceLoader.load_interactive(scene_path)
#Disable some buttons and displays the progress bar animation
$Animation.visible = true
$X.disabled = true
$Creditos.disabled = true
$About.disabled = true
$PlayButton.disabled = true
$Sair.disabled = true
while not loader.poll():
var percentage_complete = (loader.get_stage()*100.0)/loader.get_stage_count()
$Animation/Label/ProgressBar.value = percentage_complete #updates the progress bar
Well, dumb me was counting the times that the code entered the while, and so, it would be always one less... Problem solved... :D
Related
I'm currently trying to make an explosion when a node hits the ground, but there's no explosion. I played the explosion scene and it works just fine. I tried spawning a different object and it works just fine. I checked the position of the explosion and it's the same as the body position. The explosion shows up in the inspector but not in game.
func _on_Ground_body_shape_entered(body_id, body, body_shape, local_shape):
print("collision")
var scene = load("res://Rock/Explosion.tscn")
var explosion = scene.instance()
add_child(explosion)
explosion.global_position = body.global_position
explosion.emitting = true
print(explosion.position)
print(body.position)
body.queue_free()
"load" isn't a thing, do var scene = preload("res://Rock/Explosion.tscn")
When you select an object with FabricJS the depth is changed so that it appears on top of everything else. I'd like to stop this from happening.
The selection border and handles should be on top, but the object itself should be behind the other objects so that users can see how it will be positioned once they have finished moving it around.
Is there an easy way to do this?
I've now found out the answer. You have to pass preserveObjectStacking = true to the constructor.
eg
canvas = this.__canvas = new fabric.Canvas('YOUR_CANVAS_NAME', {preserveObjectStacking: true});
I am trying to make a (new in 10.10) NSSplitViewItem collapse and uncollapse whilst moving its containing window so as to keep the whole thing "in place".
The problem is that I am getting a twitch in the animation (as seen here).
The code where I'm doing the collapsing is this:
func togglePanel(panelID: Int) {
if let splitViewItem = self.splitViewItems[panelID] as? NSSplitViewItem {
// Toggle the collapsed state
NSAnimationContext.runAnimationGroup({ context in
// special case for the left panel
if panelID == 0 {
var windowFrame = self.view.window.frame
let panelWidth = splitViewItem.viewController.view.frame.width
if splitViewItem.collapsed {
windowFrame.origin.x -= panelWidth
windowFrame.size.width += panelWidth
} else {
windowFrame.origin.x += panelWidth
windowFrame.size.width -= panelWidth
}
self.view.window.animator().setFrame(windowFrame, display: true)
}
splitViewItem.animator().collapsed = !splitViewItem.collapsed
}, completionHandler: nil)
}
}
I am aware of the "Don't cross the streams" issue (from session 213, WWDC'13) where a window resizing animation running on the main thread and a core animation collapse animation running on a separate thread interfere with each other. Putting the splitViewItem collapse animation onto the main thread seems like the wrong approach and I've got a nagging feeling there's a much better way of doing this that I'm missing.
Since I am not finding any documentation on the NSSplitViewItems anywhere (yet) I would appreciate any insights on this.
I have the little test project on GitHub here if anyone wants a look.
Update The project mentioned has now been updated with the solution.
Thanks,
Teo
The problem is similar to the "don't cross the streams" issue in that there are two drivers to the animation you've created: (1) the split view item (2) the window, and they're not in sync.
In the example from the '13 Cocoa Animations talk, constraints were setup to result in the correct within-window animation as only the window's frame was animated.
Something similar could be tried here -- only animating the window's frame and not the split view item, but since the item manages the constraints used to (un)collapse, the app can't control exactly how within-window content animates:
Instead the split view item animation could completely drive the animation and use NSWindow's -anchorAttributeForOrientation: to describe how the window's frame is affected.
if let splitViewItem = self.splitViewItems[panelID] as? NSSplitViewItem {
let window = self.view.window
if panelID == 0 {
// The Trailing edge of the window is "anchored", alternatively it could be the Right edge
window.setAnchorAttribute(.Trailing, forOrientation:.Horizontal)
}
splitViewItem.animator().collapsed = !splitViewItem.collapsed
}
For anyone using Objective C and targeting 10.11 El Capitan.
This did the trick for me, didn't need to set AnchorAttributes.
splitViewItem.collapsed = YES;
I've noticed that the OM Script gets commented when I add a bitmap in either the Icon/Diagram View.
I'm using OpenModelica 1.9.1+dev (r18667) (RML version)
Code for reference
model Test
annotation(Diagram(coordinateSystem(extent = {{-100,-100},{100,100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2,2}), graphics = {Bitmap(origin = {0.12,-0.47}, extent = {{-99.77,99.65000000000001},{99.77,-99.65000000000001}}, fileName = "modelica://Test/C:/Users/MSK/Desktop/Capture.PNG")}));
end Test;
This may be a bug. Hence I've reported it
OpenModelica bug reports should be reported at: https://trac.openmodelica.org/OpenModelica/newticket
And yes, it is a bug so it does not really belong on stackoverflow.
I have a little trouble with a progress bar since iOS 5 came out. The code below was working fine before iOS 5 but with iOS 5 the progress bar is no longer displaying the new progress that is set within a loop.
The code is expected to work like this:
Create the progress bar (works)
In a new background process: Set an initial progress of 0.25 (works)
In the same background process: Update the progress while going thru the loop (worked in iOS 4)
Here's the code for the bar init:
// create a progress bar
UIProgressView *progressBar = [[UIProgressView alloc] initWithFrame:CGRectMake(coverSizeX*0.25, coverSizeY - 34.0, coverSizeX*0.5, 9.0)];
progressBar.progress = 0.0;
progressBar.progressViewStyle = UIProgressViewStyleBar;
and in a different thread it sets a starting point for the progress to 0.25:
// set an initial progress
[progressBar setProgress: 0.25];
a little later it is updating the progress within a loop to display the download progress:
// within a for-loop:
NSNumber *counterPercentage;
for ( pageDownload = 1; pageDownload < pagesToDownload; pageDownload++ ) {
counterPercentage = [[NSNumber alloc] initWithFloat: (float)pageDownload / (float)((float)pagesToDownload)];
[progressBar setProgress: [counterPercentage floatValue]];
[progressBar performSelectorOnMainThread:#selector(setNeedsDisplay) withObject:nil waitUntilDone:YES];
}
… but the progress is not shown on the screen, the progress bar is stuck at the initial 0.25 progress that was set.
Were there any changes with the iOS 5 release that could have broken it?
I've seen a lot of questions like this one since the iOS 5 switch, and I'm not sure why there is a problem only in iOS 5. But mainly because I'm not sure why there wasn't a problem before.
In your code you call [progressBar setProgress: [counterPercentage floatValue]]; from a background thread. This is a UI call and should not be made from a background thread. Also you call setNeedsDisplay which is not necessary to update the progressBar since an UIProgressView knows how to display itself. iOS 5 seems to have made the requirements for updating the UI more stringent, but only to the point of what are best practices anyway.
To my eye this looks like a perfect use for blocks. Using blocks your for loop could be written this way:
for ( pageDownload = 1; pageDownload < pagesToDownload; pageDownload++ ) {
// Other stuff in background
dispatch_async(dispatch_get_main_queue(), ^{
progressBar.progress = ((float)pageDownload/(float)pagesToDownload);
});
// Other stuff in backgroud
}
It does work in iOS 5 and the easiest way to to it is here:
.h file:
IBOutlet UIProgressView *WhateverYouWantToCallIt;
.m file:
[WhateverYouWantToCallIt setProgress:(float) 0.3];
And where it says 0.3, you can put whatever value you like (within 0 to 1)