I have a huge problem with editing controls for my game.. I have an ingame button and when you click it. The "Choose your key.." text appears, but I don't know how to actually set it up..
I have made a "waiting for input" bool.. THIS IS NOT THE REAL CODE IT'S HOW I IMAGINE IT TO BE
if (buttonIsClicked) waitinForInput = true;
while(waitingForInput)
{
kbState = Keyboard.GetState();
somehow convert it to Keys.(STH);
if (Keys.STH != defaultKeys)
{
defaultKeys = Keys.STH;
waitingForInput = false;
}
}
Is there a way to do this.. Simpliest as I can? And sorry for my bad english.. Made this in a hurry and not my native language..
Thanks for any help.. :-)
Something like this:
KeyboardState currentKeyboardState = new KeyBoardState();
KeyboardState previousKeyboardState = new KeyBoardState();
Keys jumpKey = Keys.Space;
public void handleInput()
{
lastKeyboardState = currentKeyboardState;
currentKeyboardState = Keyboard.GetState(PlayerIndex.One);
bool waitingForKey = false;
if(currentKeyboardState.IsKeyDown(Keys.A) && waitingForKey == false)
{
waitingForKey = true;
}
if(waitingForKey == true)
{
//currentKeyboardState.GetPressedKeys() returns a list of pressed keys,
//So, currentKeyboardState.GetPressedKeys()[0] returns the first pressed key
if(currentKeyboardState.GetPressedKeys().Count() > 0)
{
jumpKey = currentKeyboardState.GetPressedKeys()[0];
waitingForKey = false;
}
}
}
Related
I have a listview and I want an Item to deselect if I tap it again. So basically I tap an Item it gets selected I tap it again it gets deselected.
My Code is working just fine on Android. It also works on iOS the only thing that doesn't work is if I tap an Item its background color changes but if I deselect it its background color should change back. That happens on Android but not on iOS. Any ideas why "mylistview.selecteditem = null" works properly on Android but not on iOS?
public void AnwesenheitTapped(object sender, ItemTappedEventArgs args)
{
if (args.Item as Anwesenheit != Anwesenheit)
{
Anwesenheit = args.Item as Anwesenheit;
ViewModel.Anwesenheit = args.Item as Anwesenheit;
if (Anwesenheit == null)
{
return;
}
ViewModel.AlsAbwesendEintragenButton = true;
ViewModel.Datum = Anwesenheit.Datum;
AnwesenheitenDatum.IsEnabled = false;
if (Anwesenheit.Anmeldungsart == "Früh")
{
Anmeldungsart.SelectedIndex = 0;
}
else if (Anwesenheit.Anmeldungsart == "Mittags")
{
Anmeldungsart.SelectedIndex = 1;
}
else
{
Anmeldungsart.SelectedIndex = 2;
}
AnwesenheitenLabel.Text = "Anwesenheit bearbeiten:";
AnwesenheitenButton.Text = "Anwesenheit bearbeiten";
ViewModel.Edit = true;
}
else
{
Anwesenheit = null;
ViewModel.Datum = DateTime.Today;
AnwesenheitenDatum.IsEnabled = true;
ViewModel.AlsAbwesendEintragenButton = false;
Anmeldungsart.SelectedIndex = 0;
ViewModel.Edit = false;
AnwesenheitenLabel.Text = "Neue Anwesenheit:";
AnwesenheitenButton.Text = "Neue Anwesenheit hinzufügen";
BetreuungsoptionenListView.SelectedItem = null;
}
}
What is your Xamarin Forms version, there is a bug in Xamarin Forms 3.5 for iOS listview, which is fixed in version 3.6
I am creating an inkcanvas (CustomInkCanvas) that receives Gestures. At different times during its use, I am placing additional panels over different parts of the inkcanvas. All is well, and the part of the CustomInkCanvas that is not covered by another panel responds appropriately to ink and gestures.
However, occasionally a Gesture is not recognized, so in the default code of the gesture handler, I am trying to remove the ink from the CustomInkCanvas--even when it is not the uppermost panel.
How is this done?
Note: I have tried everything I can think of, including:
Dispatcher with Background update as:
cink.InkPresenter.Dispatcher.Invoke(DispatcherPriority.Background, EmptyDelegate);
Clearing the strokes with:
Strokes.Clear();
cink.InkPresenter.Strokes.Clear();
Invalidating the visual with:
cink.InkPresenter.InvalidateVisual();
cink.InavlidateVisual();
And even
foreach (Stroke s in Strokes)
{
cink.InkPresenter.Strokes.Remove(s);
}
Here is the full code...
void inkCanvas_Gesture(object sender, InkCanvasGestureEventArgs e)
{
CustomInkCanvas cink = sender as CustomInkCanvas;
ReadOnlyCollection<GestureRecognitionResult> gestureResults = e.GetGestureRecognitionResults();
StylusPointCollection styluspoints = e.Strokes[0].StylusPoints;
TextBlock tb; // instance of the textBlock being used by the InkCanvas.
Point editpoint; // user point to use for the start of editing.
TextPointer at; // textpointer that corresponds to the lowestpoint of the gesture.
Run parentrun; // the selected run containing the lowest point.
// return if there is no textBlock.
tb = GetVisualChild<TextBlock>(cink);
if (tb == null) return;
// Check the first recognition result for a gesture.
isWriting = false;
if (gestureResults[0].RecognitionConfidence == RecognitionConfidence.Strong)
{
switch (gestureResults[0].ApplicationGesture)
{
#region [Writing]
default:
bool AllowInking;
editpoint = GetEditorPoint(styluspoints, EditorPoints.Writing);
at = tb.GetPositionFromPoint(editpoint, true);
parentrun = tb.InputHitTest(editpoint) as Run;
if (parentrun == null)
{
AllowInking = true;
TextPointer At = tb.ContentEnd;
Here = (Run)At.GetAdjacentElement(LogicalDirection.Backward);
}
else
{
Here = parentrun;
AllowInking = String.IsNullOrWhiteSpace(parentrun.Text);
}
*** THIS FAILS TO REMOVE THE INK FROM THE DISPLAY ???? *********
if (AllowInking == false)
{
foreach (Stroke s in Strokes)
{
cink.InkPresenter.Strokes.Remove(s);
}
// remove ink from display
// Strokes.Clear();
// cink.InkPresenter.Strokes.Clear();
cink.InkPresenter.InvalidateVisual();
cink.InkPresenter.Dispatcher.Invoke(DispatcherPriority.Background, EmptyDelegate);
return;
}
// stop the InkCanvas from recognizing gestures
EditingMode = InkCanvasEditingMode.Ink;
isWriting = true;
break;
#endregion
}
}
}
private static Action EmptyDelegate = delegate() { };
Thanks in advance for any help.
It would be nice to get a guru response to this, but for anybody else getting here, apparently the strokes that go into creating the gesture have not yet been added to the InkCanvas, so there is nothing to remove or clear from the inkcanvas from within the gesture handler. Strokes are only added to the InkCanvas AFTER the gesture handler. The solution this newbie ended up with was to set a flag when ink was not allowed, and then act on it in the StrokesChanged handler like:
if (AllowInking == false)
{
ClearStrokes = true;
return;
}
void Strokes_StrokesChanged(object sender, StrokeCollectionChangedEventArgs e)
{
if (ClearStrokes == true)
{
ClearStrokes = false;
Strokes.Clear();
return;
}
All works now. Is there a better way?
How can i do this:
I have 5 incentive images. I need to display each image if my bool variable is true.
Here's What I did:
BOOL var1 = true;
BOOL var2 = true;
BOOL var3 = false;
BOOL var4 = true;
BOOL var5 = false;
if(var1)
{
cell.incentive1.hidden = false;
}
if(var2)
{
cell.incentive2.hidden = false;
}
if(var3)
{
cell.incentive3.hidden = false;
}
if(var4)
{
cell.incentive4.hidden = false;
}
if(var5)
{
cell.incentive5.hidden = false;
}
this is working..
I have a follow up question,
how will i be able to display the var4's uiimageview var2's uiimageview. I need the uiimageview to be dynamically created. That when the app detects the bool variables that are true there will be no gaps.
thanks..
When you use if..else if condition, if any one condition passes then the remaining will not be evaluated.
So for fixing the issue, you need to change all to if conditions.
But I'll suggest using like following is a better approach (There is no need of if else conditions):
cell.incentive1.hidden = !var1;
cell.incentive2.hidden = !var2;
cell.incentive3.hidden = !var3;
cell.incentive4.hidden = !var4;
cell.incentive5.hidden = !var5;
You should not use if...else as all images are independent. You should:
if(var1)
{
cell.incentive1.hidden = false;
}
if(var2)
{
cell.incentive2.hidden = false;
}
if(var3)
{
cell.incentive3.hidden = false;
}
if(var4)
{
cell.incentive4.hidden = false;
}
if(var5)
{
cell.incentive5.hidden = false;
}
You've got chained if..else if statements going on there. This means that once one of the conditions is satisfied, the entire evaluation is done and it jumps to the next bit of code. Remove the else everywhere, so that every condition is evaluated in isolation.
Try this.
cell.incentive1.hidden = (var1 == true)?true:false;
cell.incentive2.hidden = (var2 == true)?true:false;
cell.incentive3.hidden = (var3 == true)?true:false;
cell.incentive4.hidden = (var4 == true)?true:false;
cell.incentive5.hidden = (var5 == true)?true:false;
As given code if var 1 is true then it will goes to 1st block other wise it goes to next.
and best way to hide and display images you can set alpha 0 for hide and 1 for display.
I'm trying to use isVisible() within a loop to create a waitForElement type of a function for my iOS UIAutomation. When I try to use the following code, it fails while waiting for an element when a new screen pops up. The element is clearly there because if I do a delay(2) before tapping the element it works perfectly fine. How is everyone else accomplishing this, because I am at a loss...
Here's the waitForElement code that I am using:
function waitForElement(element, timeout, step) {
if (step == null) {
step = 0.5;
}
if (timeout == null) {
timeout = 10;
}
var stop = timeout/step;
for (var i = 0; i < stop; i++) {
if (element.isVisible()) {
return;
}
target.delay(step);
}
element.logElement();
throw("Not visible");
}
Here is a simple wait_for_element method that could be used:
this.wait_for_element = function(element, preDelay) {
if (!preDelay) {
target.delay(0);
}
else {
target.delay(preDelay);
}
var found = false;
var counter = 0;
while ((!found) && (counter < 60)) {
if (!element.isValid()) {
target.delay(0.5);
counter++;
}
else {
found = true;
target.delay(1);
}
}
}
I tend to stay away from my wait_for_element and look for any activityIndicator objects on screen. I use this method to actual wait for the page to load.
this.wait_for_page_load = function(preDelay) {
if (!preDelay) {
target.delay(0);
}
else {
target.delay(preDelay);
}
var done = false;
var counter = 0;
while ((!done) && (counter < 60)) {
var progressIndicator = UIATarget.localTarget().frontMostApp().windows()[0].activityIndicators()[0];
if (progressIndicator != "[object UIAElementNil]") {
target.delay(0.25);
counter++;
}
else {
done = true;
}
}
target.delay(0.25);
}
Here is a simple and better one using recursion. "return true" is not needed but incase u want it.
waitForElementToDismiss:function(elementToWait,waitTime){ //Using recursion to wait for an element. pass in 0 for waitTime
if(elementToWait && elementToWait.isValid() && elementToWait.isVisible() && (waitTime < 30)){
this.log("Waiting for element to invisible");
target.delay(1);
this.waitForElementToDismiss(elementToWait, waitTime++);
}
if(waitTime >=30){
fail("Possible login failed or too long to login. Took more than "+waitTime +" seconds")
}
return true;
}
Solution
I know this is an old question but here is my solution for a situation where I have to perform a repetitive task against a variable timed event. Since UIAutomation runs on javascript I use a recursive function with an empty while loop that checks the critical control state required before proceeding to the next screen. This way one never has to hard code a delay.
// Local target is the running simulator
var target = UIATarget.localTarget();
// Get the frontmost app running in the target
var app = target.frontMostApp();
// Grab the main window of the application
var window = app.mainWindow();
//Get the array of images on the screen
var allImages = window.images();
var helpButton = window.buttons()[0];
var nextButton = window.buttons()[2];
doSomething();
function doSomething ()
{
//only need to tap button for half the items in array
for (var i=0; i<(allImages.length/2); i++){
helpButton.tap();
}
//loop while my control is NOT enabled
while (!nextButton.isEnabled())
{
//wait
}
//proceed to next screen
nextButton.tap();
//go again
doSomething();
}
I have a Flash slideshow that plays SWFs listed in an XML file. I would like to have the upcoming SWF load while the current one displays. I've tried all sorts of combinations of LoadMovie and LoadMovieNum, including creating an empty movie clip, but there's something I'm just not getting.
Right now, after making the first round through all the files, it transitions smoothly from slide to slide, but I'd like for it to preload so that it transitions without the "Loading..." screen the first time around.
It can be viewed here: slideshow
Where should I put the LoadMovie line to load the next file (image[p+1]), and how should it look?
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
description = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
description[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
}
firstImage();
} else {
content = "file not loaded!";
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("xmlfile.xml");
/////////////////////////////////////
back_btn.onRelease = function ()
{
backImage();
};
next_btn.onRelease = function ()
{
nextImage();
};
p = 0;
function nextImage() {
if (p<(total-1)) {
p++;
trace(this);
_root.mc_loadfile.loadMovie (image[p]);
_root.movie_name.text = image[p];
next_btn._visible = true;
back_btn._visible = true;
if (getBytesLoaded() == getBytesTotal())
slideshow();
}
else if (p == (total-1)) {
p = 0;
firstImage();
}
}
function backImage() {
clearInterval(myInterval);
if (p>0) {
--p;
_root.mc_loadfile.loadMovie (image[p]);
_root.movie_name.text = image[p];
next_btn._visible = true;
if (p != 0) {
back_btn._visible = true;
}
else {
back_btn._visible = false;
}
slideshow();
}
}
I'd appreciate any help.
You can do it with the MovieClipLoader class. A brief tutorial can be found at actionscript.org, or you can check the docs on it.