Register
Site Login
Site Search
Forums
Advertisement
Welcome to PocketMatrix. PocketMatrix is dedicated to providing the best online community for mobile device developers and enthusiests. What's new?

Scrolling stars


Scrolling stars

Postby Raster Rex » Dec 9, 2002 @ 3:46pm

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
Raster Rex
 


Postby Rhino123 » Dec 9, 2002 @ 4:20pm

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: Select all









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

Star StarTab[NROFSTARS];
9 lines; 5 keywds; 1 nums; 10 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  

with an initialize function like this:
Code: Select all









10 
void InitStars(void)
{
    int i;
    for (i=0; i<NROFSTARS; i++)
    {
        StarTab[i].= rand()&255;
        StarTab[i].= rand()%320;
        StarTab[i].spdx = (rand()&7)+1;
    }
};
10 lines; 4 keywds; 5 nums; 43 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  


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

Code: Select all









10 
11 
12 
13 
14 
void DrawStars(void)
{
    int i;
    for (i=0; i<NROFSTARS; i++)
    {
        StarTab[i].+= StarTab[i].spdx;
        StarTab[i].&= 255;

        if(StarTab[i].x<240)  //clipping
        {
            DrawPixel(x,y);
        }
    }
}
14 lines; 5 keywds; 3 nums; 42 ops; 0 strs; 1 coms    Syntactic Coloring v0.4 - Dan East  


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.
User avatar
Rhino123
pm Member
 
Posts: 66
Joined: Jul 2, 2002 @ 2:58pm
Location: Amsterdam


Postby Raster Rex » Dec 9, 2002 @ 7:45pm

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
Raster Rex
 


Return to Phantom's Forum


Sort


Forum Description

Discuss any of Phantom's projects here (Operation Nutcracker, etc.)

Moderators:

sponge, RICoder, Phantom

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron