小编Rec*_*ito的帖子

C++是否具有HTML <canvas> </ canvas>和JS fillRect的等价物?

有没有办法在C++中绘制数字,就像在HTML中结合JavaScript一样?通过绘制数字,我的意思是<canvas></canvas>HTML和[canvas name].fillRect功能的功能.

我正在尝试用C++制作2D砖块

c++ 2d 2d-games

2
推荐指数
1
解决办法
1864
查看次数

使字符在屏幕中移动时,window.clear() 如何在 SFML 中工作?

嗯,我一直在看一个关于如何使用 SFML 的教程。我目前正在学习在屏幕上移动精灵。添加 window.clear() 之前;每次我移动精灵时,它都会像一条轨迹一样离开,就像精灵是刷子一样。然后教程人说在 window.draw(player); 之前添加 window.clear

你能解释一下这背后的逻辑吗?就像,窗口被清除,然后绘制角色并显示它。这是代码:

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

int main() {
    sf::RenderWindow window(sf::VideoMode(1920, 1080), "Screen", sf::Style::Default);
    sf::RectangleShape player(sf::Vector2f(100.0f, 100.0f));
    player.setFillColor(sf::Color::Green);

    //run as long as the window is open
    while (window.isOpen()) {
        // check all the window's events that were triggered since the last iteration of the loop
        sf::Event evnt;
        while (window.pollEvent(evnt)) {
            switch (evnt.type) {
            case sf::Event::Closed:
                window.close();
                break;
            case sf::Event::Resized:
                printf("New window width: %i New window height: %i\n", evnt.size.width, evnt.size.height);
                break;
            case sf::Event::TextEntered:
                if …
Run Code Online (Sandbox Code Playgroud)

c++ logic sfml

1
推荐指数
1
解决办法
1304
查看次数

标签 统计

c++ ×2

2d ×1

2d-games ×1

logic ×1

sfml ×1