stupid score question
by David Horn · in Torque X 2D · 06/15/2009 (1:21 pm) · 6 replies
Ok, this is probably dumb, but I'm not sure how to update the score on a game.
I have a GUI setup..
Then Game.as where I load everything, I have
HUD playGui = new HUD();
GUICanvas.Instance.SetContentControl(playGui);
How do I access that _score.Text attribute to update the score from another .cs file?
I have a GUI setup..
_score = new GUIText(); _score.Style = textStyle; _score.Text = "Score: 0"; _score.Position = new Vector2(700f, 30); _score.Visible = true; _score.Folder = this;
Then Game.as where I load everything, I have
HUD playGui = new HUD();
GUICanvas.Instance.SetContentControl(playGui);
How do I access that _score.Text attribute to update the score from another .cs file?
About the author
#2
06/15/2009 (2:46 pm)
If you want to access the score at any time, I'd recommend adding a property to the class HUD that allows read/write access to _score.Text such as:public string ScoreText
{
get { return _score.Text; }
set { _score.Text = value; }
}
#3
Works well. Thanks.
Now if only there was a way to create online leaderboards. I assume Microsoft still does not allow this, corect?
06/18/2009 (6:53 am)
Got it. I decided to go with Gavin's override solution.Works well. Thanks.
Now if only there was a way to create online leaderboards. I assume Microsoft still does not allow this, corect?
#4
Sure i've seen something over at creators.xna.com about online scoreboards and the possibility of it working.
06/18/2009 (8:46 am)
I think what Scott ment was instead of using Game.Instance.CurrentPlayer.Score to get your score you could a property to the main game.cs file:public string ScoreText
{
get { return _score; }
set { _score.Text ; }
}or even justpublic string ScoreText
{get;set;}would workSure i've seen something over at creators.xna.com about online scoreboards and the possibility of it working.
#5
There is one person who created one that pulls in scores from other people who are playing the game at the exact same time, but that's it.
Kinda dissapointing.
06/18/2009 (9:22 am)
I don't think XNA creators have access to post leaderboards. Much in the same way that we can't create achievements.There is one person who created one that pulls in scores from other people who are playing the game at the exact same time, but that's it.
Kinda dissapointing.
#6
I can't find anywhere what that does. I looked through the source and of course the docs.
08/12/2009 (6:08 am)
Hey Gavin, why do you have the line text0.Size = new Vector2(500, 60);I can't find anywhere what that does. I looked through the source and of course the docs.
Torque 3D Owner Gavin Beard
Byte Logic
using System; using System.Collections.Generic; using System.Linq; using System.Text; using GarageGames.Torque.Core; using GarageGames.Torque.SceneGraph; using GarageGames.Torque.Sim; using GarageGames.Torque.GameUtil; using GarageGames.Torque.T2D; using GarageGames.Torque.Platform; using GarageGames.Torque.GUI; using GarageGames.Torque.MathUtil; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.GamerServices; namespace StarterGame2D { class guiGame : GUISceneview { GUIText text0 = new GUIText(); GUITextStyle ts1 = new GUITextStyle(); public guiGame() { Style = new GUIStyle(); Position = new Vector2(0, 0); Size = new Vector2(1280, 720); ts1.FontType = @"data/images/font/agent28"; ts1.TextColor[0] = Color.Red; ts1.IsOpaque = false; ts1.SizeToText = false; text0.Text = "Score: "; text0.Position = new Vector2(130,75); text0.Size = new Vector2(500, 60); text0.Style = ts1; text0.Folder = this; } public override void OnRender(Vector2 offset, RectangleF updateRect) { text0.Text = "Score: " + Game.Instance.CurrentPlayer.Score.ToString(); base.OnRender(offset, updateRect); } } }