animations
This commit is contained in:
parent
721ff8f42f
commit
e4dda0861c
8 changed files with 161 additions and 4 deletions
45
examples/HelloAnimation/main.cpp
Normal file
45
examples/HelloAnimation/main.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import Crafter.Event;
|
||||
import Crafter.Graphics;
|
||||
import std;
|
||||
using namespace Crafter;
|
||||
|
||||
int main() {
|
||||
WindowWayland window(1280, 720, "Hello Input!");
|
||||
|
||||
UiElementBufferBuffer* element = new UiElementBufferBuffer(
|
||||
2, //bufferWidth: the width of this elements pixel buffer
|
||||
1, //bufferHeight: the height of this elements pixel buffer
|
||||
FractionalToMapped(0.5), //anchorX: relative position where this elements x anchor (top-left) is placed to its parent x anchor
|
||||
FractionalToMapped(0.5), //anchorY: relative position where this elements y anchor (top-left) is placed to its parent y anchor
|
||||
FractionalToMapped(0.5), //relativeSizeX: the relative x size this element should be scaled to compared to its parent
|
||||
FractionalToMapped(0.5), //relativeSizeY: the relative y size this element should be scaled to compared to its parent
|
||||
FractionalToMapped(0.5), //anchorOffsetX: the amount this element's anchor should be offset from the top left corner (0.5 to in the middle)
|
||||
FractionalToMapped(0.5), //anchorOffsetY: the amount this element's anchor should be offset from the top left corner (0.5 to place it in the middle)
|
||||
0, //z: this elements Z position
|
||||
false //ignoreScaling: wether this element ignores the scaling of the window, if true its size will be scaled according to the window scale
|
||||
);
|
||||
|
||||
window.elements.push_back(element);
|
||||
|
||||
element->UpdatePosition(window);
|
||||
|
||||
Animation<std::tuple<std::int_fast32_t>> anim({
|
||||
{std::chrono::seconds(0), FractionalToMapped(-0.5)},
|
||||
{std::chrono::seconds(5), FractionalToMapped(1.5)}
|
||||
});
|
||||
|
||||
anim.Start(std::chrono::high_resolution_clock::now());
|
||||
|
||||
EventListener<FrameTime> updateListener(&window.onUpdate, [&](FrameTime time){
|
||||
std::tuple<std::int_fast32_t> value = anim.Play(time.now);
|
||||
element->transform.anchorX = std::get<0>(value);
|
||||
element->UpdatePosition(window);
|
||||
if(anim.currentFrame == anim.keyframes.size()-1) {
|
||||
anim.Start(time.now);
|
||||
}
|
||||
});
|
||||
|
||||
element->buffer = {{255, 0, 0 ,255}, {0, 255, 0 ,255}};
|
||||
window.StartUpdate();
|
||||
window.StartSync();
|
||||
}
|
||||
15
examples/HelloAnimation/project.json
Normal file
15
examples/HelloAnimation/project.json
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"name": "crafter-graphics",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "executable",
|
||||
"implementations": ["main"],
|
||||
"dependencies": [
|
||||
{
|
||||
"path":"../../project.json",
|
||||
"configuration":"lib-wayland"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue