How to get Display Size [HAXE FLIXEL] - haxe

I was just wondering how I could get the size of the display in HaxeFlixel (usually 1920,1080/1280,720). This is not to be confused with the window size.

You could use https://api.openfl.org/openfl/system/Capabilities.html#screenResolutionX / https://api.openfl.org/openfl/system/Capabilities.html#screenResolutionY to obtain resolution.

You should be able to see this in your Main.hx file. It should look something like this:
class Main extends Sprite {
public function new() {
super();
addChild(new FlxGame(1920, 1080, GameState, true));
}
}

Related

MRTK thumbstick input

I’ve been trying to figure how to access thumb-stick input from the controller in MRTK.
I’m new to coding and the documentation was just a bit too confusing for me to figure out.
I figured out a pointer click through the onPointerClick methods however I just can’t figure the other inputs.
I’m sure it’s simple, I just need to see an example. Any help is appreciated.
Thanks!
You can try a script like this:
public class ThumbstickMover : InputSystemGlobalListener, IMixedRealityInputHandler<Vector2>
{
public MixedRealityInputAction moveAction;
public float speed = 1.0f;
public void OnInputChanged(InputEventData<Vector2> eventData)
{
if (eventData.MixedRealityInputAction == moveAction)
{
Vector3 localDelta = speed * (Vector3)eventData.InputData;
transform.position = transform.position + transform.rotation * localDelta;
}
}
}
For that to work you'll need to set as moveAction an input action that is mapped to one of the thumbsticks. Let me know if you have trouble with that.

Unity - Detecting keyboard input

I'm fairly new to Unity and have been looking up tons of tutorials/guides online. My issue is that for some reason when I use the below code it doesn't detect if the keyboard is clicked. Maybe I am doing keyboard detection wrong. Here is my code:
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
Vector3 player = GameObject.FindGameObjectWithTag("Player").transform.position;
void Update () {
if (Input.GetKeyDown(KeyCode.D)) {
player.x += 0.01F;
}
}
}
Your input code is correct but still couple of things that are not at right place. First you wrote an initializer (static method) outside any function. Remember when you do it in Unity3d C# then it will always give you a warning/error.
If you are using C# don't use this function in the constructor or field initializers, Instead move initialization to the Awake or Start function.
So first move that sort of lines in either functions.
Second thing you are getting Vector3 and trying to use it as reference, that means you got a position reference in form of Vector3 and every change made in that variable will be effective, that is not the case, it won't.
But yes you can do it by getting Transform or GameObject, they will do it for you.
Third and last thing, you are trying to alter Vector3 component ("x" in your case ) directly, that'd also not acceptable for Unity. What you can do is either assign position with new Vector3 or create a separate Vector3 variable, alter that, then assign it to position.
So after all of these addresses your code should be look like this,
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour
{
Transform player;
// Use this for initialization
void Start ()
{
player = GameObject.FindGameObjectWithTag ("Player").transform;
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown (KeyCode.D)) {
// Remove one of these two implementations of changing position
// Either
Vector3 newPosition = player.position;
newPosition.x += 0.01f;
player.position = newPosition;
//Or
player.position = new Vector3 (player.position.x + 0.01f, player.position.y, player.position.z);
}
}
}

NullReferenceException when trying to get text from inputfield

I am new to unity and want to get a value from a input text field. I found this question
Get text from Input field in Unity3D with C#, but when I execute it the same error always appear: NullReferenceExcpetion : Object reference not set to an instance of an object.
It seems like a stupid mistake and I tried everything but can't seem to fix it.
My code:
void Start () {
var input = gameObject.GetComponent<InputField>();
input.onEndEdit.AddListener(SubmitName);
}
private void SubmitName(string arg0)
{
Debug.Log(arg0);
}
I tried putting InputField input; before the start function and erasing var but still no luck.
If anyone can help me with this problem it would be much appreciated.
Pictures of where my scripts are attached at the moment.
Your code is nearly correct, if you have a look at the documentation, you have to call your method with function before calling the method name. It looks to me like you are mixing c# and JS, here is the `js function:
public class Example {
public var mainInputField;
public function Start() {
// Adds a listener to the main input field
// and invokes a method when the value changes.
mainInputField.onValueChange.AddListener(function() {
ValueChangeCheck();
});
}
// Invoked when the value of the text field changes.
public function ValueChangeCheck() {
Debug.Log("Value Changed");
}
}
the c# solution:
public class MenuController : MonoBehaviour {
[SerializeField]
InputField inputText;
// Use this for initialization
void Start () {
inputText.onValueChange.AddListener(delegate {
DebugInput();
});
}
private void DebugInput(){
Debug.Log ("Input: " + inputText);
}
}
My Hierarchie looks like this:
I created a Canvas and inserted an InputField inside it. The script with the code inside is attached to the Canvas and the InputField connected to the [SerializeField] inside the script in the Canvas.
I would recommend you to make your InputField a class variable, so you can access it easier later. Furthermore you should just create a [SerializeField] for your InputField so you can drag it to your script. This might avoid some mistakes too.
Change InputField(TMP) to InputField(Legacy)

mouse coordinates variable's scope

I am asking for an advice on how should I declare mouse coordinates that resides inside a namespace and use it frequently by all classes belonging to that namespace.
I use to declared its variables as static within a struct and while dealing it with other classes, puts me in some random error linking between them.
I like its scope to be globally declared but don't know how it should be done in proper way.
some of my implementations are like these:
struct Mouse {
static double X,Y,Z;
static int state,button;
}
//use it like
class Foo {
void func() {
Mouse::X = ?;
Mouse::Y = ?;
}
}
class Mouse {
double X,Y,Z;
int state, button;
}
//
class Foo {
static Mouse mouse;
//or
Mouse* mouse;
}
For me the example of class and using dynamic Memory allocation is the best

Compact Framework 3.5 Update Usercontrol With Main Form Variable Data

This seems like it should be simple, however, I cannot find an example through searching...
How do I update a label on a usercontrol using variables from its parent form?
I am building a compact framework 3.5 application.
Thanks for any and all assistance!!!
You can create a public property on the user control, and you update your label from there, for example:
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public string LabelText
{
get
{
return label1.Text;
}
set
{
label1.Text = value;
}
}
}
You can also return the label itself, although some people may say that would break encapsulation on your design.

Resources