LoginSignup
1
0

More than 5 years have passed since last update.

Siv3DのSceneManagerとScalableWindowを併用した時の暗転バグ対処

Last updated at Posted at 2018-02-27

※OpenSiv3Dではちゃんと直っています

画面サイズを可変にするScalableWindowと、シーンマネージャーを併用した際に暗転範囲がおかしくなる現象への対処法。

原因

SceneManager内でWindow::BaseClientRect()を使っているためです。
Window::ClientRect()を使うようフェードイン・アウトをオーバーライドすれば暗転がかかる範囲が直ります。
毎回オーバーライドするのは微妙なので、先にオーバーライドだけしたクラスを作ってそれを継承させていくとよいです。

以下のコードは開発者のRyoさんに直接伝授して頂いたSiv3D純正なコードなので安心してお使い頂けます。

MySceneBase.hpp
#pragma once

#include <Siv3D.hpp>
#include <HamFramework.hpp>

struct Common
{

};

using Myapp = SceneManager < String, Common >;

class MySceneBase : public SceneManager < String, Common >::Scene
{
public:
    virtual void main() {};
    virtual void draw() const {};
    virtual void init() {};

    void drawFadeIn(double t) const override
    {
        draw();
        s3d::Transformer2D tr(Graphics2D::GetTransform().inverse());
        s3d::Window::ClientRect().draw(ColorF(0.0).setAlpha(1.0 - t));
    }
    void drawFadeOut(double t) const override
    {
        draw();
        s3d::Transformer2D tr(Graphics2D::GetTransform().inverse());
        s3d::Window::ClientRect().draw(ColorF(0.0).setAlpha(t));
    }

    virtual ~MySceneBase() = default;
};

使うときの例(普通に継承するだけですが)

Main.cpp
#include <Siv3D.hpp>
#include <HamFramework.hpp>
#include "MySceneBase.hpp"

class Game : public MySceneBase
{
    void update()override
    {
        if (Input::KeyZ.clicked)
        {
            changeScene(L"title");
        }
    }

    void draw() const override
    {
        Rect(-100, -100, 1000, 1000).draw(Palette::Yellow);
    }
};

class Title : public MySceneBase
{
    void update()override
    {
        if (Input::KeyZ.clicked)
        {
            changeScene(L"game");
        }
    }

    void draw() const override
    {
        Rect(-100, -100, 1000, 1000).draw(Palette::Blue);
    }
};

void Main()
{
    Myapp app;
    app.add<Title>(L"title");
    app.add<Game>(L"game");

    ScalableWindow::Setup();

    while (System::Update())
    {
        {
            auto trans = ScalableWindow::CreateTransformer();

            app.updateAndDraw();
        }
        ScalableWindow::DrawBlackBars();
    }
}

これで画面を小さくしても大丈夫

余談

このバグについての報告も見つけたので一応紹介
http://siv3d.jp/bbs/patio.cgi?read=170
対処するという回答もされていますが、恐らくSiv3Dのバージョンがここで打ち止めになり、開発がOpenSiv3Dに移行してしまったため放置されているのだと思います。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0