1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Making mobile apps...

Discussion in 'Mobile Marketing' started by shindig, Jul 4, 2013.

  1. shindig

    shindig Registered Member

    Joined:
    Aug 2, 2012
    Messages:
    62
    Likes Received:
    9
    Occupation:
    Programmer
    Location:
    Seattle, WA
    Home Page:
    I see a lot of people wondering what's involved in making apps, and wanted to share how I got started, and how easy it actually is.

    Basic info:
    Firstly, android uses the java language and has an SDK, but most commonly people use a program called Eclipse.
    Apple's iOS uses objective C language. Apple apps have to be compiled in a program called xcode.

    Rather than re-inventing the wheel, there are great tools to help you make apps rather than making everything by hand from scratch...and they abstract things in a way that you can port the same code to other platforms with minimal effort.

    Imo the best tool is called Unity 3d game engine. It's not just for making games. I've been using it for 4+ years, I have my full time dream job using it for making apps. I use C# for everything, and it can convert my android app to ios and vice versa, as well as publish to web browser or standalone pc/mac programs.

    Workflow:
    The workflow is top notch. You can take 3d models from turbosquid or any stock modeling site, or make your own in blender/3dsmax/maya, and simply drag and drop them where you want in the editor. You simply drag and drop scripts onto the models to start coding interactions. To trigger animations on models it's as simple as writing someObject.animation.Play(animName); in a script.

    There's an asset store where you can buy/sell your own creations.

    It has a wiki called Unity wiki with tons of code, shaders, etc, a top notch manual/docs and active community to help you through your problems.

    The power of unity is it's simple to use for non-technical people, but it has real power for those who know what they're doing. And it has the "write once, deploy everywhere" philosophy. You can simply switch platforms and it'll re-import your assets using compression formats for the platform and you can simply publish it to PC/Mac/Browser/Android/iOS....

    It makes native apps, it actually serializes your game and re-creates it in the android sdk for android, and xcode for iOS...

    Unity now gives free android/ios basic licenses which used to cost $400/each. They are also adding windows phone to the next version release.

    Common concepts:


    Raycasting-- A ray is an invisible line that is used often. If you touch a screen and want to trigger something only if you touch a certain object (the player or a button or a door to a building or anything) you do a raycast from the touched/clicked position forward and you it returns any colliders it hits.
    Code:
      void Update() {
            [URL="http://docs.unity3d.com/Documentation/ScriptReference/RaycastHit.html"]RaycastHit[/URL] hit;
            if ([URL="http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html"]Physics.Raycast[/URL](transform.position, Vector3.forward, out hit, 100.0F)){
                if(hit.gameObject.tag=="Player"){
                //Execute some code
                float distanceToTarg = hit.distance; 
    
            }
        }
    }
    
    Positions in 3d space are Vector3, meaning (x,y,z). For 2d it's Vector2, using only 2 axis (x,y).

    Touches/clicks on GUI:
    You can put text on a plane and use rays to determine if it's touched, or use a builtin method from Unity for GUI elements called HitTes();

    A common way to make a button is to create a GUITexture from the menu, add your texture(img) to it, scale it how you want, then inside an Update() method in a script in the scene you can determine if it's pressed 2 ways:
    Code:
    public GUITexture button; //public lets you drag the button into a button slot in the editor
    void Update(){
    if(Input.getMouseButtonDown(0)){ //If left mouse button clicked
    
     if (button.guiTexture.HitTest ([URL="http://docs.unity3d.com/Documentation/ScriptReference/Vector3.html"]Input.mousePosition[/URL])){ //if the click was on this button
    //Button clicked execute some code
    Application.LoadLevel(1); //load the second level
    }}
    }
    
    Mobiles will automatically treat a left mouse click as a touch, but it's better to use touch events for mobiles:
    Code:
     public float speed = 0.1F;
     public GameObject someObj;
        void Update() {
            if ([URL="http://docs.unity3d.com/Documentation/ScriptReference/Input-touchCount.html"]Input.touchCount[/URL] > 0 && [URL="http://docs.unity3d.com/Documentation/ScriptReference/Input.GetTouch.html"]Input.GetTouch[/URL](0).phase == [URL="http://docs.unity3d.com/Documentation/ScriptReference/TouchPhase.Moved.html?from=Input"]TouchPhase.Moved[/URL]) { //if there's at least 1 touch, and it's moving on the screen
                [URL="http://docs.unity3d.com/Documentation/ScriptReference/Vector2.html"]Vector2[/URL] touchDeltaPosition = [URL="http://docs.unity3d.com/Documentation/ScriptReference/Input.GetTouch.html"]Input.GetTouch[/URL](0).deltaPosition;    //deltaposition is the movement from the last frame to this one
                someObj.transform.Translate(-touchDeltaPosition.x * speed, -touchDeltaPosition.y * speed, 0); //this will drag the object in game by dragging it on screen
            }
        }
    
    The other great part of Unity is collision detection and physics. You can add colliders (hitbox) to objects, multiple, and they can either be a collider or a trigger. If it's a trigger, you can use some methods in a script to react to collisions.

    Unity has a few methods for trigger detection: OnTriggerEnter(), OnTriggerStay(), and OnTriggerExit()
    Code:
    void OnTriggerEnter(Collider other) {
            Destroy(other.gameObject); //destroy the other obj
        }
    //Or:
    private GameObject target;
    void OnTriggerEnter(Collider other) {
           target = other.gameObject;
        }
    void OnTriggerExit(Collider other) {
           target = null;
        }
    For Physics Unity uses PhysX, and to use it in an app all you have to do is add a rigidbody to a gameobject and it will react to gravity.

    To access the rigidbody in code is a piece of cake as well:
    Code:
    void FixedUpdate() {
    if(floating){
    floating=false;
            rigidbody.AddForce([URL="http://docs.unity3d.com/Documentation/ScriptReference/Vector3-up.html?from=Rigidbody"]Vector3.up[/URL] * 10); //upward force
    StartCoroutine("resetFloating", 0);
    }
        }
    IEnumerator resetFloating(){
    yield return new WaitForSeconds(3);
    floating=true;
    }
    
    Notice the startcoroutine and IEnumerator. Coroutines are how you add a delay to C# code. In that example it will reset the floating variable after 3 seconds which will trigger the code in the LateUpdate(). Coroutines must have a yield in them or it'll throw an error.

    Coroutines can be started with either StartCoroutine(methodname()); or StartCoroutine("methodname", 0.5f);
    The second one using a string to call the method can also be stopped by code using StopCoroutine("methodname");

    Floating and decimale point numbers must have an f after them or you get an error. So 0.5f would be half a second wait in a coroutine.

    Advanced:
    You can download/upload content from a server easily. If you google "unty serverside highscores" there's a php and C# script that shows you how to make a highscores database on your server, which can be hacked up for any kinda server communication you want to do....

    You can let people upload images off their phones easily. Just google unity screenshot server and there are working examples.

    The class used for communicating remotely is WWW class if you search for it in the documentation.

    Here's an app I started making but bailed on it:


    Ask if you have any questions...
     
    • Thanks Thanks x 1
    Last edited by a moderator: May 18, 2016
  2. amIdreaming

    amIdreaming Regular Member

    Joined:
    May 15, 2013
    Messages:
    233
    Likes Received:
    75
    wow these are quite advanced
    newbie questions, what are the differences between Eclipse vs Basic4android, Google MIT Appinventor etc? which is the most popular, flexible, easy to use?
     
  3. shindig

    shindig Registered Member

    Joined:
    Aug 2, 2012
    Messages:
    62
    Likes Received:
    9
    Occupation:
    Programmer
    Location:
    Seattle, WA
    Home Page:
    Haven't used basic4android or appinventor, but the google app inventor looks like the easiest to use for simple apps, by far.

    I'd go with html5 and javascript though for simple web type apps.
     
  4. oliverrusso

    oliverrusso Registered Member

    Joined:
    Mar 7, 2013
    Messages:
    63
    Likes Received:
    1
    Hi can u be able to convert my website into android application. I have a little bit knowledge about how to develop android application and how to published into Google play store. I have my own apps into Google play market. Do u have a services on fiverr. Let me know pls.