Friday, August 17, 2012

Emo Framework Tutorial Example 2 - Click and Drag a Certain sprite

Here's another example of moving a certain sprite that you desired. Imagine like a moving a chess piece in a board.


 class PickupSprite {  
      sprite1 = null;  
      sprite2 = null;  
      selected_sprite = null;  
      function onload() {  
           print("Loading PickupSprit");       
      }  
      function onDispose() {  
           print("Exiting...");  
      }  
      function onMotionEvent(mevent) {  
           local id = mevent.getPointerId();  
           local action = mevent.getAction();  
           if(!sprite1) {  
                sprite1 = emo.Sprite("private.png");  
                sprite1.load();  
           }   
           if (!sprite2 ) {  
                sprite2 = emo.Sprite("captain.png");  
                sprite2.load();  
                sprite2.move(100,100);  
           }  
           if(action == MOTION_EVENT_ACTION_DOWN || action == MOTION_EVENT_ACTION_POINTER_DOWN ) {  
                print("Clicked at x: " + mevent.getX() + " y: " + mevent.getY());  
                if(sprite1.contains(mevent.getX(), mevent.getY()) ) {  
                     selected_sprite = sprite1;  
                }  
                else if(sprite2.contains(mevent.getX(), mevent.getY()) ) {  
                     selected_sprite = sprite2;  
                }  
           } else if(action == MOTION_EVENT_ACTION_UP ||   
                          action == MOTION_EVENT_ACTION_POINTER_UP ||  
           action == MOTION_EVENT_ACTION_CANCEL ||  
           action == MOTION_EVENT_ACTION_OUTSIDE ) {  
       print("Released");  
                selected_sprite = null;       
           }  
           if ( selected_sprite ) {  
                print(selected_sprite.getName());  
                handleTouch(selected_sprite, mevent);  
           }  
      }  
      function handleTouch(sprite, mevent) {  
     local action = mevent.getAction();  
     if (action == MOTION_EVENT_ACTION_DOWN || action == MOTION_EVENT_ACTION_POINTER_DOWN) {  
     } else if (action == MOTION_EVENT_ACTION_MOVE) {  
       sprite.moveCenter(mevent.getX(), mevent.getY());  
     } else if (action == MOTION_EVENT_ACTION_UP ||  
           action == MOTION_EVENT_ACTION_CANCEL ||  
           action == MOTION_EVENT_ACTION_OUTSIDE ||  
           action == MOTION_EVENT_ACTION_POINTER_UP) {  
     }  
      }  
 }  

Emo Framework Tutorial - Load And Drag a Sprite

I've been recently exploring this new framework. It lacks sources so im posting it here.

This example would allow you to load a sprite, and move it base on your mouse/touchdrag


 class LoadDragSprite {  
      sprite = null;  
      function onLoad() {  
      }  
      function onDispose() {  
      }  
   function handleTouch(sprite, mevent) {  
     local action = mevent.getAction();  
     if (action == MOTION_EVENT_ACTION_DOWN || action == MOTION_EVENT_ACTION_POINTER_DOWN) {  
       sprite.moveCenter(mevent.getX(), mevent.getY());  
     } else if (action == MOTION_EVENT_ACTION_MOVE) {  
       sprite.moveCenter(mevent.getX(), mevent.getY());  
     } else if (action == MOTION_EVENT_ACTION_UP ||  
           action == MOTION_EVENT_ACTION_CANCEL ||  
           action == MOTION_EVENT_ACTION_OUTSIDE ||  
           action == MOTION_EVENT_ACTION_POINTER_UP) {  
     }  
   }  
   function onMotionEvent(mevent) {  
     // pointer id is a unique id of the pointer.  
     local id = mevent.getPointerId();  
     local action = mevent.getAction();  
     if (!sprite ) {  
                sprite = emo.Sprite("graphics.png");  
                sprite.load();  
     }  
     handleTouch(sprite, mevent);  
   }  
 }  

Sunday, February 12, 2012

Yii thoughts

I was researching on some good PHP MVC framework. I run into yii. I heard pretty good things about yii unfortunately, i don't like the conventions and how it tries to call yii libraries. I just think it's not clean and an eyesore to the code. I still admire it's full functionality plus the widgets.. It's still so powerful!

CodeIgniter Crud Generator

I really think that CodeIgniter Needs a Crud Generator like Yii/Cakephp. Developers like me is so poor on webdesign, and I intend to focus more on the backend. I make sure that the models are good/smooth and ok before I proceed to fixing the views.

I just tried, grocery crud. Spent an hour and found out it doesn't support (yet) postgres.