I get a ContentLoadException "File not found", when the debugger hits my LoadContent method in my DrawableGameComponent. I created a test string that outputs the Content Root Directory and it is as follows : \GameName\bin\x86\Debug\Content minus my personal folders preceding it of course.
Here is the code in the Game child class :
GraphicsDeviceManager graphics;
global_vars variables;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content"; //Folder for the Content Manager to place pipelined files as they are loaded
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
variables = new global_vars(graphics);
Character c = new Character(null, null, variables, this);
this.Components.Add(c);
base.Initialize();
}
And the DrawableGameComponent implementation :
public Character(Ability[] starting_abilities, Player owner, global_vars vars, Game game) : base(game)
{
this.variables = vars;
this.abilities = starting_abilities;
this.character_owner = owner;
this.experience = 0;
this.position = new Rectangle(variables.CHARACTER_START_POSITION_X, variables.CHARACTER_START_POSITION_Y, variables.CHARACTER_WIDTH + variables.CHARACTER_START_POSITION_X, variables.CHARACTER_HEIGHT + variables.CHARACTER_START_POSITION_Y);
}
public override void Initialize()
{
base.UpdateOrder = variables.CHARACTER_UPDATE_PRIORITY;
base.DrawOrder = variables.CHARACTER_UPDATE_PRIORITY;
base.Enabled = true; //Enables Game to call Update on this component
base.Visible = true; //Enables Game to call Draw on this component
this.move_speed = 3;
this.position.X = variables.CHARACTER_START_POSITION_X;
this.position.Y = variables.CHARACTER_START_POSITION_Y;
this.move_state = variables.CHARACTER_DEFAULT_MOVESTATE;
this.charsprite = new SpriteBatch(variables.manager.GraphicsDevice);
base.Initialize(); //Super class calls LoadContent
}
protected override void LoadContent()
{
String test = Game.Content.RootDirectory;
character_default = Game.Content.Load<Texture2D>("Character_Grey_Eyes_Center");
character_right = Game.Content.Load<Texture2D>("Character_Grey_Eyes_Right");
character_left = Game.Content.Load<Texture2D>("Character_Grey_Eyes_Left");
character_down = Game.Content.Load<Texture2D>("Character_Grey_Eyes_Down");
character_up = Game.Content.Load<Texture2D>("Character_Grey_Eyes_Up");
base.LoadContent();
}
I've checked and double checked the Folders, Filenames, etc and they all look normal. I'm absolutely stumped.
Solved it. My Character was being added to the Component list in the Games Initialize() before it's super class call to base.Initialize(). This made my game begin calling the Character's Load and Init functions. Since the Game's Init was not called, the super class Microsoft.Xna.Framework.Game Content variable was either a null pointer or not set up properly.
The solution was to add the Character to the Component list in the game's LoadContent()
Related
I am currently working on a standalone app that can handle communication from a mobile and also utilizes VLC player to output a stream.
The way I do it is that output stream object is in the main window, but I receive requests via SignalR.
The request is fairly simple - it's just a string. The problem is I have no clue on how to pass the string from a SignalR hub back to the MediaPlayer object. How do I either get a string passed to an object outside or make a mediaplayer "persist" inside the hub? For now my code concerning it looks like this:
The hub:
[HubName("CommHub")]
public class CommHub:Hub
{
VLCControl outputplayer = new VLCControl();
public void RequestConnectionsList()
{
var databasePath = "--dbpath here--";
var db = new SQLiteConnection(databasePath);
List<string> output = db.Table<VideoSources>().Select(p => p.Name).ToList(); //Gets names from the db
Clients.Client(Context.ConnectionId).CamsInfo(output); //send available connection names to client
}
public void RequestOutStream(string requestedName) //this function is called but i have no idea how to make it work
{
outputplayer.playSelected(requestedName);
}
}
VLCControl:
class VLCControl
{
public Media rtsp;
private const string VIDEO_URL = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov";
private MediaPlayer player;
public static string GetConfigurationString() //using this method in mainwindow player as well
{
string address = Properties.Settings.Default.LocalAddress;
string port = Properties.Settings.Default.LocalPort;
string result=
":sout=#duplicate" +
"{dst=display{noaudio}," +
"dst=rtp{mux=ts,dst=" + address +
",port=" + port + ",sdp=rtsp://" + address + ":" + port + "/go.sdp}";
return result;
}
public void playSelected(string inputAddress)
{
var databasePath = "D:\\Projects\\Sowa\\Sowa\\Serwer\\VideoSources.db";
var db = new SQLiteConnection(databasePath);
string input = db.Table<VideoSources>().FirstOrDefault(p => p.Name == "test").Address;
db.Close();
var rtsp = new Media(MainWindow._libvlc, input, FromType.FromLocation);
rtsp.AddOption(VLCControl.GetConfigurationString());
player.Stop();
player.Play(new Media(MainWindow._libvlc, VIDEO_URL, FromType.FromLocation));
}
}
The players are definitely working - when i create a mediaplayer in mainwindow it does indeed output as expected.
I think your question can be rephrased as "How can I call a method on my UI from a SignalR Hub"
For that, you have several options :
If you are using ASP.net core's SignalR, you can use dependency injection to inject either your window or an accessor to your window
You can get your main window with (MyWindow)Application.Current.MainWindow. What you do with it is up to you then
You can create a static class that will hold a reference to your component directly. This example assumes you have only one view at a time in your application.
public static class ViewAccessor {
public static MyView View { get; set; }
}
In your view constructor, after InitializeComponents:
ViewAccessor.View = this;
In your hub :
ViewAccessor.View.Play(...);
I am writing an App which declares some class variables in StateMachine as for example:
Label Logo=null; Image helpIcon=null;
and these are initialised in initVars()
Logo = new Label(resFile.getImage("ic_action_play.png"));
helpIcon = resFile.getImage("ic_action_help.png");
beforeMain() calls createMenu() to setup a menu dynamically.
private void createMenu(int menuNumber, Form targetForm) {
Toolbar tb = targetForm.getToolbar();
if (menuNumber == MAIN_MENU && !menuInitialised) {
tb.addComponent(BorderLayout.WEST, Logo);
menuInitialised = true;
}
tb.addCommandToRightBar("", helpIcon, (e)->getDialog(1));
etc...
This works fine.
One of the menu items shows a Dialog, "Setup" and if I set a breakpoint in beforeSetup(Form f)
all the class variables have been reset to null. The instance of StateMachine hasn't changed
and the Ctor is not called. The only way I could retain the initialisations was to make the (class) variables that are
initialised in initVars() static. Is that right or am I not doing this correctly?
initVars happens before class init code e.g.:
private int myValue = 1;
protected void initVars() {
myValue = 2;
// will print 2
System.out.println(myValue);
}
public Statemachine() {
// will print 1
System.out.println(myValue);
}
The output of this will be:
2
1
As initVars happens before the constructor and initializing a value in the class scope is the equivalent of setting it in the constructor. The solution is not to initialize the variable and only set it in the initVars().
This is one of the old GUI builder oddities which is why we are moving towards the new GUI builder.
Is it possible to change a variable in another scene in unity. I have a script right now that has the user pick 5 heroes and those 5 heroes get saved to a array, but in order for the game to run how i want it, that array will be in another scene and I'm not sure how to go about saving the five heroes data to an array in another scene. I can do it all in one scene but 2 scenes would be more efficient. Here's my code:
using UnityEngine;
using System.Collections;
public class HeroChooser : MonoBehaviour {
public static GameObject Archer;
GameObject Berserker;
GameObject Rouge;
GameObject Warrior;
GameObject Mage;
GameObject MainCamera;
public int counter = 0;
public bool archerOn = false;
public bool berserkerOn = false;
public bool rougeOn = false;
public bool mageOn = false;
public bool warriorOn = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI(){
if(archerOn == false){
if (GUI.Button (new Rect(50,0,50,50), "Archer")){
Archer = GameObject.Find("Archer");
MainCamera = GameObject.Find("Main Camera");
HeroArraySaver heroArraySaver = MainCamera.GetComponent<HeroArraySaver>();
heroArraySaver.array[counter] = Archer;
archerOn = true;
counter++;
}
}
Its saying that: Static member HeroArraySaver.array cannot be accessed with an instance reference, qualify it with a type name instead im not sure how to go about fixing it.
A simple way would be to create an empty GameObject and attach a script/MonoBehaviour to that which holds your data. To make it persist you would have to call DontDestroyOnLoad() on that GameObject. This will ensure your GameObject will hang around when moving to a different scene.
So something like:
GameObject myPersistentDataObject = new GameObject("myPersistentDataObject");
MyDataClass data_class = myPersistentDataObject.AddComponent<MyDataClass>();
//set your data to whatever you need to maintain
And in your Awake of your MyDataClass you'd do something like
void Awake()
{
DontDestroyOnLoad(transform.gameObject);
}
Then in your other scene you can simply find your GameObject again and retrieve its data from the attached component.
Assuming you have integer IDs for the heroes, simply store them in a static variable:
public class GlobalData {
public static int[] heroIds;
}
Static variables can be accessed from any scene and will persist as long as your game runs. The same technique works for strings or enums.
I want to disable the dropdown shadow on the dropdown of a ToolStripDropDownButton. If the dropdown menu contains items that have dropdowns themselves (e.g. multi-level menu) then setting the DropShadowEnabled to false on the ToolStripDropDownButton causes the top level dropdown to appear at the wrong position. See attached picture.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
toolStripDropDownButton1.DropDown.DropShadowEnabled = false;
}
}
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.toolStripDropDownButton1 = new System.Windows.Forms.ToolStripDropDownButton();
this.item1ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.subitem1ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStrip1.SuspendLayout();
this.SuspendLayout();
//
// toolStrip1
//
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripDropDownButton1});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(292, 25);
this.toolStrip1.TabIndex = 0;
this.toolStrip1.Text = "toolStrip1";
//
// toolStripDropDownButton1
//
this.toolStripDropDownButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.toolStripDropDownButton1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.item1ToolStripMenuItem});
this.toolStripDropDownButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripDropDownButton1.Image")));
this.toolStripDropDownButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
this.toolStripDropDownButton1.Name = "toolStripDropDownButton1";
this.toolStripDropDownButton1.Size = new System.Drawing.Size(29, 22);
this.toolStripDropDownButton1.Text = "toolStripDropDownButton1";
//
// item1ToolStripMenuItem
//
this.item1ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.subitem1ToolStripMenuItem});
this.item1ToolStripMenuItem.Name = "item1ToolStripMenuItem";
this.item1ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.item1ToolStripMenuItem.Text = "item1";
//
// subitem1ToolStripMenuItem
//
this.subitem1ToolStripMenuItem.Name = "subitem1ToolStripMenuItem";
this.subitem1ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.subitem1ToolStripMenuItem.Text = "subitem1";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.toolStrip1);
this.Name = "Form1";
this.Text = "Form1";
this.toolStrip1.ResumeLayout(false);
this.toolStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ToolStrip toolStrip1;
private System.Windows.Forms.ToolStripDropDownButton toolStripDropDownButton1;
private System.Windows.Forms.ToolStripMenuItem item1ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem subitem1ToolStripMenuItem;
}
This is very typical lossage in the ToolStripItem classes. Clearly it is a bug, it probably got introduced when they applied a hack to work around a Windows problem. You can still see the internal bug number in the Reference Source:
public bool DropShadowEnabled {
get {
// VSWhidbey 338272 - DropShadows are only supported on TopMost windows
// due to the flakeyness of the way it's implemented in the OS. (Non toplevel
// windows can have parts of the shadow disappear because another window can get
// sandwiched between the SysShadow window and the dropdown.)
return dropShadowEnabled && TopMost && DisplayInformation.IsDropShadowEnabled;
}
set { // etc... }
}
But without a corresponding fix in the setter and the renderer.
The flakeyness they mentioned actually got fixed in Vista, you are still running on XP so you can't see it. Drop shadows are done differently on the Aero desktop and it is a system setting whether or not they are enabled. So using the property is entirely ineffective on Aero.
These ToolStripItem class bugs didn't get fixed after the .NET 2.0 release, about the entire Winforms team moved over to the WPF group. And they are certainly not getting fixed now, no point filing a bug at connect.microsoft.com although you are free to do so.
With the added wrinkle that the property just cannot have an effect anymore on later versions of Windows since it is now a system setting, the only logical thing to do here is to throw in the towel. Don't change the property.
I have a Setting.cs file containing the info
[Serializable]
public class Setting
{
public Setting() {}
public String defaultAlertTone = Path.GetDirectoryName(Application.ExecutablePath) + "\\Sounds\\applause-2.wav";
}
and my settingsForm retrieving the info through this code
Setting settingObject;
public SoundPlayer player;
public settingsForm(backgroundForm backgroundFormObject)
{
InitializeComponent();
this.backgroundFormObject = backgroundFormObject;
settingObject = backgroundFormObject.getSetting();
}
private void InitializeSound()
{
// Create an instance of the SoundPlayer class.
player = new SoundPlayer();
player.SoundLocation = settingObject.defaultAlertTone;
// Listen for the LoadCompleted event.
player.LoadCompleted += new AsyncCompletedEventHandler(player_LoadCompleted);
// Listen for the SoundLocationChanged event.
player.SoundLocationChanged += new EventHandler(player_LocationChanged);
}
Why is it that every time I run the app, there would be a null reference exception on the
player.SoundLocation = settingObject.defaultAlertTone;
the backgroundFormObject.getSetting(); is just a method to retrieve the setting object. the code for it are as follows
Setting settingObj = new Setting();
public Setting getSetting()
{
return settingObj;
}
The reasons could be
InitializeSound() is somehow running before settingsForm (not likely, but this would make the settingObject not initialized and refer to null).
If this is the complete code for Setting class, i don't see how calling new Setting() anywhere would make a difference. So use Setting settingObject = new Setting(); when you first define this property in the settingsForm class.
It is not the settingObject which is null.