AR With Printed Buttons - augmented-reality

I made an AR Application that detects the printed marker & plays the video on it.
I'd like to have a button printed on paper, which triggers an event when its blocked by a finger.
IMAGE LINK: http://tinypic.com/view.php?pic=23le2h2&s=7
The application development is to have an AR Quiz that works with simple printed paper & Webcam only. What is the best solution to have the button event triggered by hiding the marker?
Operating System: Windows PC
Framework: FLARManager

You just need to listen when and what combination of markers is active and make if statments like:
private function onEnterFrame (evt:Event) :void
{
if (this.activeMarker_1 && this.activeMarker_2)
{
trace("no button is being pressed");
}
else if (this.activeMarker_1 && this.activeMarker_2 == null)
{
trace("answer: no");
}
else if (this.activeMarker_1 == null && this.activeMarker_2)
{
trace("answer: yes");
}
else if (this.activeMarker_1 == null && this.activeMarker_2 == null)
{
trace("both buttons are being pressed");
}
}

Related

UWP: WebView using the Mouse Forward and Backward Buttons

I'm developing a UWP-App with a WebView inside. At the WebView I want to use the forward and backward buttons of the mouse to navigate forward and backward. At default the WebView doesn't support it. (a normal browser does)
So I've found the PointerPressed Event and in this event I can check if the pointer-device is the mouse and if the pointer-properties are IsXButton1Pressed or IsXButton2Pressed. If I implement it on other usercontrols it works perfectly. But on the WebView usercontrol it doesn't work.
That's how I implemented it on other usercontrols:
private void Page_PointerPressed(object sender, PointerRoutedEventArgs e)
{
PointerPoint currentPoint = e.GetCurrentPoint(this);
if(currentPoint.PointerDevice.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse)
{
PointerPointProperties pointerProperties = currentPoint.Properties;
if(pointerProperties.IsXButton2Pressed)
{
if (grd_content.Children.Count == 1 && grd_content.Children[0] is Interfaces.IWebNavigation)
{
Interfaces.IWebNavigation iWebNav = (Interfaces.IWebNavigation)grd_content.Children[0];
e.Handled = iWebNav.GoForward();
}
}
else if(pointerProperties.IsXButton1Pressed)
{
if (grd_content.Children.Count == 1 && grd_content.Children[0] is Interfaces.IWebNavigation)
{
Interfaces.IWebNavigation iWebNav = (Interfaces.IWebNavigation)grd_content.Children[0];
e.Handled = iWebNav.GoBackward();
}
}
}
}
How can I implement the mouse forward and backward button on a WebView usercontrol?

Wait until a tap gesture from user?

In my spritekit game I would like users to choose starting positions on a map by tapping and then adding the sprite to the appropriate place. I am struggling to figure out how to make the game "wait" for the user input without advancing.
My initial thought was an infinite while loop, but that seems to simply freeze the game.
if self.settingsInstance.startPositionMode == "custom" {
for player in self.settingsInstance.gamePlayers {
if player.isPlayerHuman == true {
//Allow human to choose
player.isCurrentlyActive = true
while player.hasStartAssigned == false {
~ -> Wait until a tap gesture occurs
}
print("success!")
if player.hasStartAssigned == true{
player.isCurrentlyActive = false
}
}
}
}
In my tap handling function I first check for player.isCurrentlyActive == true and then set the .hasStartAssigned to true, but so far this method isnt working.
Does anyone have some pointers for how to "wait" for user input?
Thanks!

IOS Safari 8.1.3 WebAudio API doesn't stop in sleep mode

In HTML5 for IOS 8.1.3 Safari browser. I'm using a background music that continuously play in loop using AudioContext. On top of that, some voice over audio comes randomly for which I've used normal audio object (var _audio = new Audio()).
Everything working absolutely perfect as required. Now when I'm pressing the home button, the voice over stops immediately but the background music keeps on playing. Also if I resume the safari, voice over resumes playing from where it had stopped.
Couple of solutions came to my mind are:
Don't use loop property for the context. On ended callback re-play the context. But this not possible in my situation.
Use "pagehide" and "pageshow" event to know the browser going to or coming back from sleep. This is working for me but not on all devices. I'm checking this in multiple iPads and all of them are IOS 8. But strangely in some iPads the events are not getting trigger at all.
So I'm stuck here. Any suggestion would be appreciated. Thanks.
You might have more success using the page visibility api. It has good support across browsers and devices. To cover all the vendor prefixes do:
var hidden, visibilityChange;
function onVisibilityChange() {
if (document[hidden]) {
// hidden, stop audio
} else {
// shown, restart audio
}
}
if (typeof document.hidden !== 'undefined') {
hidden = 'hidden';
visibilityChange = 'visibilitychange';
} else if (typeof document.mozHidden !== 'undefined') {
hidden = 'mozHidden';
visibilityChange = 'mozvisibilitychange';
} else if (typeof document.msHidden !== 'undefined') {
hidden = 'msHidden';
visibilityChange = 'msvisibilitychange';
} else if (typeof document.webkitHidden !== 'undefined') {
hidden = 'webkitHidden';
visibilityChange = 'webkitvisibilitychange';
}
if(visibilityChange !== undefined) {
document.addEventListener(visibilityChange, onVisibilityChange, false);
}

Disable eventlistener temporarily till animation completes

I'm working on a basic flash fight game. I'm not a developer so i'm new to actionscript except that i have some background knowledge about coding from my course.
The problem is-
There are about 6 fighting moves and i want to disable all 6 key_down events till the animation completes. And all 6 animations have different time frames. Can some1 just help me out with this?
stage.addEventListener(KeyboardEvent.KEY_DOWN, enterKeyHandler);
function enterKeyHandler(event:KeyboardEvent):void {
if (event.keyCode == Keyboard.B) {
gotoAndPlay(252);}
if (event.keyCode == Keyboard.V) {
gotoAndPlay(259);}
I have put down only 2 of them but there 6 in total.
I would use a public static flag , ex:
keyboardDisabled:Boolean = false;
While you play your animations you could set this to true, and inside the function which listens to keyboard events just check if keyboard is disabled and return right away.
Some code would look like
public static var keyboardDisabled:Boolean = false;
stage.addEventListener(KeyboardEvent.KEY_DOWN, enterKeyHandler);
function enterKeyHandler(event:KeyboardEvent):void {
if ( keyboardDisabled )
return;
if (event.keyCode == Keyboard.B) {
gotoAndPlay(252);}
if (event.keyCode == Keyboard.V) {
gotoAndPlay(259);
}
Then in the frame where your animation begin
keyboardDisabled = true;
And on animation end
keyboardDisabled = false;

Process.Start opens too many browsers in XNA game

I'm creating a game in XNA that runs on a PC.
On the splash screen, the user has three options. If they press "Enter" the game will begin, if they press "M" they'll go to the Help menu and if they press "W" I want that to take them to my website.
I'm using Process.Start to open the browser to my website.
The problem is that when I press "W", sometimes it will open 1 browser with the website. However, most of the time it will open anywhere from 3 - 7 browsers simultaneously.
Why is it opening multiple browsers simultaneously?
How do I make it open only 1 browser when "W" is pressed?
Here is my code. I haven't built my website yet, so I'm using yahoo.com as the destination:
private void UpdateSplashScreen()
{
KeyboardState keyState = Keyboard.GetState();
if (gameState == GameState.StartScreen)
{
if (keyState.IsKeyDown(Keys.Enter))
{
gameState = GameState.Level1;
explosionTime = 0.0f;
}
if (keyState.IsKeyDown(Keys.M))
{
gameState = GameState.HelpScreen;
}
if (keyState.IsKeyDown(Keys.W))
{
Process.Start("IExplore.exe", "www.yahoo.com");
}
}
Thanks,
Mike
A common way to handle this is to always track the keyboard state from the previous frame. If a key wasn't down on the previous frame, but is down this frame then you know it was just pressed. If the key was down on the previous frame then you know it's being held down.
// somewhere in your initialization code
KeyboardState keyState = Keyboard.GetState();
KeyboardState previousKeyState = keyState;
...
private void UpdateSplashScreen()
{
previousKeyState = keyState; // remember the state from the previous frame
keyState = Keyboard.GetState(); // get the current state
if (gameState == GameState.StartScreen)
{
if (keyState.IsKeyDown(Keys.Enter) && !previousKeyState.IsKeyDown(Keys.Enter))
{
gameState = GameState.Level1;
explosionTime = 0.0f;
}
if (keyState.IsKeyDown(Keys.M) && !previousKeyState.IsKeyDown(Keys.M))
{
gameState = GameState.HelpScreen;
}
if (keyState.IsKeyDown(Keys.W) && !previousKeyState.IsKeyDown(Keys.W))
{
Process.Start("IExplore.exe", "www.yahoo.com");
}
}
I usually create a KeyPressed function which cleans things up a bit.
bool KeyPressed(Keys key)
{
return keyState.IsKeyDown(key) && !previousKeyState.IsKeyDown(key);
}
The code you are using runs about 60 times a second; you may only press your key down for 100ms or so but in that time it checks to see if W is pressed down about 7 times. As such, it opens a large number of browser windows.
Try recording a timestamp (using DateTime.Now) of when you open the browser and then check that a certain time has elapsed (~2 secs?) before allowing another window to be opened. Or, create a boolean flag that is set false by opening the browser, so the browser can be opened only once.
Thanks guys, that's what the problem was.
Callum Rogers solution was the easiest:
I declared a boolean:
bool launchFlag = false;
Then checked it and set it to true after the website launched.
private void UpdateSplashScreen()
{
KeyboardState keyState = Keyboard.GetState();
if (gameState == GameState.StartScreen)
{
if (keyState.IsKeyDown(Keys.Enter))
{
gameState = GameState.Level1;
explosionTime = 0.0f;
}
if (keyState.IsKeyDown(Keys.M))
{
gameState = GameState.HelpScreen;
}
if (keyState.IsKeyDown(Keys.W))
{
if (launchFlag == false)
{
Process.Start("IExplore.exe", "www.yahoo.com");
launchFlag = true;
}
}
}
I held the W key down for 30 seconds and it launched just 1 browser!
Thanks,
Mike

Resources