Adding Event example
This commit is contained in:
parent
ec8eb971a5
commit
49f42e98f4
5 changed files with 70 additions and 1 deletions
|
|
@ -23,7 +23,8 @@ end
|
|||
assets = CopyDir(PathJoin(paths.build, paths.examples), "assets")
|
||||
|
||||
examples = BuildExamples(example_settings, {
|
||||
"text"
|
||||
"text",
|
||||
"events"
|
||||
}, assets)
|
||||
|
||||
PseudoTarget("examples", examples)
|
||||
|
|
|
|||
28
examples/events/EventsExample.cpp
Normal file
28
examples/events/EventsExample.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
|
||||
#include <Spectre/System/MessageHandler.h>
|
||||
#include <Spectre/System/Log.h>
|
||||
#include "EventsExample.h"
|
||||
|
||||
void EventsExample::init()
|
||||
{
|
||||
getMessageHandler()->registerListener(this);
|
||||
}
|
||||
|
||||
void EventsExample::onEvent(const sp::Event& event)
|
||||
{
|
||||
if (event.type == sp::Event::Key) {
|
||||
const char* name = event.key.getKeyName().c_str();
|
||||
const char* pressed = event.key.pressed ? "pressed" : "released";
|
||||
sp::Log::info("Key: %s %s", name, pressed);
|
||||
}
|
||||
}
|
||||
|
||||
void EventsExample::update(double dt)
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
void EventsExample::render()
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
22
examples/events/EventsExample.h
Normal file
22
examples/events/EventsExample.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
|
||||
#ifndef EVENTS_EXAMPLE_H
|
||||
#define EVENTS_EXAMPLE_H
|
||||
|
||||
#include <Spectre/Game.h>
|
||||
#include <Spectre/System/EventListener.h>
|
||||
|
||||
class EventsExample : public sp::Game, sp::EventListener
|
||||
{
|
||||
public :
|
||||
void onEvent(const sp::Event& event);
|
||||
|
||||
protected :
|
||||
|
||||
void init();
|
||||
|
||||
void update(double dt);
|
||||
|
||||
void render();
|
||||
};
|
||||
|
||||
#endif /* EVENTS_EXAMPLE_H */
|
||||
7
examples/events/bam.lua
Normal file
7
examples/events/bam.lua
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
local base = PathDir(ModuleFilename())
|
||||
|
||||
src ={
|
||||
base .. "/main.cpp",
|
||||
base .. "/EventsExample.cpp"
|
||||
}
|
||||
11
examples/events/main.cpp
Normal file
11
examples/events/main.cpp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
#include "EventsExample.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
EventsExample game;
|
||||
|
||||
game.run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue