@all - Please read and correct if I goof any details.
@ its4krishna - Part 1
Before I answer, I hope that you’ve looked at the API docs (https://docs.coronalabs.com/daily/api/) and specifically read these entries:
1. Why do we need to use display.getCurrentStage():setFocus(self, event.id
When you touch the screen, the device starts tracking that touch. Until your finger is lifted, the device can differentiate this touch from another finger touching the screen before or after.
To be clear, the device knows how to group began, moved, and ended phases for a specific touch.
setFocus() tells the system to start sending all other touch events related to the current touch event being processed to the current object doing the processing:
[background=#fafafa]-- This code is in the current listener.[/size][/background]
-- 'self' is the object currently receiving the event details -- event.id is required if you are allowing multi-touch. Each touch (in multitouch) has a -- unique ID display.getCurrentStage():setFocus( self, event.id ) -- Now, all future events related to this touch will be sent to 'self' for processing.
Current Stage & setFocus() Relationship
This is a fancy name for ‘top group’. The top group contains all other groups and gets all touch events sent to it first. So, we must setFocus() via ‘current stage’ to ensure that the event gets routed to the right child of that stage.
2. What is the use of self and when should I use self in my codes and what does self.markx means
Self is the object which the listener/function is ‘attached’ to. This is not something that can be explained in a few lines, so let me share this link with you (and how the community):
https://docs.google.com/document/d/1Y84OufJB_eGZFkUknX28IBZFRV2_-gw1OOTsozN-IK4/edit?usp=sharing
I wrote a quick and dirty guide for a friend.
I suggest reading the entire document, but pay close attention to pages 7 … 8 for an answer to your question about self.
self.markX = something
This is creating a field named ‘markX’ on the object (self) that is calling this listener. It then asigns a value (something).
This is ‘field’ is now forever available on that object till it is set to ‘nil’. So, in later calls to the touch listener, we can check for the last value in that field if we need it (which is what he is doing).
3. what does self.isFocus=true means
As with self.markX, this is a field we are creating and setting to true (or false) to use as a flag in later calls to the listener.
When it is set to true, this listener will proceed to the correct if-the-else branch for a ‘currently focused’ object.
4. What does event.xStart and event.y gives us
This is all in the API docs. Please read/follow each link on this page:
https://docs.coronalabs.com/daily/api/event/touch/index.html
@ its4krishna - Part 2
Be sure you have spent time doing plenty of Lua programming exercises before you try to understand Corona code. Without a solid foundation you will quickly become lost and start forming bad habits based on partial knowledge.
I’m not chastising you here, but hoping to help you.
I also strongly suggest following some formal guides or training like Dr. Brian Burton’s Corona Books, especially if you don’t already know at least one programming language and/or do not have a formal education (taught via classes) in programming.