You can change the line:
local numFish = 10
From 10 to 1.
You can change the line:
local numFish = 10
From 10 to 1.
Hello. I was asking for a file. A snippet doesn’t help me too much cause I get a bunch of errors in which I dont know what they mean (I think that may the reason i am not understanding things like I should)… Can anyone make a file for me to practice with? I appreciate the helpful attempt though, Panc. :)
Alright, I can break it down to brass tacks:
The sample project you’re talking about is the “fishies” sample. It is delivered with every Corona installation. You can locate it by starting the Corona simulator, clicking the Help dropdown, selecting “sample projects”, and then locating the “fishies” project under the Graphics header. Once this is loaded, you can then click on File, and then Open Project Files. This will open the folder in Windows Explorer. Once the folder is open, locate the main.lua file. This is the file that holds all appropriate code to run this example. Open this file with whichever code dev program you use (notepad, notepad++, BBEdit, etc…). Once the file is open, open the Search field from within the editor you are using. Within the search field, you want to type in “local numFish = 10”. Once your editor has found the location of this line, you can then change the number 10 to the number 1, in order to change the amount of fishies from 10 to 1. You can then save this file, and reload the simulator, to change the amount of fish from 10 to 1.
Let me know how you get on.
There is a simpler sample. Look into Corona installation folder called Samples / Getting Started and open the project called FrameAnimation1.
It is a simpler code bouncing around one fruit image. See if that is ok to go through. Cheers
Nah I get alll kinds of errors if I attempt to change any graphics…I kinda of feel like I shouldnt of spent the 50 bucks for glider. I thought I would be able to get a hold on this stuff though - but cant, obviously. I need a example like this but simpler. I get frustrated when i dont understand how to read code (and I cant read code - it looks like a foreign language to me).
I already tried the docs and I dont understand what they’re saying either - I feel like im reading chinese…I tried your example too, ksan, and thanks but I dont get that either…Maybe Im not cut out for coding? I will try a few other things but as of right now I feel like I rushed into purchasing glider (purchased about 10 minutes ago) - looks like a program that will now never get used. Could of bought something else with that 50 bucks, i got a big watch list on ebay that needs attention…
Can you build and run FrameAnimation1 in Glider? If so we can walk you through this. Honestly though its perhaps best to get one of the very nicely authored books on Corona and start there. Books by Dr. Burton etc come to mind.
Well, I was actually hoping to do the animation of what I see in the fishies file by way of a transition.to (or similar) type of statement. I saw an example where a transition.from and .to statements moved the graphic from the top to back down to the bottom of the screen. But I dont understand the code it is using.
it was something like transition.from (objectname, time=200, x, y, easing.inQuad)
then after that first statement, there was another transition.to (objectname, time=200,x,y,easing.out) type of statement - Or something like that. I remember seeing it in the DOCS. Is it possible to do what I see with the fishies file with a transition statement? Please advise - And thanks for responding so far. I appreciate the helpful attempts.
I havent looked at the animationFrame sample file yet, Im going to do that right now though.
I tried the animationFrame sample file and messed with it and it seems to be the simplified example I am looking for. Thanks for the suggestion, ksan. Now Im just trying to get ahold of what each line does. Thanks again.
Most welcome. Ask if you have questions. All the best.
I found the following code (in a different post) and altered it.
startMusic = {} startMusic[1] = audio.loadSound("sound1.mp3") startMusic[2] = audio.loadSound("sound2.mp3") startMusic[3] = audio.loadSound("sound3.mp3") local function playStartMusic() local thisStartMusic = math.random(#startMusic) audio.play(startMusic[thisStartMusic]) end audio.play(startMusic, {onComplete=playStartMusic})
I can’t figure out why it isn’t working. Can anyone explain what each line of this code is doing?
Once again, I grabbed it out of a different post that was asking about randomizing sounds. This is why there are no comments. Whenever I type any code I always comment each line so I can remember what each line does - And this is what I need here.
Can anyone be so kind as to comment each line so I can see what is going on with this code? Thank you.
Wanted to add a thanks to mr. Brent Sorrentino for the audio code sample which I found in a different post, just wish it had comments for each line… B)
I believe the problem with your audio code is with this hine:
audio.play(startMusic, {onComplete=playStartMusic})
startMusic is an array of loaded sound files, but isn’t a loaded sound file directly. So it can’t play, and thus not complete. I don’t think it can play an array like that.
You should likely just replace that line with:
playStartMusic()
That will run your function that randomly picks one of the loaded sounds and plays it.
Pretty sure that is what is going on.
thanks thegdog. your answer worked, it does play now (I am very grateful!), but I am trying to get it to play random everytime one sound/song ends. I tried adding this and it does not work.
playStartMusic({duration=5000, onComplete=playStartMusic})
I put the duration=5000 in there so it would only play 5 sec so I could see it if it working. It just plays all the way through then stops and doesnt play anymore. I noticed too that everytime I start the simulator a random song/sound will be called, but this is the wrong behavior - I want it to play continuously a different sound/song one after the other…
Any ideas?
Just taking a guess at this, but try:
startMusic = {} startMusic[1] = audio.loadSound("sound1.mp3") startMusic[2] = audio.loadSound("sound2.mp3") startMusic[3] = audio.loadSound("sound3.mp3") function playStartMusic() local thisStartMusic = math.random(#startMusic) audio.play(startMusic[thisStartMusic], {onComplete=playStartMusic}) end playStartMusic()
I think removing the local from that function might take care of it.
If it doesn’t, it is hacky, but you could do:
-- Define the array startMusic = {} -- Fill the array with music startMusic[1] = audio.loadSound("sound1.mp3") startMusic[2] = audio.loadSound("sound2.mp3") startMusic[3] = audio.loadSound("sound3.mp3") -- Set up function to play random music function playStartMusic1() -- Get a random number between 1 and however many items are in the startMusic array local thisStartMusic = math.random(#startMusic) -- Play the audio file and when done playing, call a function audio.play(startMusic[thisStartMusic], {onComplete=playStartMusic2}) end function playStartMusic2() local thisStartMusic = math.random(#startMusic) audio.play(startMusic[thisStartMusic], {onComplete=playStartMusic1}) end -- Start the playing of music playStartMusic1()
The second example you gave works perfectly. Thank you very much. Now - even though it works I am still interested in exactly what is going on here. Can you comment the lines for me? I want to learn what is going on in that code - I would be extremely grateful.
Sure, added some comments
Thanks again. You have been a great help. I appreciate it very much. I wish there were classes in my area to where I could learn this from an instructor - I have read many books and tried many tutorials on programming in corona sdk and I just can’t get it down… Programming has always been difficult for me to grasp…o well. Again - Thanks!
You’re welcome. Someone else might have a better solution to this.
I’m still fairly new to LUA programming as well. That’s why it drives me nuts that I wasn’t sure how to get this working with just one function to randomly play the music.
Here’s a less hacky way to do it as well:
-- Define the array startMusic = {} -- Fill the array with music startMusic[1] = audio.loadSound("sound1.mp3") startMusic[2] = audio.loadSound("sound2.mp3") startMusic[3] = audio.loadSound("sound3.mp3") -- Set up function to play random music function playStartMusic() -- Get a random number between 1 and however many items are in the startMusic array local thisStartMusic = math.random(#startMusic) -- Play the audio file and when done playing, call an outside function audio.play(startMusic[thisStartMusic], {onComplete=playMusicAgain}) end -- Set up function to allow us to loop back to the original function playMusicAgain() -- Call the play function again playStartMusic() end -- Start the playing of music playStartMusic()
Basically, does the same thing, but with a little less code. And always good to make apps as small as possible.