PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Scrolling stars

Hi im a newbie and need help im tring to get a scrolling star field but all i manage to do is get a screen full of pixles :oops: any ideas as how i should proceed?

Thanks

Rex
Hi Raster Rex,

First of all, don't forget to clean the screen every frame, removing all the previously drawn stars.

I'm not sure if you want to do a 3d or 2d starfield.
I'd suggest starting with a 2d star field first! :)


what you should do is basically make an array of 'stars', and initialize these withrandom values. then every frame update the entire array and draw them to the screen.

so your 'Start Struct' should basically look like this (for a side star scroller):

Code:

#define NROFSTARS (256)
struct Star
{
int x,
int y,
int spdx
};

Star StarTab[NROFSTARS];

with an initialize function like this:
Code:

void InitStars(void)
{
int i;
for (i=0; i<NROFSTARS; i++)
{
StarTab[i].x = rand()&255;
StarTab[i].y = rand()%320;
StarTab[i].spdx = (rand()&7)+1;
}
};


then every frame you should have a function which resembles this:

Code:

void DrawStars(void)
{
int i;
for (i=0; i<NROFSTARS; i++)
{
StarTab[i].x += StarTab[i].spdx;
StarTab[i].x &= 255;

if(StarTab[i].x<240) //clipping
{
DrawPixel(x,y);
}
}
}


hope this helps

R

p.s. further improvements might be using fixed point for the x position and its speed... resulting in more speeds then these 8.
Thanx very much for the info :D but im also having trouble understanding the EasyCE buffers command can you help me in this area please? i just get a blank screen now and no stars :?

Regards

Rex