I am making a multiplayer game where timer needs to be started onStop and stopped onResume - countdowntimer

I have tried making a multiplayer game where if a user comes out of the activity , a timer starts for declaring him loser of the game in Onstop and onPause , but if he returns i want to stop timer in onResume or onPause without disturbing the flow of the game and continuing with stopping the timer and no winner declared . I have tried CountdownTimer but the problem is that it starts declared the winner but doesn't stop when i re-enter the activity . Can you please tell me an alternative solution . I have tried making it null , cancel and all other stuff it didnt work

Related

Nativescript - ActivityIndicator not working for a specific chunk of code

I'd like to display an activity-indicator displayed when I do a long process.
I set a model busy flag to true.
I then call a method that returns a Promise - when the promise calls resolve, I then set the busy flag to false in my 'then' handler.
When I wait for the promise to resolve, I expect the Activity Indicator animation to be displayed but it's not.
I checked and made sure the UI set up is correct and it works.
The work that's being done is using nativescript-calendar plugin - I'm adding a few calendar entries.
I commented out the work that's being done and just went to sleep for a little bit and then called resolve() and the animation worked.
So the Activity Indicator and the Promise mechanism is setup correctly - it's something this plug-in is doing that's causing the AI not to display.
What could cause such a behavior?
I actually edited the Promise work code - put to sleep for about 1 second and then started the calendar work. I see the AI for 1 second and then it freezes.
So it looks like the calendar writes is causing the AI to freeze.
I was under the understanding that Promise work is done in the background and should not effect foreground animation.
I've had a similar issue when using SQLite.
As you haven't explicitly stated that your running the calendar in a worker I am assuming your keeping it in the UI thread (main thread).
Any large amount of work done in the UI thread will cause noticeable lag/delays. So for example you call the activity-indicator then call a process that maxes out the thread, the process finishes the activity indicator goes to be drawn on the screen but then is hidden straight away before it is displayed as the process is finished.
The ideal way to solve this is to move the calendar writes code into a worker (multithread your app) and on success message turn off the activity-indicator.

Live Timer // Parse & Swift

Im trying to figure out how can I do a live 30 second timer which every 30 second something happens. No matter who opens the app the timer will continue to run even if you just open the app and the timer might be on 20s or 10s or even 1s. And right when it hits zero, I have something that pops up.
I have it done but it's a timer that starts when the app is view is opened and always starts from 30s and if someone else opens the app he also starts from 30s i want it so that who ever opens the view the timer is still running.

Autohotkey: multiple / contingent uses for one command

I'm working on a game design / UI project to redesign an existing game's control scheme (in this case, Trine) to use minimalistic input. I am trying to map lateral movement and the jump function to a Win8 tablet's volume buttons. Here is the basic code I am using:
Volume_Up::
Loop 5
{
Send {right down}
Sleep 50
}
Send {right up}
Return
Volume_Down::
Loop 5
{
Send {left down}
Sleep 50
}
Send {left up}
Return
This is working fairly well and is pretty responsive for moving left and right. However, the desired behavior that I want is to trigger jump (i.e. up) when BOTH buttons are depressed. For instance:
Player holds VolumeUp to move right.
Player comes to an obstacle.
Player continues to hold VolumeUp to queue right-bound movement and;
Player taps VolumeDown momentarily
Player jumps, movement continues up-and-over obstacle toward the right.
I have tried various permutations on using another script with the (Volume_Up & Volume_Down::) syntax to trigger this interaction, but that always seems to interfere with the movement commands. I think this may call for a nested If statement inside the move-left / move-right commands, to check if both buttons are depressed, but the Autohotkey documentation is not very clear and I'm unsure how to code that (I'm more of a game designer than I am a programmer). Any help would be really appreciated!
First of all, give attention to the comment from MCL. Pressing a button down 5 times and never releasing it in between does not seem to do much.
I think that you want multiple threads to be able to run at the same time.
Look up threads, but be aware about the following:
"Although AutoHotkey doesn't actually use multiple threads, it simulates some of that behavior: If a second thread is started -- such as by pressing another hotkey while the previous is still running -- the current thread will be interrupted (temporarily halted) to allow the new thread to become current. If a third thread is started while the second is still running, both the second and first will be in a dormant state, and so on."

DispatcherTimer not updating with AdControl running

I have a simple app that I am creating with a countdown timer that uses a DispatcherTimer for the time base. I have an event handler setup for On_Tick of the DispatcherTimer (set for 1 sec interval). I have three (3) pivot pages using three different instances of AdControl and all are "live" with a real ApplicationID and AdUnitID. This timer is setup on one of the pivot pages.
What I am seeing is that when I open my app and the AdControl starts, after 60 seconds, the adControl wants to refresh. My timer works fine for the first minute, then starts to lose a second every three seconds, like it is missing a tick event (coincidentally when the adcontrol "scrolls" to a new message every three seconds?). I've tried using a background worker for the dispatcherTimer but that did not seem to do anything for me. The code in the event handler is fairly short, with just a couple of "if-then" statements and a few textBlock updates.
Anyone else seen similar issues with the AdControl?
I would say the reason is that the ad control and the timer both want to do something on the UI thread. Thus when the ad control is busy the timer action is blocked during this time. To quote MSDN:
Timers are not guaranteed to execute exactly when the time interval
occurs, but they are guaranteed to not execute before the time
interval occurs. This is because DispatcherTimer operations are placed
on the Dispatcher queue like other operations. When the
DispatcherTimer operation executes is dependent on the other jobs in
the queue and their priorities.
It also explains why using a background worker does not help. As soon as you go back from another thread to the UI thread you have the same problem again. So this issue is basically by design.
Oh and it can also be the other way round. If you would be doing intensive work in the UI thread then the ad control would be blocked. As well as the rest of your UI. This is the reason why you should do as much work as possible in background threads. Maybe the ad control doesn't adhere to this advice.
So far this probably won't help you much. But perhaps it is possible to just use one AdControl and move this from Pivot to Pivot as the user pans around?
I've experienced the same problem with my own timer style app. In my case it only appears to happen when there is animation in the current advertisement.
According to the DispatcherTimer documentation, the delay is expected behaviour, so the solution it to use a different timer... eg System.Threading.Timer
...
//create the timer
var timer = new System.Threading.Timer(
new System.Threading.TimerCallback(TimerTick),
null,
//Set the due time to infinite so the timer wont start immediately
System.Threading.Timeout.Infinite,
0);
//start the timer
timer.Change(0, 1000);
//stop the timer
timer.Change(System.Threading.Timeout.Infinite, 0);
}
void TimerTick(object state)
{
//Dont forget to update the UI on the UI thread.
Dispatcher.BeginInvoke(() =>
{
MyTextBox.Text = "New Text";
});
}
Problem solved!

Close browser/Exit from website Events

Nowadays I am creating browser game, using ASPX, CSS and AJAX.
I need to know when the user close the browser or exit from website,
because of these cases for example:
if a player opens a game room and than close the browser or exit from the website,
this room need to be deleted immediately.
2 players are playing in a room, and than one of them leave so the game is finished and the one that stay is the winner.
In this case I can use the countdown timer of the players' turns, and when the countdown timer reaches 0 - The other player wins,
but I prefer that the message will appear as soon as the player left the room,
its faster, and when the countdown reaches 0 there is 2 possibilities - the player left or the player didn't react in time.
Anyone can tell me how can I know when the user close the browser or exit from my website?
because as far as I know the Session object won't be effective since the Session_End method runs several minutes after the browser is close or the user is AFK,
and I can't let the Session_End close the room for players that are AFK since they are waiting for more players to join, and I need to fire my events immediately.
P.S: I found this method, I don't know if its works but I don't think it will fit my needs because I need the event to fire even when the user move from my site to another website.
Ext.EventManager.on(window, 'beforeunload', function() {
alert('cross-exit tab click AND cross-exit browser click');
});
The onbeforeunload event fires before the user leaves a page. This fires when the user closes the browser or tab, or goes to another page, even if that page is on your own website.
Inside the event handler, you'd make a call back to your server saying that the session was closed. Note that this will have to be an authenticated call with a crumb to avoid an XSRF (ie, player B tricks player A into ending his session).
The only caveat is that it does not work on Opera. For opera, you could use the onunload event, but since this fires when the browser is closed, it's very hard to send anything back to your server in this event handler.
Handling onbeforeunload will probably work.

Resources