How to make an object static in lua - lua

I'm making an android game in LUA with the corona SDK and I want to stack boxes onto each other.
I can add the boxes to physics but when the boxes land I want them to become static so they don't move anymore after they have landed and I have no idea how to do that. Can someone please help me? I already tried it with physics.removeBody() after I added them but that didn't work.
I'm sure the solution will be pretty easy but I'm relatively new to the corona SDK.

One way of accomplishing this would be to - after
physics.removeBody()
add it again, this time as static, eg.:
physics.addBody(bodyObj, "static", ...)
Remember this about physics.removeBody() though:
This call cannot be used in a collision event. However, your collision
handler may set a flag or include a time delay via
timer.performWithDelay() so that the action can occur in the next
application cycle or later

Related

iOS Swipe Gesture Recogniser for a quick-paced game

I'm new to the iOS development world, so I'm starting off with a game that's neither Clash of Clans or the infamous 'I'm Rich'. I know Python and HTML/CSS so I will be able to cope with computer terms, but it would be great if you would be able to explain any answers.
A pattern flashes on the screen for half a second, let's say it is 'arrow left, arrow right, arrow left' (in picture form). Then the user has to replicate the pattern (in the right order) in order to boost forward. Basically, I'm asking what would be the simplest/most effective way of programming this? It would be great if I could easily add more patterns.
One way I thought that it could be done is to have an ID for each pattern, in which there are pre-defined 'nodes' that have to be swiped in a particular order. One benefit to this idea is that I can add patterns, however it could take a while to program them. Another idea I had is to assign an 'eraser' to the user's brush and it will detect when +-95% of the pattern is swiped. However, this would allow the user to swipe in any order.
Perhaps there is something super easy that I can do, but at the moment I have no idea. It would be great if I could do this in Apple Swift, however Objective-C is not a problem.
Thank you in advance,
Will
You basically answered your own question in the title. Take a look at the UISwipeGestureRecognizer documentation. From there you'd just want to push gestures into an array and then compare to existing pattern arrays

Corona SDK - Managing Game State/Objects/Inventory System/Sprite Animation

I am attempting to determine the best way and most efficient way to handle the following tasks in a game written with the Corona SDK. It seems like there are so many ways to do things that it becomes quite confusing, so I am hoping someone here can help!
I am creating an adventure type game that will have an inventory system/puzzles etc. The thought process I've developed so far involves using separate "classes" to handle each specific aspect of the game. Such as InventoryManagement.lua, ObjectManagement.lua, PuzzleManagement.lua etc.
Just a side note - this game really doesn't involve Physics, but I would like to have static images with animations that occurs (Think opening a door or picking up an object):
Here is an example of what I am trying to accomplish:
Say you start a new game and it loads the first scene. I need to setup the player's inventory, the objects in the room, their state, images for these things etc. which I assume could be defaulted on first game load, and loaded subsequently ...
Then the player clicks on a key to pick it up - at this point the key needs to appear in their inventory so now it will be removed from the scene, added to their inventory (Via InventoryManagement?), and the scene will be updated (Via SceneManagement?)...
From now on the key should no longer show in the scene.
Now say they click the key and use it on a door, the door should animate open and remain open from now on.
If the player leaves the room and comes back, the key should not appear.
Now to me it makes sense to load/unload the scene every time you enter/leave the scene, but ... won't this become memory intensive etc. if you do it this way? ... Is there a better way to handle a scene if it has say, 30 objects on screen?
Hopefully that is clear - It is hard to find specific information related to each one of these elements. Everything seems to be related to physics games and I can't seem to find something on how to "Add a key to the scene if, but not if, and if it's been used then animate that door" :(
Thanks!
Had the same problem with unexpected results when jumping between storyboards. One thing I found out was
Always make sure to Runtime:remove and stop the timers you use. One alternative when you want to reset everything is to make a reset.lua file and on enterScene you use storyboard.removeScene or storyboard.purgeScene (If you just want to get rid of all display objects you have rigged up in memory in scene:createScene).
Also check out storyboard.RemoveAll() or purgeAll()
You need to make some stuff in Global space (using _G) to use them between scenes.
To change between scenes, "Storyboard" is very nice.
But mind you, you will need to use some manual memory hacking if you make things too much memory intensive, mainly, you might need to before loading a scene, do several calls of "collectgarbage" after cleaning the last scene, otherwise you will hit a curious problem:
You loaded scene "A".
You switch to scene "B".
The game 'unloads' "A", but the garbage collector don't, then loads "B", the end result is memory use of "A" + "B".
On this adventure game I was making in Corona, it resulted in several crazy crashed until I figured the "collectgarbage" trick.

iOS: How to make the CADisplayLink's event called BEFORE actual screen draw?

I'm building a cross platform UI library's iOS implementation using UIKit, one of the library's primary function is allow user to change the child control's size freely, and the parent control's size will automatically adapt.
Since refresh the parent's size everytime when a child's size changed is inefficient and unnecessery, so I designed the UI system to refresh all "dirty" control's position, size, and a lot of things before actual device draw/render happen. On iOS, I use CADisplayLink to call the refresh method, then I discovered the event was called AFTER everything has presented onto screen, that caused the following problem:
User will see a "crashed" layout first. (The render happens first)
After a short period (CADisplayLink's event triggered), everything will return to normal.
At first I thought my way of using CADisplayLink is wrong, but the solution cannot be found anywhere, so I'm quite despaired right now (I'm going to hang my self!!)
Or maybe I shouldn't use CADisplayLink at all?
Please Help me!
PS. Since I'm building a cross platform thing I'm actually using MonoTouch, but I believe the basic concept is same.
PS2. And since I'm using MonoTouch, which is C#, so the description above may not fit in the Objective-C world (like the word "event", I think the Obj-C relevant is selector, or something ^_^)
PS3. Also please pardon my poor English, feel free to ask me any questions if my description isn't clear enough.
Codes here:
CADisplayLink _displayLink = CADisplayLink.Create(Update); //Update is my refresh method
_displayLink.AddToRunLoop(NSRunLoop.Current, NSRunLoop.NSDefaultRunLoopMode);
Should be easy enough to understand ^_^
From all the information of what I can gather, is that basiclly there is no way of doing that. So I have modified my layout code, which now apply the properties immediatly after a value is set. Some optimization still required, but no need to rely on CADisplayLink anymore.
Thanks anyway!

What approach should I take in developing simple animation based iOS game

My question here is not about how to achieve something, but what all to include that would have the best effect for the content I am presenting.
I am designing an app (probably with single screen) which is story based. Not a story, but a scenario, to say. A typical scenario is driving through the street, going to office or both in one. And so on.
Upon each tap (or any user activity), next step of the scenario will reveal itself. Like meeting a person, colliding with a car and so on. But since these scenarios are virtually infinite, it is not possible to design graphics for my app. To say in other words, it won't be an office, an attic, a castle or a house. It can be any of that, or a combination of them.
Due to this limitation, and partially my laziness to deal with a lot of graphics (I don't have a subordinate, nor big bucks!), I have decided to do some simple animation upon each tap. A single object (like a ball) can roll or emerge from nowhere etc.
My questions:
1) Optional: How do I achieve this animation? I know objective c but I do not know if it suffice. Box2d is other option that I know of. Is it ok or an overkill? If objective c suffices, can anyone help me with simple code that will animate a rolling ball from far (center of the iphone)?
2) Required: Above is something I can figure out by myself, but this is more important: How do I devise my other UI to describe the scene and situation? What all iOS features would fit the best in situation? I can think of single UILabel to describe situation, but I do not know how I can position/animate it along with 1 above. Again, this seems far too simplistic however. Are there other iOS views that could help me?
Sorry for somewhat ambiguous requirement, but I am facing lack of imagination here, and I know if I am misled at this step, a lot of things can go wrong.
Thank you for your assistance.

What is the right way to design a point and click game with Lua?(Corona)

I have some ideas,I have already drawn the scenes roughly and put them into corona.
This is how I would think it would work.
1.I have all the major scenes
2.In each major scene ,there are mini scenes,which lead to smaller scenes with puzzles.
3.I create a game.lua module so it would handle the game logics,and keep track of them.
Example:
A.Door is opened,puzzle number one is solved.
B.Send a costume event to the game module.
4.I need a separate module for inventory box so it acts as an overlay over other scenes.
It also interacts with game module.
.
I know you might say,wait till you get started,but Am I on the right Track?
Do you have better suggestions or know any code examples(Corona Sdk,Lua,Moai,GiderosMobile)?
.
Thanks in advance
I am making a game more or less on this style using Corona, there are a beta on google play.
Corona SDK offers a API named Storyboard, that API allow you to code each scene as a lua module, and allows also you to load a scene as a "overlay".
I guess that you would make each of your scenes a full Storyboard scene, and the inventory a "overlay" scene.
The difference between overlay to a normal scene, is that when you load a overlay it triggers a event on the scene that was open instead of unloading that scene (And when the overlay is unloaded, it triggers another event)
So yes, at least if you do it in Corona, you are in the right track!

Resources