Game Development Community

Gui, displaying active items

by GxG6(Mark-Anthony) · in Torque X 2D · 07/22/2010 (4:13 pm) · 10 replies

Hello everyone. I have a component that generates a random item that can be shot.
now thats running all fine and dandy but how do I get the selected random item to be displayed on screen and remove it when shot and then load the next into the GUI class?

Lets say I have a class that handles generating the random item using a limited switch. the switch result is chosen and then it is loaded into the fire class/component. but i'm having trouble using the chosen item to b e displayed on my gui

#1
07/22/2010 (10:13 pm)
Well, you register the object to show it and mark it for deletion to destroy it. But the GUI aren't really the right place, you should do that in the scene itself.
#2
07/24/2010 (10:30 pm)
hmm that would simplify things, i was going for a tetris type thing but when I really think about it ya can't really tell the difference anyway
#3
07/24/2010 (10:32 pm)
so what I basically have to do is make another clone of the item that came through the switch, and have it be deleted as soon as the fire but is pressed? or when the previous item has been destroyed?
#4
07/24/2010 (10:49 pm)
Well, when to destroy it is up to you, just when it has to go away.
#5
07/29/2010 (8:21 pm)
I'm stuck :/
I'm trying to get the chosen Item from 1 component to be displayed in another component, but I can't access the assigned T2dsceneobject from the said component. ugh. Maybe I'm making things more difficult than they need to be, but I've tried searching for examples of what I'm trying to do through the forums but no luck. :/

basically i already have my "object picker" set up and the end result is like:
Loadedit = _pickeditem.clone() as T2DSceneobject;
now thats working good and all and I can even load it and use it for the item code inside that same component, but the problem is when I try to put in in another component to be displayed.
last attempt i tried something like this:
if (_displyth == null)
            {
                RandomizeItComponent chngeit = Owner.Components.FindComponent<RandomizeItComponent>();
                chngeit.Activeitem();
                _displyth = chngeit.Activeitem.ds as T2DSceneObject;
            }

obviously the last line is uber wrong :/
#6
07/29/2010 (9:10 pm)
I'm very sorry but I just don't follow: what are you exactly trying to do?
#7
07/30/2010 (4:07 am)
sorry, what I'm trying to do is have on screen a box that will show the next item that will be used. there are 3 items that will be randomly chosen to be used by the player. I managed to construct a code to handle randomizing the 3 items and allowing the player to use the result of the randomization. the problem is I can't get the item to be displayed on screen before it is used :/
its similar to the hud on tetris where it shows you the next set of blocks that will appear on the screen
#8
07/30/2010 (11:47 am)
Ok then,

you took a very complex and original way to achieve that :) I'll tell you what I would do.

First off I would use a sprite sheet to contain the pieces and their animations. This will drammatically reduce the memory fragmentation. Then I would create this box just dragging the actual sprite sheet in the scene, adding a simple component which changes the image index of the texture (the MaterialRegionIndex property of the T2DStaticSprite object) according to a global variable containing the index of the next piece.

If you don't like working with sprite sheets (which is the best way) you might want to resort to changing the material texture:
(_yourStaticSprite.Material as SimpleMaterial).SetTexture(yourTexture.Instance)

I hope this will clear your way ;)
Pino


EDIT: I forgot to tell you how to get the Texture resource to use the SetTexture :) You have to prepare (or in the onRegister) the content of class wide fields like this:
yourTexture = ResourceManager.Instance.LoadTexture(@"data/images/yourTextureName");

The field is declared at class level:
Resource<Texture> yourTexture = null;

The Set Texture will use the Instance of the resource:

(_yourStaticSprite.Material as SimpleMaterial).SetTexture(yourTexture.Instance)
#9
07/30/2010 (12:01 pm)
Sorry for the long Edit above :)
#10
07/30/2010 (10:43 pm)
No Problem, I actually never thought of doing it that way. I think were i got lost is that i have everything in different components . thank you for your help