space background

Hey guys, 

just found on the web an code that should be working based on the writer of the website.

the code should create an space looking background, but for some reason i cant get it to work and i was wondering what the problem is. i dont get any errors.

this is the code:

main.lua

display.setStatusBar(display.HiddenStatusBar)

local storyboard = require(“storyboard”);–Include the storyboard library

local physics = require(‘physics’)  

physics.start()

physics.setGravity(0, 0)

storyboard.gotoScene(“Menu”)

config.lua

application = {

    content = {

        width = 320,

        height = 480,

        scale = “letterBox”,

        fps = 30,

    },

}

menu.lua

local storyboard = require(“storyboard”)

local scene = storyboard.newScene()

function scene:createScene( event )

local scene = self.view

    local createStars = function()

        for i = 1, 20 do

            local star = display.newCircle( math.random( display.contentWidth ), math.random(display.contentHeight), 1 )

            star:setFillColor( math.random(200) + 55 )

            physics.addBody( star,{ density = 50, friction = 0, bounce = 0, radius = 1 } )

            star:applyLinearImpulse( 0, -1, star.x, star.y )

            local moveStar = function()

                if star.x ~= nil then

                    if star.x >= 0 then

                        star:removeSelf()

                    elseif star.x > 0 then

                        star.x = star.x - 5

                    end

                end

            end

timer.performWithDelay( 1, moveStar, display.contentWidth + 50 )

end

local makeStar = function()

    local star = display.newCircle( display.contentWidth + math.random( 20 ), math.random(display.contentHeight), 1 )

    star:setFillColor( math.random(200) + 55 )

    local moveStar = function()

        if star.x ~= nil then

            if star.x >= 0 then

            --print( “removing” );

                star:removeSelf()

            elseif star.x > 0 then

                star.x = star.x - 5

            end

        end

    end

timer.performWithDelay( 1, moveStar, display.contentWidth + 50 )

end

timer.performWithDelay( 75, makeStar, 0 )

end

end

function scene:enterScene( event )

local scene = self.view

if storyboard.getPrevious() ~= nil then

storyboard.removeScene(storyboard.getPrevious())

end

end

function scene:destroyScene( event )

local scene = self.view

end

scene:addEventListener( “createScene”, scene )

scene:addEventListener( “enterScene”, scene )

scene:addEventListener( “destroyScene”, scene )

return scene

Let me know if you know an answer to this. And i am new to corona. just learned it 3 weeks ago.

What’s not working?

When you say you are getting no errors, are you looking in your terminal/cmd window or are you only looking for popup errors from Corona SDK?

What version of Corona are you running?

Thanks

Rob

Rob , at the moment i am using the latest version. And i think it is better if you see it yourself. here is the link:

http://thatssopanda.com/corona-sdk-tutorials/create-a-space-background-with-sean-perryman/

What they show in the video, that’s actually what i want, but for some reason i can’t create it.

i hope the information above can help you to help me to answer my question :slight_smile:

I  know what you want, but what I don’t know is what is not working.  Are you getting any errors in your terminal or cmd window?  if you don’t know how to check that please read:
 

https://coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

It seems that you create a “master function” called createStars but you never calls it so no stars are being created.

Here is another one I made, which might be a little easier to understand:

local function createStars() local starCounter = 0 local function createStar() starCounter = starCounter + 1 local star = display.newCircle( display.contentWidth + math.random( 20 ), math.random(display.contentHeight), 1 ) star:setFillColor( math.random(200) + 55 ) local function removeStar() star:removeSelf() starCounter = starCounter - 1 end transition.to(star, {time = math.random(1000, 5000), x = - 1, onComplete = removeStar}) end local function starCreator() if starCounter \< 20 then createStar() end end Runtime:addEventListener("enterFrame", starCreator) end createStars()

Best regards,

Tomas

THANK YOU Tomas, just what i needed and as you said now i understand it. :smiley:

What’s not working?

When you say you are getting no errors, are you looking in your terminal/cmd window or are you only looking for popup errors from Corona SDK?

What version of Corona are you running?

Thanks

Rob

Rob , at the moment i am using the latest version. And i think it is better if you see it yourself. here is the link:

http://thatssopanda.com/corona-sdk-tutorials/create-a-space-background-with-sean-perryman/

What they show in the video, that’s actually what i want, but for some reason i can’t create it.

i hope the information above can help you to help me to answer my question :slight_smile:

I  know what you want, but what I don’t know is what is not working.  Are you getting any errors in your terminal or cmd window?  if you don’t know how to check that please read:
 

https://coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

It seems that you create a “master function” called createStars but you never calls it so no stars are being created.

Here is another one I made, which might be a little easier to understand:

local function createStars() local starCounter = 0 local function createStar() starCounter = starCounter + 1 local star = display.newCircle( display.contentWidth + math.random( 20 ), math.random(display.contentHeight), 1 ) star:setFillColor( math.random(200) + 55 ) local function removeStar() star:removeSelf() starCounter = starCounter - 1 end transition.to(star, {time = math.random(1000, 5000), x = - 1, onComplete = removeStar}) end local function starCreator() if starCounter \< 20 then createStar() end end Runtime:addEventListener("enterFrame", starCreator) end createStars()

Best regards,

Tomas

THANK YOU Tomas, just what i needed and as you said now i understand it. :smiley: