unity instantiated player with photon attaching to cinemachine - 2d

So before i used photon i used to have the player attached to the cinemachine camera in the inspector but now that im instantiating the player at runtime i really have no clue how that works, im making a 2d topdown game so i cant have the camera on my player prefab because it will rotate all crazy when i move my mouse.
is there a way to have all players each their own camera? i also dont want to destroy other people's cameras but disable them so i can re enable them later (spectating).
thanks!

The solution seemed to be really simple, i simply disabled the camera objects by default and enabled them if IsMine is true
if(view.IsMine)
{
myCinemachine.SetActive(true);
}
else
{
myCinemachine.SetActive(false);
}

did you put this code in the update or start
i mean this code
if(view.IsMine)
{
myCinemachine.SetActive(true);
}
else
{
myCinemachine.SetActive(false);
}

Related

Best Practices to implement a menu system in a QML game?

I'm relatively new to QML/QtQuick 2 and I quite enjoy it. To start mastering it I am implementing a small fullscreen game. My idea is to have the (simple) game and when the uses presses up the ESC key to pop-up a graphical menu with some settings.
Now I have all the basics running but I'm not completely sure which is the best Declarative way of managing the menu and passing keyboard focus back and forth.
Is it better to statically create the menu and make it hidden in my main file, like this:
MyMenuSystem {
visible: false
}
and then set it to "visible" when I need it? Or defer loading it and use Loader and create a new instance? I prefer to have it declared in my QML code for cleanness, but what is the best practice here? Or is there some component to switch between views that I'm completely missing? I could find very little information and examples on this topic. Thanks!
Your question is kinda broad and could lead to opinionated answers, but since it's a topic close to my heart, I thought I'd try to give some advice.
Loader
I tend to only use Loader when the item I need to load is only relevant under certain circumstances. For example, if a document is open that doesn't support a certain feature, then the UI element that represents that feature can be put into a Loader. A benefit of this (besides a (usually) very small increase in performance) is that it avoids the need to add lots of null checks for that feature. For example, if you don't use a Loader in this case, you might end up with a lot of code that looks like this:
text: optionalFeature.foo ? optionalFeature.foo.bar : ""
With a Loader, you control when the item is loaded, such that it's only loaded when the optional feature is enabled. Then the code becomes much nicer:
text: optionalFeature.foo.bar
Popup
For an in-game menu, I'd use a Popup. This is good if you want the user to be able to see the game in the background, though you can also obscure that with an overlay, if you wanted.
StackView
If you don't want to use a popup, then I'd suggest StackView. You should probably be using this for each screen in your game anyway, as it is a perfect fit for it.
Here's how I managed to do a Menu System:
I used Component to create a Component and createObject() to turn it into an instance of that component.
MyMenu.qml:
import QtQuick 2.9
Popup {
/* Menu Item 1 */
/* etc etc */
}
Game.qml:
Component {
id: myMenuId
MyMenu {
}
}
Game {
id: myGameId
property var dynamicItem
Keys.onPressed: {
if (event.key == Qt.Key_ESC) {
dynamicItem = myMenuId.createObject(myGameId);
dynamicItem.open()
}
}
}

How can I get the keyboard Caps Lock state in javafx

In my project, how to keyboard caps lock on state. i have refer this question How can I get the Caps Lock state, and set it to on, if it isn't already?. but i am get solution in javafx. please give me solution.I am also ref for this site https://community.oracle.com/thread/2415027?tstart=0
You will want this import:
import java.awt.Toolkit;
If you are wanting it on no matter what, just turn it on with:
Toolkit.getDefaultToolkit().setLockingKeyState(KeyEvent.VK_CAPS_LOCK, true);
If you want to check first if it is off, then turn it on:
if (!Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK)) {
Toolkit.getDefaultToolkit().setLockingKeyState(KeyEvent.VK_CAPS_LOCK, true);
}
Lastly, if you want to toggle between the two states:
if (Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK)) {
Toolkit.getDefaultToolkit().setLockingKeyState(KeyEvent.VK_CAPS_LOCK, false);
} else {
Toolkit.getDefaultToolkit().setLockingKeyState(KeyEvent.VK_CAPS_LOCK, true);
}
I don't think it is possible to query the capslock/numlock state directly in JavaFX 8. Robert's solution uses the AWT Toolkit, which is not JavaFX, but should work for you. You might want to create a feature request in the JavaFX issue tracker for locking key state tracking.

I want to make the browser fullscreen through my flex website

I have a website which is built totally in flex.
I want to make a button, on the click of which the browser becomes fullscreen. I am not talking about a flex fullscreen, by which i mean "Application.application.stage.displayState = StageDisplayState.FULL_SCREEN;" I dont want to use this.
The reason, I dont want to use it is, that flash does not supports keyboard on flex-fullscreen. But if i can make the browser fullscreen, it will solve my purpose.
Also i am hoping the same method will be good for all browsers on PC and Mac both.
Use ExternalInterface to call a javascript function for it. Sorry this solution is half-baked so I'm not 100% sure it works..
//In ActionScript
public function fullScreen():void
{
if (ExternalInterface.available)
{
ExternalInterface.call("fullScreen");
}
else
{
//Error
}
}
//In JavaScript
function fullScreen()
{
if (parseInt(navigator.appVersion)>3) {
moveTo(0,0);
resizeTo(screen.availWidth,screen.availHeight);
}
//on older browsers just leave it alone
}
i did the same work using thw solution for which you r saying no, u r saying the keyboard doesn't work, but it's working in ma case
here is the button code :
<mx:Button id="fullscreen" styleName="fullscreen" click="toggleFullScreen();"/>
and here is the function which gets called :-
private function toggleFullScreen():void
{
if(Application.application.stage.displayState == StageDisplayState.NORMAL)
Application.application.stage.displayState = StageDisplayState.FULL_SCREEN;
else if(Application.application.stage.displayState == StageDisplayState.FULL_SCREEN)
Application.application.stage.displayState = StageDisplayState.NORMAL;
}
also there are some files , that u need to copy in the html-template folder:-
i'll send u those files, mail me ankursharma85#in.com, i'll reply u
and yes, when u r in full screen mode, u can press "esc" key to get to the normal mode, and if u want to use keyboard to make fullscreen, then u keyboard events, thats a different story
i hope this helps
tc hav a gr8 time

Flex: cannot resize player back from Full Screen

The key event is not listened by my Flex app. Since it is really simple code, I cannot understand where the problem is...
init() {
stage.addEventListener(KeyboardEvent.KEY_DOWN, escHandler);
}
private function escHandler(event:KeyboardEvent):void {
debugF.text = "ESC pressed";
}
thanks
I'm not sure I fully understand your question, but a lot of the user interaction events (including keyboard) are disabled when Flash is in fullscreen mode. Escape is automatically handled by Flash to exit out of fullscreen. I don't believe it will be passed to your listeners.

AS3 Project - Mouse Move Listener Reacting Outside of Application

I'm getting an unusual behavior that I can't seem to get to the bottom of. When I run this, if I move in the swf area it traces normally on mouse move. To be expected.
But it's tracing for the move event when I click anywhere on screen. If I click and drag, it traces as if I were moving in the swf area of the browser.
Here's the code. I've simplified to it's barebones. Just put this in in an empty AS3 project in Flex called "Engine" - sans quotes obviously.
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
[SWF(width='640', height='360', backgroundColor='#888888', frameRate='31')]
public class Engine extends Sprite
{
public function Engine()
{
// Add the mouse handlers
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
}
public function mouseMoveHandler(evt:MouseEvent):void
{
trace("move");
}
}
}
As a workaround I've add the MOUSE_MOVE one MOUSE_OVER and remove it on MOUSE_OUT. But the behavior still seems quite unusual and I'd be interest in understanding why it's happening.
Can anyone tell me how I can keep the events constrained to the actual stage of the application?
As already mentioned, you can't stop these events from firing. They are triggered until you release the mouse.
What you can do is compare the coordinates of the MouseEvent with the bounds of the stage and ignore those outside.
public function mouseMoveHandler(evt:MouseEvent):void
{
if (evt.stageX >= 0 && evt.stageX <= stage.stageWidth &&
evt.stageY >= 0 && evt.stageY <= stage.stageHeight)
{
trace("move");
}
}
If you click inside your flash movie and drag the mouse outside of it, MOUSE_MOVE event will continue to trigger until you release your mouse. MOUSE_LEAVE will trigger only when you release the mouse outside the player. This is how Flash Player works.
Maybe I'm wrong but I don't think you can change this behaviour.
Ok, This is a known bug that only happens with Mac.
There is a fix here :
http://www.visible-form.com/blog/transformmanager-fix-for-mac-firefox/

Resources