Anyone know how I can 'reverse' starfield?

Hi everyone, I’d like my inter-stellar ship to have a reverse gear. Do any of you know how I can effectively reverse the starfield demo in PC, I’ve played around with the default settings, but I think I need to use other API syntax that I haven’t discovered yet.

Thanks muchly. [import]uid: 176868 topic_id: 37158 reply_id: 67158[/import]

Assuming you are talking about the example here:
http://developer.coronalabs.com/code/simple-parallax-starfield-or-use-it-snow

then you have to subtract the speed instead of adding it, and check for the stars to move off the top of the screen instead of the bottom, then move them to the bottom instead of the top.

I put comments in the code where I changed it. If this is not the example you are asking about, most likely it will have similar mechanisms that need to be reversed.

Also note that example is pretty old, and used depreciated code, so I just updated it.

[lua]
– create table
local stars = {}

– initial vars
local stars_total = 600
local stars_field1= 200
local stars_field2= 400
local stars_field3= 800
local star_width = 1
local star_height = 1

– create/draw objects
for i = 1, stars_total do
local star = {}
star.object = display.newRect(math.random(320),math.random(480),star_width,star_height)
stars[i] = star
end

– update star locations and setcolor
local function udpdatestars(event)
for i = stars_total,1, -1 do
if (i < stars_field1) then
stars[i].object:setFillColor(100,100,100)
starspeed = 1
end
if (i < stars_field2 and i > stars_field1) then
stars[i].object:setFillColor(155,155,155)
starspeed = 2
end
if (i < stars_field3 and i > stars_field2) then
stars[i].object:setFillColor(255,255,255)
starspeed = 3
end
–changed +starspeed to -starspeed
stars[i].object.y = stars[i].object.y - starspeed

–changed stars[i].object.y > display.contentHeight
if (stars[i].object.y < 0) then
– changed -480 to +480
stars[i].object.y = stars[i].object.y+480
end
end
end

– let updatestars run at enterFrame
Runtime:addEventListener(“enterFrame”,udpdatestars)
[/lua]
[import]uid: 173551 topic_id: 37158 reply_id: 145478[/import]

Assuming you are talking about the example here:
http://developer.coronalabs.com/code/simple-parallax-starfield-or-use-it-snow

then you have to subtract the speed instead of adding it, and check for the stars to move off the top of the screen instead of the bottom, then move them to the bottom instead of the top.

I put comments in the code where I changed it. If this is not the example you are asking about, most likely it will have similar mechanisms that need to be reversed.

Also note that example is pretty old, and used depreciated code, so I just updated it.

[lua]
– create table
local stars = {}

– initial vars
local stars_total = 600
local stars_field1= 200
local stars_field2= 400
local stars_field3= 800
local star_width = 1
local star_height = 1

– create/draw objects
for i = 1, stars_total do
local star = {}
star.object = display.newRect(math.random(320),math.random(480),star_width,star_height)
stars[i] = star
end

– update star locations and setcolor
local function udpdatestars(event)
for i = stars_total,1, -1 do
if (i < stars_field1) then
stars[i].object:setFillColor(100,100,100)
starspeed = 1
end
if (i < stars_field2 and i > stars_field1) then
stars[i].object:setFillColor(155,155,155)
starspeed = 2
end
if (i < stars_field3 and i > stars_field2) then
stars[i].object:setFillColor(255,255,255)
starspeed = 3
end
–changed +starspeed to -starspeed
stars[i].object.y = stars[i].object.y - starspeed

–changed stars[i].object.y > display.contentHeight
if (stars[i].object.y < 0) then
– changed -480 to +480
stars[i].object.y = stars[i].object.y+480
end
end
end

– let updatestars run at enterFrame
Runtime:addEventListener(“enterFrame”,udpdatestars)
[/lua]
[import]uid: 173551 topic_id: 37158 reply_id: 145478[/import]