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) {
}
}
}
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.
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
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);
}
}
Subscribe to:
Posts (Atom)