Hi Rob, do you think when your done with your game you could post the code somewhere? It would really help me out with a lot of things. When your done, that is…
Below is a page with a wealth of info and tutorials for Corona:
I’ll consider it. I generally don’t open source/public domain my apps. I tend to share snippets from them though. Besides, my punch-list is two pages in a 2 column note book. I just need to bear down and get some work done on it.
Rob
Ya thats what i asked…but according to your answer i want to ask you that do we have to save the file for game levels i normal main.lua or we have to make one new lua file…and yes i asked that how to make levels but u answered for how to go to that level …thanks well but tell me how is level made and is it a function…please give example…
YOU ARE AWESOME THANK YOU
YA ya you can include it where you want to but i want to ask you that how game levels are maked…like if we want to make any function we do like
local function Example (event) if elseif else end end end Runtime:addEventListener
and if we want to insert image than we do it like
local image = display.newImage("example.png") image.x=centerX image.y=centerY
but now, for example i have a button which displays “play” and i want to make it like when user touches it it show levels so i ll do
local function onTouch(event) if (event.target.name=="play") then audio.play(backgroundmusic), composer.gotoscene(example.lua) end end Runtime:addEventListener
Its just what i feel will look like, so if its not correct then correct it, now coming back to point i want to know how levels are made like is it a function or what please give the world most easiest example of the code from the top so i can understand easily(from inserting images to level to going to scene)…Thanx
YOU Are GENIOUS
If you need advanced levels with varying graphics, physics, and/or animations, I highly recommend that you take a look at Level Director X. It’s rather advance in functionality but easy for anyone to pick up and use. There is a completely free version and the full version is only $20 (a steal if you ask me).
Now that you’re asking about how to manage multiple scenes, we have a wealth of tutorials, guides and documentation on Composer our scene manager. But let me point you to one resource in particular:
https://coronalabs.com/blog/2015/04/14/tutorial-the-basic-game-template/
At the bottom is a link to our Github repository where you can download the basic game template. It has no game in it other than two buttons that say “I Win” and “I loose” or something like that. The tutorial explains the flow of the game template and it serves as a great example of composer scenes and moving among them. I would suggest starting there.
After that, check out:
https://coronalabs.com/blog/2015/08/11/tutorial-treasury-composer/
It has a collection of (almost all) all of our information regarding Composer.
Rob
Oh so you means that whenever i click on the button “play”…it changes the scenes? and it doesnot have any link to function?
When you say link to function, are you thinking like a web link or do you have another thought in mind. With Corona going to a new scene is a matter of calling the command: composer.gotoScene( “scenename”, { optional=parameters } ) where “scenename” is the name of the .lua file containing a valid Composer scene that you want to go to and the optional parameters include things like what transition to use and how long the transition should take. For instance if you wanted to crossFade from menu.lua to game.lua over 500 milliseconds (1/2 second), you would write:
composer.gotoScene( “game”, { time=500, effect=“crossFade” } )
Now how you get to a point to run that command is dependent on your app and what’s going on. Going from “Menu” to “Game”, the menu scene probably has a “Play” button. When that button is pressed an event is generate that will call a function you’ve defined to handle the button touch. In that button touch at a minimum you want to call the command above.
Once you’re in your game and something happens like your player dies and you want to go to the game over scene you might just call the composer.gotoScene( “gameover” ) as part of the code that detected the player died or if the player beat the level and you want to go to the next level you might want a “nextlevel” scene that you go to automatically.
Rob
OH Thats great but i have a little confusion that is when i do not know about composer screen then i thought that moving from play button to game it maybe like this->
display.setStatusBar (display.HiddenStatusBar) local backgroundmusic = audio.loadStream("background.mp3") local centerX = display.contentCenterX local centerY = display.contentCenterY local background = display.newImage("background.png") background.x = centerX background.y = centerY local button = display.newImage("button.png") button.x = centerX button.y = 420 --Now this is weird when i done this local function onTouch(event) if(event.phase == "began") then local newImage =display.newImage("nyc.png") newImage.x = centerX newImage.y= centerY audio.play(backgroundmusic) end end Runtime:addEventListener("touch", onTouch)
So is like going to scene or what as when i click on the screen ,the new image appear and a background music plays…for example if it is in composer scene then how do it be held…i mean that where we have to keep these files!!!..
Thanx and your tutorials are cool!
Depending on the complexity of the game, you may not need scenes at all. For something simple you can build everything in main.lua. But once things get more complex it’s really best to break things out into multiple modules. My first game was all in main.lua before I learned about scene management and today that code is nearly impossible to work on. The file is too long, too many lines of code in one file. Breaking things out into their own modules helps maintain the project and makes it easier to work with.
To answer your last question: think of a scene as like it’s own mini-app. It will have it’s own background, buttons, artwork, activity and so on. Each scene is a page of your app if you want to think about it in web page terminology. Each scene could have it’s own background music.
If you have not done so, download the sample-game-template from the first tutorial. It will create a folder with everything in it. Your project folder has a main.lua, config.lua and build.settings. Your scene.lua files go in the same folder. As you learn more, you can with a few simple changes have your scene files in a sub-folder, but I would wait on that for a couple of projects. The main focus when starting to use Composer is understanding Composer.
I would also suggest that you go through and build out the two apps in our Getting Started Guide.
https://docs.coronalabs.com/guide/programming/index.html
Chapter 5 covers how to get a game that’s all in your main.lua into scenes. I would still recommend going through the previous chapters so you’re familiar with the game code you will be converting.
Rob
Oh thank you very much and yes please tell me the name of the game you maked and got the highest download among all your other game…in simple words tell me your most successful name of the game!..Thanks and ya on android one!
Normally, you would make a new lua file. But, like Rob said, it is very useful to transfer data that you are going to use multiple times from the same source.
local function onTouch(event) if (event.target.name == "play") then composer.gotoscene("example.lua") end end
For the background music you would want to play it when you get to the next scene.
Oh Ya! its simple and bro please reply to my latest posts! Thanx