Thursday, May 22, 2014

Technology Bashers

"Bashing on tech you have no experience w to promote the one tech you know says more about u as a dev than the tech..." -- Iris Classon

Sunday, May 18, 2014

Animation not working during gameplay

Here are the properties prior to getting it fixed:

Idle:



Walking:



Here are the transition settings:

Idle to Walking. Notice previewing transition was not available too




Walking to Idle:



The solution is rather simple, on Idle animation, change the speed to 1 (not working when the idle starts with 0):






After setting the Idle's speed to 1, the walking animation works during game play; and the animation transition and preview pane also become available in Inspector too:





Wednesday, May 14, 2014

High-falutin code #3 Deliberately leaking the abstraction

Even in modern times, there still are developers who would deliberately leak the abstraction even when there's no compelling reason to do so

<div id='blah'>Meh</div>

.
.
.

var e = document.getElementById('blah');
e.style.color='red';
e.innerHTML = "bleh";


Most who would do that would use efficiency as an excuse. Those showboating attitude are akin to what snotty attitude C developers exhibit towards C++ when C++ first came out, saying C++ is inefficient as under-the-hood C++ always pushes an extra parameter (class instance reference) to a function; likewise when C language first came out, assembly language developers see the C language inefficient in generating machine code as compared to their handcrafted assembly language code. We should let the API do the heavy lifting and not leak the abstraction when there's no reason to do so


It's lamentable there are still some developers who would handcraft their DOM manipulation using pure javascript, i.e., sans the framework, and proudly saying they don't know scant (or doesn't want to know) about jQuery, AngularJS, react and whatnot, that's a thinly veiled humblebragging, to them just because old school === hardcore. If someone got to maintain a code mess from developers bringing-their-20th-century-skills-to-the-21st-century who wrote javascript code sans a framework, you can't blame the new developer who knows where they live


Worser yet, those abstraction leakers put down new technology and blatantly claim that old approaches are more efficient and new technology are inferior

Friday, May 9, 2014

Preventing float overflow on endless runner type of game

If the character is moving against the world, instead of the world moving against the player also known as treadmill-type mechanism, there's a likely chance that the player's location could overflow the float's limitation.


Here's a way to deal with that problem:

using UnityEngine;
using System.Collections;

public class CameraRunnerScript : MonoBehaviour {

    public Transform player;

    // Update is called once per frame
    void Update () 
    {
        MoveCamera ();

        float currentCameraX = this.transform.position.x;

        // this prevents overflowing the float, reset the camera
        if (currentCameraX > 100) 
        {
            // reset the player position
            this.player.transform.position = new Vector3(0, player.position.y, 0);


            MoveCamera ();      


            // make all spawned object follow the camera's new position
            var grounds = GameObject.FindGameObjectsWithTag("Ground");
            foreach (var item in grounds) 
            {
                var delta = item.transform.position.x - currentCameraX;
                item.transform.position = new Vector3(this.transform.position.x + delta, item.transform.position.y, 0);
            }


        }
    }


    // move the camera based on player's position
    void MoveCamera ()
    {
        this.transform.position = new Vector3 (this.player.position.x + 6, 0, -10);
    }


}

Thursday, May 1, 2014

Things that are convenient when your RDBMS has first class boolean support

Other RDBMSes could embed boolean expression anywhere:

select exists(select * from person) as has_record;

select 
  person_id in (1,6,8) as one_of_the_chosen_ones,
  person_id % 2 = 0 has_even_id,
  * 
from person;


You have to do this in SQL Server:
select 
  case when exists(select * from person) then 
    convert(bit, 1)
  else
    convert(bit, 0)
end as has_record;

select 
  case when person_id in (1,6,8) then
    convert(bit, 1)
  else
    convert(bit, 0)
  end as one_of_the_chosen_ones,
  case when person_id % 2 = 0 then 
    convert(bit, 1)
  else
    convert(bit, 0)
  end as has_even_id,
  * 
from person;