Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Moving star background

edited June 2014 in Questions Posts: 4

I am new to the Codea community and I am starting my first project, but I can't seem to get a simple background to work. The background I am trying to create is a black background with white dots (stars) moving to like like they are going towards the screen. I have already spent a lot of time creating my own sprites and game music, so I don't want to give up on this because of the background. If someone could give me some tips on how to create this background in working order, I would be greatly appreciative.


  • Posts: 425

    The bit invader example has a scrolling star background, you could look in there

  • dave1707dave1707 Mod
    Posts: 7,749

    @Rekneps Here's an example of moving stars towards you. It's set up for white stars, but if you want colors, comment out the line that says white stars.

    displayMode(FULLSCREEN) function setup() col={color(0, 12, 255, 255), color(107, 145, 171, 255), color(255, 243, 0, 255), color(168, 169, 97, 255), color(255, 255, 255, 255), color(255, 150, 0, 255), color(255, 0, 13, 255)} nbrStars=150 st={} for z=1,nbrStars do c=math.random(7) -- colored stars c=5 -- white stars table.insert(st,vec4(math.random(WIDTH),math.random(HEIGHT),1,c)) end speed=75 end function draw() background(40, 40, 50) for a,b in pairs(st) do fill(col[b.w]) ellipse(b.x,b.y,b.z) xd=WIDTH/2-b.x if xd<.05 and xd>-.05 then xd=.1 end yd=HEIGHT/2-b.y if yd<.05 and yd>-.05 then yd=.1 end b.x=b.x-xd/speed b.y=b.y-yd/speed b.z=b.z+.1 if b.x<0 or b.x>WIDTH or b.y<0 or b.y>HEIGHT then st[a].x=math.random(WIDTH) st[a].y=math.random(HEIGHT) st[a].z=1 end end end
  • Posts: 4

    Thank you all so much!

  • Posts: 4

    @dave1707 Also, a huge thank you to you! This was exactly what I was looking for!

Sign In or Register to comment.