I was wondering how to get scrolling stars in the background of a game that I'm making. I would appreciate any help.
110359
Printable View
I was wondering how to get scrolling stars in the background of a game that I'm making. I would appreciate any help.
110359
scroll vertically, horizontally, ? Vertical is something like this. It assumes that you want 100 stars scrolling vertically in a 100*100 pixel area.
VB Code:
Type PointAPI x as long y as long End Type Sub Game_Loop() Dim StarPos(99) as POINTAPI,lCounter1 as Long For lCounter1 = 0 To 99 StarPos(lCounter1).x=Rnd*100 StarPos(lCounter1).y=Rnd*100 Next lCounter1 While Running For lCounter1 = 0 To 99 StarPos(lCounter1).y=(StarPos(lCounter1).y+1) Mod 100 Form1.PSet (StarPos(lCounter1).x,StarPos(lCounter1.y)),vbWhite Next lCounter1 Wend End Sub
That's a nice loop snake! :cool:
But, he may mean like the screensaver... It's not all that hard to do, but it is a challenge nonetheless. To have it come from the middle, I suggest using sine and cosine with a different radius and angle for each star. Expand the radius by the star's speed (if they all have the same speed it looks flat and boring) and draw it. When it's offscreen, you can create it in the middle again and start the loop over.
Oh, snake, put a doevents in there or else your code will never be displayed :D
[hides head in ass for shame]
oops, I am sorry. Doevents is also needed.
[/hides head in ass for shame]
It will look more 3D if a star's brightness is proportional to its speed. So a fast star is bright and a slow star is not ;)
Thanks for the help guys. Yes I did mean vertically. Again thank you.
110359
Where ever I put the section:
Type PointAPI
x As Long
y As Long
End Type
It tells me it can't go there. Also where should the doevents go.
You're declaring a Type, and declarations are always before the subs and functions :)
The DoEvents should be right after the While.
As that is true, far away stars could be really bright... add some randomness into that :)Quote:
Originally posted by Jotaf98
It will look more 3D if a star's brightness is proportional to its speed. So a fast star is bright and a slow star is not ;)
It keeps coming up with an error saying:
Cannot define as a Public user-defined type within a private object module.
Select Project->Add Module
Not class module, not a form, but a module.
Sorry about all the questions. Thanks for all the help.
All you have to do is declare the type as a private type...
Private Type PointAPI
x As Long
y As Long
End Type
no prob, right!
In my game craft, stars move opposite to the direction of travel.
Check it out :
http://www.coolground.com/plenderj/1.0.17.zip
Older versions of the game also had stars moving at different speeds in the background to make them look farther away, but that effect only works if you're travelling in the one direction.
It looks stupid if the player changes direction often