Oh I love Lua tables. As far as typical arrays go, as a single dimension array's go, they are beautiful. But when you get to multi-dimensional arrays it gets more tricky since you're having to do a table in a table (in a table (in a table)))
@Josh, it's really not even functional enough to demo the concept.
I am new to this whole thing and was wondering how you can make the blocks fall without the physics engine? I was also wondering how you make them fall down a straight path? Whenever i put them in the physics engine, they fall in different places. Sorry I'm a noob, but any advice would help.
In game programming there is a concept known as the "Game Loop". This is a loop that runs forever (until the game is over or the player exits) that manages moving everything.
In Corona SDK, that concept is implemented using a special event called "enterFrame". By default, 30 times per second (or 30 FRAMES per second); which is how fast the screen updates, this event will be triggered and your game can respond to it by putting this line of code in place where you want to manage objects manually.
1
| Runtime:addEventListener("enterFrame", someFunctionToRunEachFrame) |
If you want a quick refresher, have a look at this article I wrote here it talks about the basics of movement in a computer game, when there was *no* physics engine that could be used as physics.start().
cheers,
?:)
How would i make 5 certain objects fall down 5 certain paths continuously from above the screen without using physics and without being able to control the movement of them? Thanks a lot for all the help
@bmuneoka: Impossible. You need to have some kind of control over an object, no matter if you use physics or somerthing else. How else would you determine if a state in the game needs to be changed.
Anyway, back to the initial problem. Use Transition.to with an eventhandler that deals with the object, ones it will reach its final position. You also need to be able to change the transition on the fly if you user interacts with the object.
How is it impossible? What about the "crates" sample code application? The crates fall from above the screen from wherever assigned to fall from. All i want to do is make random objects fall from above the screen (like tetris) constantly (ie. numbers falling from the top of the screen) without using physics and maybe have some function catch them
I think Mike meant its impossible because something has to be responsible for moving the object.
There are three ways to move things in Corona SDK:
1. Use Physics
2. Use Transitions (transition.to)
3. Manage it yourself with changing .x and .y
Of course transition.to is a way to change .x and .y automatically and is probably the simplest path to do things falling from the top to the bottom. In my game OmniBlaster (http://bit.ly/omniblaster) I use transition.to to manage all my weapons fire. For moving the enemy ships and asteroids, I use #3 and have my own move function that gets called during the "enterFrame" event.
If you use the easiest of the languages/frameworks, they will all have to be told what to do. This telling generally is in the form of code.
If you apply physics, then the object acts like a real object that is affected by gravity as set in that world and will fall in the direction of the gravitational forces.
If you have learned or heard of LOGO, a language they used to use to teach kids the basics of programming, even in that there are commands that include, up 100, turn 90, left 100, turn 90, and so on.
Similarly, coronaSDK makes things easy for developers but is by no means any more than that, it still requires directions on how to manage the same.
So finally coming to your predicament, as many have suggested and in the tutorial on movement that I pointed out earlier, you have to move the object in regular intervals to provide the illusion of movement. I shall write another tutorial on this topic soon.
till then, I hope this can give you an idea.
cheers,
?:)
...CONTD....
just wanted to add this video to show you that you can have objects keeping on moving till a particular specified event/object/condition is met.
look at the video here
The balls have to move in the direction of the swipe and also be aware of what's in the way.
cheers,
?:)
sorry for sort of spamming here, but im trying to teach myself this stuff, so i have another question: How can I make a continuous loop after i've made a transition.to() function, so that it keeps on going, after the transition is complete?
I really should do a blog post on this topic.
Traditionally games use something called a "game loop" that constantly watches for input from the devices (including the network for multi-player games).
Under Corona SDK's hood, there most likely is such a loop that manages all the animations and screen updates as well as monitors for touch events and network input.
While Lua supports FOR and WHILE loops where you could write your own, the problem with that is that there is no way to keep your loop from eating up all the CPU time. If this were Objective C there are controls that sleep your app except when it needs to run. So if you tried a
1
2
3
| while true do
some stuff
end |
@bmuneoka, a Transition.To statement can have an onComplete method that is fired once the transition is done. If you have predefined the function name as a local, the it should be possible ot call itself again.
Here is an example out of one of my games were one fucntion is called from a transition.to statement.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| local onBombDelete
local onBombComplete
--****************************************************************
onBombDelete = function( target )
--****************************************************************
target.parent:remove( target )
end
--****************************************************************
onBombComplete = function( target )
--****************************************************************
local params = { time=300, xScale=2.0, yScale=2.0, onComplete=onBombDelete }
target.hit = true
target.mytween = transition.to (target, params)
end |
What robmiracle is describing is a so called finite state machine approach. You have a main game loop which controls the mechanics of the game depending on one or more state variables. You can use this approach in functional programming languages and also inside an event driven language like Corona. Just don't lock up the engine with an infinite loop like robmiracle has explained.
I'm starting to understand now thanks a ton guys
views:2685 update:2011/10/4 17:12:07