Now have a simple camera system that I can configure in json for different motion effects.

This commit is contained in:
Zed A. Shaw 2025-11-03 00:25:48 -05:00
parent 8345097e10
commit 5b57fb2033
11 changed files with 173 additions and 128 deletions

View file

@ -12,10 +12,10 @@ namespace boss {
$combat_ui(true),
$arena(scene),
$view_texture({BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT}),
$view_sprite($view_texture.getTexture()),
$zoom_anim(animation::load("test_zoom"))
$view_sprite($view_texture.getTexture())
{
$view_sprite.setPosition({BOSS_VIEW_X, BOSS_VIEW_Y});
$camera.style("bounce");
}
void UI::init() {
@ -45,7 +45,7 @@ namespace boss {
$actions.render(window);
$combat_ui.render(window);
if($zoom_anim.playing) {
if($camera.playing()) {
zoom("player2");
}
@ -80,12 +80,12 @@ namespace boss {
if(cell_name == "") {
sf::View zoom{{BOSS_VIEW_WIDTH/2,BOSS_VIEW_HEIGHT/2}, {BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT}};
$view_texture.setView(zoom);
} else if($zoom_anim.playing) {
} else if($camera.playing()) {
auto& cell = $arena.$ui.cell_for(cell_name);
sf::Vector2f pos{float(cell.x/2), float(cell.y/2)};
sf::View zoom;
$zoom_anim.apply(zoom, pos, {BOSS_VIEW_WIDTH/2, BOSS_VIEW_HEIGHT/2});
$view_texture.setView(zoom);
$camera.resize({BOSS_VIEW_WIDTH/2, BOSS_VIEW_HEIGHT/2});
$camera.move($view_texture,
{float(cell.x/2), float(cell.y/2)});
}
$view_sprite.setPosition({BOSS_VIEW_X, BOSS_VIEW_Y});