Game Development Community

expanding asteroids demo

by Shane · in Torque Game Builder · 07/27/2009 (2:01 pm) · 11 replies

Hello, I wanted to work on another little game idea and used the asteroids game demo to expand on to do this. I got scrolling around a tilemap working, but I have a very stupid question. The score and player count that was shown in the asteroids demo now is just static on the screen and thusly scrolled off the screen. I assume I have to mount the score and player icon objects to the player and take off the rotation, but how to mount the scores and that to the player at the top left of the screen? I see mount force but that doesn't seem like its what I want to use. Secondly the "Game over" that comes up is static too, and so I guess I have to put the Game oVer at the players last known coordinates when the player dies.... did the demo pretty quick (behaviors are new to the TGB version I am using so I am getting a handle on those as well). Am I even in the ball park with the mounting? Thanks for any help here!



#1
07/27/2009 (2:54 pm)
Well, you want the game over image to display in the center of the screen, no matter where the camera is correct.

Try something along these lines:
imageName.setPosition(%scenegraph.cameraPosition);

`patrick
#2
07/27/2009 (3:10 pm)
Thanks for the response, I am using the cameraMount behavior located on this site...it is mounted to my main player ship I think... I am also using the gameText behavior that comes from the asteroids demo. So I am not sure what object I need to access to get the cameraPosition from.
#3
07/27/2009 (3:23 pm)
The code I provided you should work, perhaps with some slight modifications. Essentially, replace the 'imageName' with the name you gave your "Game over" - I assumed this was an image or animated image...

For the other text, you can simply use the name you gave that and apply an offset to stick it in the corner. Something like:
scoreName.setPositionX(%scenegraph.cameraPositionX - 480);  
scoreName.setPositionY(%scenegraph.cameraPositionY + 320);
#4
07/27/2009 (3:24 pm)
awesome I got the game Over text to stick thre by using:

%pos = sceneWindow2D.getCurrentCameraPosition();
then:
So my new function is:

function GameTextBehavior::gameOverText(%this)
{
%this.owner.text = "Game Over";
%this.owner.setBlendAlpha(0);


%pos = sceneWindow2D.getCurrentCameraPosition();
%this.owner.setPosition(%pos);
%this.fadeInText(1, %this.fadeLength, 1);
}

works like a charm, will do the rest with the other info. Thanks a lot! :)
#5
07/27/2009 (6:20 pm)
My pleasure, it seemed like you only needed a nudge... :)
#6
07/27/2009 (6:31 pm)
Well now I am learning how Torque passes data around. Back in the day there was data blocks I think it was called? Now they seemed to of made way for behaviors. That asteroids demo on the TDN, uses all behaviors. I figured out how to make the game over and highscore list appear center string using above. The display score behavior though seems to have no "heartbeat" function to allow me to add the above calculation to set the position there for no matter where the camera is.

Its odd, on a standard class I can make it where an onUpdate function is called, behaviors don't seem to do this that I can tell...or I am doing it wrong.

So my display score behavior updates the score from other behaviors , how to make the display behavior have a heartbeat where i can get at the sceneWindow2D current camera pos.
#7
07/28/2009 (7:06 am)
Hehe, you're not kidding about 'back in the day'... member since '01. Nice!

Datablocks still have their place in torque script but I guess are not as widely used in TGB as TGE(A). Again, I'm not familiar with those behaviors but take a look at this link for a quick and dirty how to get a callback working on object created from behaviors.
www.garagegames.com/community/forums/viewthread/88805

I think that's what you mean by heartbeat but I could be off the mark.

`Patrick
#8
07/28/2009 (7:20 am)
awesome thanks! I went to that link and I had tried it earlier with it not working, what I was missing was the .owner part, I guess behaviors really need that. I had tried earlier just %this.enableUpdateCallback();
not the %this.owner.enableUpdateCallback();

I am still getting a handle on how behaviors work. Powerful but confusing sometimes... thanks though the score now sticks on the screen! Though the score displays really jittery which I am guessing is a side effect of how the CameraFollow.cs behavior updates the camera..
#9
07/28/2009 (8:21 am)
To be honest, I'm not much on behaviors. They seem like a great way to use other people's code but my background tends more towards a traditional OOP format when writing my own code.

Yeah, the 'owner' of the behavior is the object it is attached to, so if you want to enable a callback on that object, you need to include 'owner' as you described, otherwise you are enabling a callback on the behavior itself.
#10
07/29/2009 (1:11 pm)
Do you have an email address? I have a few questions and that I'd like to send to ya...
#11
07/29/2009 (1:28 pm)
sure do. patrickadesso - a t - gmail dot com