Starfield
by Eddie Saunders · in Torque Game Builder · 03/05/2005 (5:10 am) · 5 replies
Morning,
One of the most common 2D effects is the good old parallax stafield (this was huge on the C64). Anyway, would it be possible to add a plot/unplot pixel command?
I'm sure I can do the same effect with sprites (and I'm sure this is how GG would do it anyway) within t2D, just thinking easy here. :)
Overall I like T2D, I think I'm gonna have a blast with it. :)
Eddie.
One of the most common 2D effects is the good old parallax stafield (this was huge on the C64). Anyway, would it be possible to add a plot/unplot pixel command?
I'm sure I can do the same effect with sprites (and I'm sure this is how GG would do it anyway) within t2D, just thinking easy here. :)
Overall I like T2D, I think I'm gonna have a blast with it. :)
Eddie.
#2
I think I've got a rough scribbled concept of doing this with sprites (easier than I
thought, so who knows... :D ), which I'll post once I get coded up. 2D shoot 'em ups just aren't the same without the stars. (*loves a good shoot 'em up*) :)
Thanks for your input.
Eddie.
03/05/2005 (8:45 am)
You're probably correct, the last thing we need is for Melv to be going crazy trying to implement such a thing, and I know I don't want to go crazy implementing such a thing.I think I've got a rough scribbled concept of doing this with sprites (easier than I
thought, so who knows... :D ), which I'll post once I get coded up. 2D shoot 'em ups just aren't the same without the stars. (*loves a good shoot 'em up*) :)
Thanks for your input.
Eddie.
#3
Would I just define multiple fxScroller2D? Can you also use a tile map at the same time?
Thanks!
03/05/2005 (9:46 am)
Can you give an example of how you would code the layerd PNG approach. I have created a PNG starfield with the stars masked out. (can you use transparency?) I also have a backround with just black.Would I just define multiple fxScroller2D? Can you also use a tile map at the same time?
Thanks!
#4
However, I'd recommend the sprite approach. Just create some star PNGs (or just plain white squares if you want the old-school look), define imagemaps for the stars, as per usual in T2D. Then set-up a loop and define a bunch of sprites using the star imagemaps. This way you can even set individual scroll speeds (or scalars, if you want them to change their scroll rate based on player movement) for each star, so it looks like they're truly independent in space. Or, if you want the classic look exactly, you could just assign the stars to one of three pre-set scroll speeds / scalars.
There are other ways too, but this'd work! :)
03/05/2005 (11:20 am)
Brian, yes you can use transparency in PNGs, that's their main draw. You could use tiles or scrollers (or both, yeah).However, I'd recommend the sprite approach. Just create some star PNGs (or just plain white squares if you want the old-school look), define imagemaps for the stars, as per usual in T2D. Then set-up a loop and define a bunch of sprites using the star imagemaps. This way you can even set individual scroll speeds (or scalars, if you want them to change their scroll rate based on player movement) for each star, so it looks like they're truly independent in space. Or, if you want the classic look exactly, you could just assign the stars to one of three pre-set scroll speeds / scalars.
There are other ways too, but this'd work! :)
#5
Setup the datablock to load the graphic
// This should be a star, but I used a missle as a placeholder.
datablock fxImageMapDatablock2D(starImageMap)
{
mode=full;
textureName="~/client/images/playerMissile";
};
And now the loop to display these....
function CreateStarfield()
{
//setup 30 stars and position them at random spots across the screen
//loop to place 30 stars on screen
for(%a=0; %a < 30; %a++)
{
// we now need to set a random location for X & Y
// XPos/YPos will need tweaking to use the entire screen
$starXPos = getRandom (0,20);
$starYPos = getRandom (0,20);
%position = ( $starXPos SPC $starYPos );
%star=new fxStaticSprite2D() { scenegraph = t2dsceneGraph; };
%star.setposition (%position);
%star.setSize ("2 2");
%star.setImageMap(starImageMap);
echo ($starXPos@" "@$starYPos@" "@%a@" "@%position);
}
}
03/06/2005 (6:16 am)
Phew! I just started coding up my 2D starfield effect with sprites, and boy what a job that was to get the 30 sprites displayed on screen... This caused me major headaches, so I decided to post in this section in case someone else is giving it a go and getting issues as well. My main problem was getting the random positions into xxxx.setposition(), after a few hours, I cheated and looked at the source for the scroller game included with T2D, 20 seconds later I was fixed... Anyway, here's my code incase anyone is interested in getting those on screen (they don't move yet...). Setup the datablock to load the graphic
// This should be a star, but I used a missle as a placeholder.
datablock fxImageMapDatablock2D(starImageMap)
{
mode=full;
textureName="~/client/images/playerMissile";
};
And now the loop to display these....
function CreateStarfield()
{
//setup 30 stars and position them at random spots across the screen
//loop to place 30 stars on screen
for(%a=0; %a < 30; %a++)
{
// we now need to set a random location for X & Y
// XPos/YPos will need tweaking to use the entire screen
$starXPos = getRandom (0,20);
$starYPos = getRandom (0,20);
%position = ( $starXPos SPC $starYPos );
%star=new fxStaticSprite2D() { scenegraph = t2dsceneGraph; };
%star.setposition (%position);
%star.setSize ("2 2");
%star.setImageMap(starImageMap);
echo ($starXPos@" "@$starYPos@" "@%a@" "@%position);
}
}
Torque Owner Jason Cahill
Default Studio Name
No coding: Draw several layers of PNGs of stars and scroll them at differing speeds, based on parallax distance.
Coding: Create a series of bitmaps in C++ that you want to use as the texture(s) above, and render into those. That's how you'd get the ability to "setpixel."