Friday, August 17, 2012

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);
}
}

No comments:

Post a Comment