2 Questions - Please Help
by Do Not Delete · in Torque X 2D · 09/05/2007 (7:46 pm) · 42 replies
1. What is the best way to pause a game using Torque X?
2. I've been tinkering around with the FireProjectileComponenet from the Blaster Tutorial and decided to add the code to the Player Controller.cs file. There is one problem though, it can't find SceneObject. The SceneObject in our case is the Dragon. What would the equivilent of SceneObject be in our case?
Code:
Thanks!
2. I've been tinkering around with the FireProjectileComponenet from the Blaster Tutorial and decided to add the code to the Player Controller.cs file. There is one problem though, it can't find SceneObject. The SceneObject in our case is the Dragon. What would the equivilent of SceneObject be in our case?
Code:
// Set the position based on the position of the object that's shooting.
projectileObj.Position = SceneObject.Position;
projectileObj.Layer = SceneObject.Layer + 1;Can anyone help?Thanks!
About the author
#22
If you wanted the firing functionality to be a little more expandable, you could move the _Fire method onto the ActorController class and have it do a similar input forwarding (something like "foreach(ActorComponent actor in _movers) actor.Fire();"). Then you could have a Fire method on ActorComponent that spawned a projectile based on a template stored on the Actor (essentially the same code that is currently in your _Fire method on PlayerController, but in this case it would be using a template specified by a property to clone the projectile and it would be using that actor's owner to get the position). Assuming that all worked, you could have different types of actors shoot different projectiles and you could set it all up from the editor with templates.
09/10/2007 (5:31 am)
Well done, Dro.If you wanted the firing functionality to be a little more expandable, you could move the _Fire method onto the ActorController class and have it do a similar input forwarding (something like "foreach(ActorComponent actor in _movers) actor.Fire();"). Then you could have a Fire method on ActorComponent that spawned a projectile based on a template stored on the Actor (essentially the same code that is currently in your _Fire method on PlayerController, but in this case it would be using a template specified by a property to clone the projectile and it would be using that actor's owner to get the position). Assuming that all worked, you could have different types of actors shoot different projectiles and you could set it all up from the editor with templates.
#23
I'm still have this problem though,
If I pause the game, quit, select single player from the main menu, go to the single player main menu, select new game I can't move the dragon with the controller, but I can shoot using the controller (only X button, no jumping with controller either). The keyboard works fine though.
Do you know how to fix it?
09/10/2007 (7:01 am)
I'll will definitly try that. I'm still have this problem though,
If I pause the game, quit, select single player from the main menu, go to the single player main menu, select new game I can't move the dragon with the controller, but I can shoot using the controller (only X button, no jumping with controller either). The keyboard works fine though.
Do you know how to fix it?
#24
Thomas when you have time, can you help me fix the pause game issue?
Also, how could I tell if the actor is facing left or right?
Thanks,
Dro
09/10/2007 (4:45 pm)
Just wanted to let you know that your way works much better! Thanks! There is a little more tweaking to make it perfect but I'll get to that later. Thomas when you have time, can you help me fix the pause game issue?
Also, how could I tell if the actor is facing left or right?
Thanks,
Dro
#25
09/11/2007 (7:46 pm)
I don't know. That sounds weird. How are you binding the player's input?
#26
Also, how can I tell if the actor is dead and what way is the actor facing?
09/11/2007 (8:15 pm)
To show the pause menu? I do it directly in the PlayerController.cs file (I think that whats its called).Also, how can I tell if the actor is dead and what way is the actor facing?
#27
1. How can I know if the actor died?
2. How can I know which way the actor is facing?
3. How can I fix the pause menu issue?
09/19/2007 (7:20 am)
Bump. 1. How can I know if the actor died?
2. How can I know which way the actor is facing?
3. How can I fix the pause menu issue?
#28
2. Like so:
3. I have no idea how you've implemented your menu's level loading, so it's literally impossible to tell you how to fix the problem without more information about how the menu works.
09/19/2007 (6:04 pm)
1. There's an Alive public property on ActorComponent.2. Like so:
// this would be on an ActorComponent somewhere // if facingRight is falce, the actor is facing left bool facingRight = _actor.FlipX.
3. I have no idea how you've implemented your menu's level loading, so it's literally impossible to tell you how to fix the problem without more information about how the menu works.
#29
For number 3 what else would you need to know. Would it be good if I have a class and I call all the menu stuff from that class? Like a sound manager except for menus?
How would I create a simple power up? For example lets say the player collides with this power up and it turns invisible (the power up not the player)?
09/19/2007 (8:49 pm)
I fixed problem number 1 and 2 with ease thanks to your help ;).For number 3 what else would you need to know. Would it be good if I have a class and I call all the menu stuff from that class? Like a sound manager except for menus?
How would I create a simple power up? For example lets say the player collides with this power up and it turns invisible (the power up not the player)?
#30
As for the menu, I would need to know exactly what it's doing in broad terms. Basically, what's the high level order that things are happening? What does the menu actually do when you "quit" (unload the level, or just delete objects)? Is anything flagged as persistent in the original level? Are you loading the same level before you unload the first one? Are the components (such as the drill head kill component) being successfully added to the drills when the second level is loaded? etc.
Any info about anything special you're doing to handle level load and unload might also help.
09/20/2007 (5:29 pm)
Derive from CollectibleComponent. It does all that for you (checks for actors, etc.) and you get a _confirmPickup callback on your subclass that you can override and return true (allow the actor to pick it up and then delete the pickup) or false (don't allow the actor to pick it up).As for the menu, I would need to know exactly what it's doing in broad terms. Basically, what's the high level order that things are happening? What does the menu actually do when you "quit" (unload the level, or just delete objects)? Is anything flagged as persistent in the original level? Are you loading the same level before you unload the first one? Are the components (such as the drill head kill component) being successfully added to the drills when the second level is loaded? etc.
Any info about anything special you're doing to handle level load and unload might also help.
#31
This is all done through a Level class that I wrote. Here is the code for that:
And for the power up I added the collectable component to it, but now how would the game know if it is collected or not?
09/20/2007 (7:36 pm)
I use the SceneLoader to unload the sample_level.txscene file. Then I use the SceneLoader to load the same level when the user clicks new game.This is all done through a Level class that I wrote. Here is the code for that:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using GarageGames.Torque.GUI;
using PlatformerStarter.GUI;
using GarageGames.Torque.PlatformerFramework;
using GarageGames.Torque.Sim;
using GarageGames.Torque.Platform;
using GarageGames.Torque.Core;
using GarageGames.Torque.T2D;
using GarageGames.Torque.XNA;
namespace PlatformerStarter
{
public class Level
{
/// <summary>
/// Start a new game
/// </summary>
public static void NewGame()
{
Game.Instance.SceneLoader.Load(@"data\levels\sample_level.txscene");
}
/// <summary>
/// Unload the sceneloader to quit the game
/// </summary>
public static void QuitGame()
{
Game.Instance.SceneLoader.Unload(@"data\levels\sample_level.txscene");
}
}
}And for the power up I added the collectable component to it, but now how would the game know if it is collected or not?
#32
For the collectible, you want to make a subclass and override _confirmPickup, like I mentioned above. If you're going to return true you can also just notify the actor what happened, change it's health, make it invisible, swap out a material, etc. You have a reference to the actor in that method.
09/21/2007 (2:55 pm)
So there are no persistent objects and you are unloading the scene before you load the next one, correct?For the collectible, you want to make a subclass and override _confirmPickup, like I mentioned above. If you're going to return true you can also just notify the actor what happened, change it's health, make it invisible, swap out a material, etc. You have a reference to the actor in that method.
#33
What do you mean by that exactly?
Edit: How do I count 30 seconds in real life in Torque X? Like if 30 seconds passes something happens.
09/23/2007 (7:46 pm)
Quote:So there are no persistent objects and you are unloading the scene before you load the next one, correct?
What do you mean by that exactly?
Edit: How do I count 30 seconds in real life in Torque X? Like if 30 seconds passes something happens.
#34
10/02/2007 (7:15 am)
Any news on the timer example you were gonna show me?
#35
[elevator music]
Ok, here it is. This should work on a component class or any TorqueObject class that can register for tick callbacks:
EDIT: Clarity.
10/02/2007 (4:07 pm)
Oh, dang.. I keep forgetting to do that. One sec.. writing.[elevator music]
Ok, here it is. This should work on a component class or any TorqueObject class that can register for tick callbacks:
public void ActivateTimer(float totalTimeMS)
{
_activationTime = TorqueEngineComponent.Instance.TorqueTime;
_delay = totalTimeMS;
_isActive = true;
}
public void ProcessTick(Move move, float elapsed)
{
if (_isActive)
{
float currTime = TorqueEngineComponent.Instance.TorqueTime;
if (currTime - _activationTime >= _delay)
{
// _delay milliseconds have passed since ActivateTimer was called!
// <-- timer logic goes here! <--
Console.WriteLine("MY TIMER WORKS! \n{0} SECONDS HAVE PASSED!", _delay / 1000.0f);
// now deactivate the timer
_isActive = false;
}
}
}
private bool _isActive;
private float _activationTime;
private float _delay;EDIT: Clarity.
#36
10/02/2007 (4:11 pm)
Also, please start new topics for new questions if they're unrelated to the original post. It's more likely that someone else will find a previous answer if it's got it's own correctly titled thread. :)
#37
I tried your code by nothing happens. Here your code + my code
10/02/2007 (6:31 pm)
Sorry for not creating a new thread.I tried your code by nothing happens. Here your code + my code
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using GarageGames.Torque.Core;
using GarageGames.Torque.T2D;
using GarageGames.Torque.PlatformerFramework;
using PlatformerStarter;
using GarageGames.Torque.XNA;
using GarageGames.Torque.Sim;
namespace Utopia
{
/// <summary>
/// Slow Motion Component - Slows down the game for 30 seconds.
/// </summary>
[TorqueXmlSchemaType]
class SlowMotion : CollectibleComponent
{
//======================================================
#region Private, protected, internal methods
protected override bool _confirmPickup(T2DSceneObject ourObject, T2DSceneObject theirObject, ActorComponent actor)
{
// try to add this pepper to the Dragon's inventory
if (actor is PlayerActorComponent)
{
// Slow down the game for 30 seconds
TorqueEngineComponent.Instance.GameTimeScale = 0.5f;
ActivateTimer(5000);
// true = yes, i was picked up. delete me!
return true;
}
// false = no, this guy didn't pick me up.
return false;
}
public void ActivateTimer(float totalTimeMS)
{
_activationTime = TorqueEngineComponent.Instance.TorqueTime;
_delay = totalTimeMS;
_isActive = true;
}
public void ProcessTick(Move move, float elapsed)
{
if (_isActive)
{
float currTime = TorqueEngineComponent.Instance.TorqueTime;
if (currTime - _activationTime >= _delay)
{
// _delay milliseconds have passed since ActivateTimer was called!
// <-- timer logic goes here! <--
TorqueEngineComponent.Instance.GameTimeScale = 1.0f;
// now deactivate the timer
_isActive = false;
}
}
}
private bool _isActive;
private float _activationTime;
private float _delay;
#endregion
}
}
#38
You need to register for tick callbacks. Also, you don't want to put the timer on the collectible component because it will be deleted when it's collected and never let the timer finish. You can put the timer code on your actor or something that already gets ticked and add the code that's in process tick above to the _update method. Or you could make it a seperate component that ticks and has a delegate for the timer event to make it universal.
You can also use the scheduler for stuff like this (might be easier in this case):
10/03/2007 (3:05 pm)
Right...Quote:
This should work on a component class or any TorqueObject class that can register for tick callbacks
You need to register for tick callbacks. Also, you don't want to put the timer on the collectible component because it will be deleted when it's collected and never let the timer finish. You can put the timer code on your actor or something that already gets ticked and add the code that's in process tick above to the _update method. Or you could make it a seperate component that ticks and has a delegate for the timer event to make it universal.
You can also use the scheduler for stuff like this (might be easier in this case):
TorqueEngineComponent.Instance.RealTimeSchedule.Schedule(time, myDelegate, data);
#39
10/03/2007 (9:19 pm)
How can I know if the collectible was collected or not?
#40
10/04/2007 (2:49 pm)
If it exists, it wasn't collected. You can know *when* an actor is trying collect it: when the _confirmPickup() method is called. If you want to do something when it's collected, then put whatever logic you want just before you return true in _confirmPickup().
Torque Owner Do Not Delete
If I pause the game, quit, select single player from the main menu, go to the single player main menu, select new game I can't move the dragon with the controller, but I can shoot using the controller (only X button, no jumping with controller either). The keyboard works fine though.
Thanks!