Hi,
I want to let sprite to respond to touch events, so I subclassed the sprite class, here is my implementation,
[code]#ifndef Urho3D__SpriteButton
#define Urho3D__SpriteButton
#include “Sprite.h”
using namespace Urho3D;
class SpriteButton : public Sprite
{
OBJECT(SpriteButton);
// BASEOBJECT(SpriteButton);
public:
SpriteButton(Context *context);
virtual ~SpriteButton();
static void RegisterObject(Context* context);
/// React to mouse click begin.
virtual void OnClickBegin(const IntVector2& position, const IntVector2& screenPosition, int button, int buttons, int qualifiers, Cursor* cursor);
/// React to mouse click end.
virtual void OnClickEnd(const IntVector2& position, const IntVector2& screenPosition, int button, int buttons, int qualifiers, Cursor* cursor, UIElement* beginElement);
/// React to mouse drag motion.
virtual void OnDragMove(const IntVector2& position, const IntVector2& screenPosition, int buttons, int qualifiers, Cursor* cursor);
};
#endif /* defined(Urho3D__SpriteButton) */[/code]
[code]#include “Precompiled.h”
#include “Context.h”
#include “ResourceCache.h”
#include “Texture2D.h”
#include “SpriteButton.h”
namespace Urho3D
{
extern const char* UI_CATEGORY;
}
SpriteButton::SpriteButton(Context *context)
: Sprite(context)
{
}
SpriteButton::~SpriteButton()
{
}
void SpriteButton::RegisterObject(Context* context)
{
context->RegisterFactory(UI_CATEGORY);
COPY_BASE_ATTRIBUTES(SpriteButton, Sprite);
UPDATE_ATTRIBUTE_DEFAULT_VALUE(SpriteButton, "Is Enabled", true);
// UPDATE_ATTRIBUTE_DEFAULT_VALUE(Button, “Focus Mode”, FM_FOCUSABLE);
}
void SpriteButton::OnClickBegin(const IntVector2& position, const IntVector2& screenPosition, int button, int buttons, int qualifiers, Cursor* cursor)
{
}
void SpriteButton::OnClickEnd(const IntVector2& position, const IntVector2& screenPosition, int button, int buttons, int qualifiers, Cursor* cursor, UIElement* beginElement)
{
}
void SpriteButton::OnDragMove(const IntVector2& position, const IntVector2& screenPosition, int buttons, int qualifiers, Cursor* cursor)
{
}[/code]
But, it not work. Did the sprite can respond to touch events? and how can I do it?
Thank you very much!