gpt4 book ai didi

c++ - 我怎样才能让我的代码显示这个输出我是新的 sfml 和代码块

转载 作者:行者123 更新时间:2023-12-03 07:15:13 26 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Loading a texture in sfml

(4 个回答)


1年前关闭。




我怎样才能让我的代码显示这个输出我是新的 smfl 和 codeblock
我不知道如何调用 Sprite 并让它移动
我和我的 friend 在这个大流行期间很困惑在线类(class)很难:(

this is the output

#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>


class Game
{
public:Game();
void run();

private:
void processEvents();
void update(sf::Time deltaTime);
void render();
void handlePlayerInput(sf::Keyboard::Key key,bool isPressed);

private:
sf::RenderWindow mWindow;
sf::CircleShape mPlayer;
bool mIsMovingUp = false;
bool mIsMovingDown = false;
bool mIsMovingLeft = false;
bool mIsMovingRight = false;
float PlayerSpeed = 10.0f;
sf::Time TimePerFrame = sf::seconds(1.f / 60.f);
};

Game::Game()
: mWindow(sf::VideoMode(640, 480), "SFML Application")
, mPlayer()
{
mPlayer.setRadius(40.f);
mPlayer.setPosition(100.f, 100.f);
mPlayer.setFillColor(sf::Color::Cyan);
}
这是完整代码的链接 https://pastebin.com/g4v2DzgF
请发送帮助 S.O.S

最佳答案

首先,您需要加载纹理。

sf::Texture texture;
texture.loadFromFile("ship.png");
不要删除纹理。它必须存在才能使用它。
接下来,您需要使用纹理创建一个 Sprite 。
sf::Sprite sprite(texture);
记住要绘制 Sprite ,这与绘制玩家的方式相同。
您也可以像移动播放器一样移动 Sprite 。
查看文档以获取更多详细信息:
  • 绘制 Sprite :
  • https://www.sfml-dev.org/tutorials/2.5/graphics-sprite.php
  • https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Texture.php
  • https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Sprite.php

  • 移动可变形物:
  • https://www.sfml-dev.org/tutorials/2.5/graphics-transform.php
  • https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Transformable.php

  • 关于c++ - 我怎样才能让我的代码显示这个输出我是新的 sfml 和代码块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64740886/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com