调用Flappy Bird Clone函数时出现未解决的错误

问题描述 投票:0回答:1

我收到错误:

错误LNK2019无法解析的外部符号“ public:structDirectX :: SimpleMath :: Vector2 __thiscall Bird :: getScreenPos(void)“引用(?getScreenPos @ Bird @@ QAE?AUVector2 @ SimpleMath @ DirectX @@ XZ)在函数“ private:void __thiscall Game :: Render(void)”中(?Render @ Game @@ AAEXXZ)

当我运行代码时。我不知道问题是什么,我希望有人可以帮助我,这里是我要在其中调用方法的类的代码:

//
//Bird.h
//
#pragma once
class Bird
{
private:
    DirectX::SimpleMath::Vector2 screenPos;
    int yVelocity;

    const int gravity = 3;
public:
    Bird();
    ~Bird();

    void Flap();
    void Update();

    inline void Bird::setScreenPos(DirectX::SimpleMath::Vector2 newPos);
    inline DirectX::SimpleMath::Vector2 Bird::getScreenPos();
    inline void setX(float newX);
    inline void setY(float newY);
};

//
//Bird.cpp
//
#include "pch.h"
#include "Bird.h"

Bird::Bird()
{
    screenPos.y = 500;
    screenPos.x = 100;
    yVelocity = 0;
}

Bird::~Bird()
{
}

void Bird::Flap()
{
    yVelocity = 50;
}

void Bird::Update()
{
    yVelocity -= gravity;
    screenPos.y += yVelocity;
}


inline DirectX::SimpleMath::Vector2 Bird::getScreenPos()
{
    return screenPos;
}

inline void Bird::setX(float newX)
{
    screenPos.x = newX;
}

inline void Bird::setY(float newY)
{
    screenPos.y = newY;
}

inline void Bird::setScreenPos(DirectX::SimpleMath::Vector2 newPos)
{
    if (screenPos.y < 0)
        screenPos = newPos;
}

并且我初始化对象的代码在此块的底部:

//
// Game.h
//

#pragma once

#include "StepTimer.h"

#include "Bird.h"


// A basic game implementation that creates a D3D11 device and
// provides a game loop.
class Game
{
public:

    Game() noexcept;
    ~Game() = default;

    Game(Game&&) = default;
    Game& operator= (Game&&) = default;

    Game(Game const&) = delete;
    Game& operator= (Game const&) = delete;

    // Initialization and management
    void Initialize(HWND window, int width, int height);

    // Basic game loop
    void Tick();

    // Messages
    void OnActivated();
    void OnDeactivated();
    void OnSuspending();
    void OnResuming();
    void OnWindowSizeChanged(int width, int height);

    // Properties
    void GetDefaultSize( int& width, int& height ) const noexcept;

private:

    void Update(DX::StepTimer const& timer);
    void Render();

    void Clear();
    void Present();

    void CreateDevice();
    void CreateResources();

    void OnDeviceLost();

    // Device resources.
    HWND                                            m_window;
    int                                             m_outputWidth;
    int                                             m_outputHeight;

    D3D_FEATURE_LEVEL                               m_featureLevel;
    Microsoft::WRL::ComPtr<ID3D11Device1>           m_d3dDevice;
    Microsoft::WRL::ComPtr<ID3D11DeviceContext1>    m_d3dContext;

    Microsoft::WRL::ComPtr<IDXGISwapChain1>         m_swapChain;
    Microsoft::WRL::ComPtr<ID3D11RenderTargetView>  m_renderTargetView;
    Microsoft::WRL::ComPtr<ID3D11DepthStencilView>  m_depthStencilView;

    // Rendering loop timer.
    DX::StepTimer                                   m_timer;

    //texture
    Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_texture;

    std::unique_ptr<DirectX::SpriteBatch> m_spriteBatch;
    DirectX::SimpleMath::Vector2 m_origin;

    Bird* bird;
};

实际功能在Game.cpp中称为:

bird->setX(backBufferWidth / 2.f);

谢谢!

c++ directx flappy-bird-clone
1个回答
0
投票
inline DirectX::SimpleMath::Vector2 Bird::getScreenPos()
{
    return screenPos;
}
© www.soinside.com 2019 - 2024. All rights reserved.