Which is Right Way to Add Joystick in Unity3d , Adding on Scene Directly or Iniatiating it From Player Scripts - user-controls

I have to add Joystick control in my Game
I had done with Two Approaches both works well for me , but confused Which one to go with.
1) Initiating Joystick Control from Players Object/Script and getting inputs there.
2) Add Joystick Control Directly to Game Scene and then accessing it in player script by findObjectwithTag and getting inputs .

Calling "Instantiate" and "GameObject.Find" is pretty expensive so in my opinion the efficient way is
1: Add Joystick Control Directly to Game Scene
2: Create a public object inside player and assign "joystick control" from inspector (Editor).

Related

MRTK Poke Pointer on different finger

I am trying to add the PokePointer to a different finger than the index finger. I have tried setting up custom Input Actions and Controller Definitions for that with no success.
How can I attach the PokePointer to a different finger for example the thumb so that I can press buttons with my thumb?
The SphereCast and FingerCurosr of PokePointer has been hardcode with Index Tip and does not expose any API to access. It is recommended to polling the joint pose from the controller and raise an event when the location of ThumbTip close to the button.

Phaser3 Scenes transitions

I'm new to Phaser3 and before starting a crazy project, I want to know how I should start, switch between scenes. I saw that there are several functions, start, launch, switch, run, resume, pause, etc.
Example, lets say I want to have 2 scenes, a Menu and a Game. I boot on the Menu and I want to go to the Game scene and if I click on a button then come back to the Menu scene.
I've achieved this by calling the start function, but I noticed that the all, init, preload and create functions are called every time and therefore I'm loading all the images, setting all the listener over and over again.
This seems wrong, should I be using the launch or switch functions and pausing and resuming? But how do I hide the previous scene?
Thanks in advance.
This question might be a little too broad, but with Phaser 3 in mind, it still depends upon what purpose your menu serves.
I think most games have a main menu that will generally be called when the game first starts, and then won't be called again.
If this is an in-game menu, where settings can be changed or part of the game can be reset/restarted, then it might not make sense to redirect to a completely different scene.
With Phaser 3's support of multiple scenes - with Dev Log #119 and Dev Log #121 probably being the best current sources of information - another option would be to start a new scene within the current scene to handle this.
However, if this is really just UI, there's nothing to stop you from creating an overlay, instead of spawning an entire scene.
If you're concerned about performance I might think about whether the entire menu needs to be called, or if a simplified menu would work. Also, make sure that you're preloading assets before you're in the menu and main game.
I personally use Boot > Preloader > Splash Screen > Main Menu > Main Game scenes, where the Preloader loads the majority of the assets I'll need. This has the downside of a longer initial load, but the upside of minimal loading after this point.
Scene Transitions
How I handle these in my starter templates is to add the scenes to the Scene Manager when creating the scene. Then I transition by start to the first scene.
this.scene.add(Boot.Name, Boot);
this.scene.add(Preloader.Name, Preloader);
this.scene.add(SplashScreen.Name, SplashScreen);
this.scene.add(MainMenu.Name, MainMenu);
this.scene.start(Boot.Name);
Then I simply keep starting the next scenes as needed.
this.scene.start(Preloader.Name);
For another game that uses multiple scenes I ended up creating the following function (TypeScript) to handle this:
private sleepPreviousParallelScene(sceneToStart: string): Phaser.Scene {
if (this.uiSceneRunning !== sceneToStart) {
// Make sure that we properly handle the initial state, when no scene is set as running yet.
if (this.uiSceneRunning !== "") {
this.scene.get(this.uiSceneRunning).scene.sleep();
}
const newScene = this.scene.get(sceneToStart);
newScene.scene.start();
this.scene.bringToTop(sceneToStart);
this.uiSceneRunning = sceneToStart;
return newScene;
} else {
return this.scene.get(this.uiSceneRunning);
}
}
In the game I was using this for, I was trying to replicate a standard tab interface (like what's see in the Dev Logs above with the file folder-like interface).
Ok, here is the deal. In phaser 3, the start function actually SHUTS DOWN the previous scene as it starts the new one. This is why you see the init, preload ext every time. If however, you 'launch' your scenes instead, then they will not go through the whole shut down, restart sequence. You can move them to the top or bottom, set to receive input or not, etc. HOWEVER, BEWARE! As of phaser 3.16, sleep or pause of a scene does NOT shut down the update. As a result, if you launch a scene, then sleep it, it basically does nothing other than maybe set the flag, saying it's asleep even though it really isn't. So any update processing will continue in any launched scene. You can short circuit the update with a flag of some sort at the beginning, (that's what I've resorted to), but the other gotcha is the camera size. All the scenes must therefore have the same camera size or they will render (even if "sleeping") and mess up your display.
So, bottom line, it's going to be messy until sleep and pause actually work.

Titanium: Sounds overlapping each other

Sorry if it looks like a noob question, but i'm new to titanium so some concepts are foreign to me.
I have a script called entry.js which is called from details.js using require('entry.js').
Now within entry.js i play a sound, depending on what entry is selected.
var player = Ti.Media.createSound({url:"/sounds/0"+e.id+".mp3"});
player.play();
That part is ok. The problem is when i go back to the details screen, and select another entry, the new sound overlaps the old one.
So i need a global value or object that i can pass down to entry.js to make sure if the sound is playing or not.
But if i declare a global TI.Media object in details.js i get an error in entry.js:
Cant find variable player
So the question is, how do i detect in a sub javascript file that an instance of audio is already running?
You can check whether the audio is playing using the isPlaying() method or try to stop the playing music when you get back to the details screen. You can use stop() method to stop the sound. It will stops playing the audio and resets the playback position to the beginning of the clip.
If you want to create a global variable or pass variable from one window to another, refer the following links
Passing parameters from currentWindow to the new window in Titanium
Passing variable between windows

How to draw a map using mkmapview with driving directions between map annotations

I'm developing an App with some maps functionalities (among other things), I'd like to draw a map from my current location to a given destination, but I do not want to use the shareadapplication, The shared application does not have a BACK button for example and some other navigation items I already have.
I want to do it in my own viewcontroller with mkmapview on it.
I already have the code to place the pin annotations, what I need is to trace the driving directions from A to B.
The other option is to use the [[UIApplication sharedApplication] openURL:url] call to appear inside the viewcontroller window so I can keep my navigation items.
Any ideas?
thnxs
You can't do the "other option". iOS apps do not run inside windows that you can put within your app, they are full screen apps and you can make you app switch to them, but you can't make other apps switch back to yours.
So, the big question is, where are you going to get driving directions from? Check out GoogleMapsSDK, OpenStreetMap and CloudMade, because iOS maps won't give you the directions.

show popovers on uilabel touch in iphone

I have a number of UILabels on a single view of a iphone application ios 4.3. How to handle touch events for all these labels at one time? I wanted to show pop overs on touch of that label. I know popovers are not available on iphone and will be making my custom ones.
what i did was using UITapGestureRecognizer and adding an action #selector(labelTap:) and then doing [label addGestureRecognizer:TapGestureRecognizerObject. But when i use the same UITapGestureRecognizer for all my UIlabels only the last added label shows the tap action.
i have set userInteractionEnable to YES.
Can any one point me to the right direction?
You need to create separate UITapRecognizer for tracking different UILabel, when a UIGestureRecognizer is added to multiple views, it will only track event from last it added to. To better understand why you need different instances of UITapRecognizer, think of it as a UIView that only handles touches event but doesn't do any drawing.

Resources