标签: sfml

在SFML中从tileset加载一个tile

所以我得到了这样的tileset:Tileset

如何在SFML中仅加载一个tile?

c++ tile sfml

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

简单的彩色3D棱镜

我开始学习OpenGL,我正在使用它与SFML 2.1来获取窗口,加载图像等.但我有一个简单的棱镜问题.面部是透明的,看起来很糟糕:/我正在看教程,但我不知道我的代码有什么问题......你能帮助我吗?我读到这是Z-Buffering的问题.怎么解决?

这是我的代码:

#include <iostream>
#include <stdio.h>
#include <cmath>
#include <SFML/OpenGL.hpp>
#include <SFML/Graphics.hpp>

using namespace std;

void drawCube (float x, float y, float z, float width, float height, GLuint Texture);

int main()
{
    // Window
    sf::RenderWindow window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, sf::ContextSettings(32));

    // Camera
    GLdouble eyex = 0;
    GLdouble eyey = 0;
    GLdouble eyez = 2575;

    GLuint Texture = 0;
    {
        sf::Image Image;
        if (!Image.loadFromFile("background.png"))
            return EXIT_FAILURE;
        glGenTextures(1, &Texture);
        glBindTexture(GL_TEXTURE_2D, Texture);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Image.getSize().x, Image.getSize().y, 0, GL_RGBA, GL_UNSIGNED_BYTE, Image.getPixelsPtr());
        glTexParameteri(GL_TEXTURE_2D, …
Run Code Online (Sandbox Code Playgroud)

c++ opengl 3d sfml opengl-1.x

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

如何使用C++和SFML创建自己的类

在学习了C++的基础知识后,我目前开始使用SFML.我已经了解了Arrays,References以及它之前的所有内容,但却努力掌握使用类的概念.

在SFML中,我创建了一个简单的sprite移动程序,但是,我想将这些信息移到一个类中(假设它将被称为"Player").我搞砸了很多但是我无法让它发挥作用.

我已经尝试在类中创建一个函数来检查播放器输入,但我无法访问我在main中创建的精灵.我想将与玩家相关的所有内容移到Player类中,但需要一些建议.

这样做的正确方法是什么?(请不要说回去学习课程,这是我想要了解的地方!)

main.cpp中

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

int main()
{
    //character position
    enum Direction{ Down, Left, Right, Up };
    sf::Vector2i source(1, Down);

    //window
    sf::RenderWindow window(sf::VideoMode(1200, 700), "Testing");
    window.setKeyRepeatEnabled(false);

    //player character
    sf::Texture pTexture;
    sf::Sprite pSprite;
    if(!pTexture.loadFromFile("image/playerSprite.png"))
        std::cout << "Texture Error" << std::endl;
    pSprite.setTexture(pTexture);
    pSprite.setScale(1.5f, 1.5f);

    //game loop
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) //move up
        {

            source.y = Up;
            pSprite.move(0, -0.2);

            //animation
            source.x++;
            if(source.x * 32 …
Run Code Online (Sandbox Code Playgroud)

c++ oop refactoring class sfml

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

OpenGL 与 gl3w

我正在尝试学习 OpenGL。我使用 SFML 窗口模块作为上下文,使用 gl3w 作为我的加载库。我经常使用 SFML,因此按照本教程为 OpenGL 设置它不是问题:http : //www.sfml-dev.org/tutorials/2.0/window-opengl.php

我可以毫无问题地运行示例代码。我链接了 OpenGL 所需的一切(opengl32.lib 和 glu32.lib + sfml*.lib)。

然后我按照这个答案得到 gl3w :How to set up gl3w on Windows? .

但是现在如果我尝试运行这段代码,它主要是来自 SFML 的示例代码

#include <SFML/gl3w.h>
#include <SFML/Window.hpp>

static const GLfloat red[] = { 1.0f, 0.f, 0.f, 1.f };

int main()
{
    // create the window
    sf::Window window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, sf::ContextSettings(32));
    window.setVerticalSyncEnabled(true);
    gl3wInit(); //ignore return value for now

    // load resources, initialize the OpenGL states, ...
    // run the main …
Run Code Online (Sandbox Code Playgroud)

c++ opengl linker sfml

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

在sfml c ++中向后翻转youtr字符精灵

我有一些小问题让我的精灵角色翻转.基本上我有一个可以走到右边的角色..我正在寻找它以使它看起来像是向左走.我目前还没有找到一个可行的解决方案,所以任何帮助都会令人惊叹!

我在用:

SFML 2.1 C++

我试过了:

  guy.setTextureRect(sf::IntRect(guy.getGlobalBounds().width, 0, guy.getGlobalBounds.width * -1, guy.getGlobalBounds.height));
Run Code Online (Sandbox Code Playgroud)

c++ window sprite sfml

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

c ++ sfml数组[5]的for循环window.display中的字符串,只显示1,3,5行

如果我无法正确解释自己,你将不得不原谅我,我正在尝试使用c ++ sfml字符串数组创建一个高分表.我试着用它们分别绘制它们window.draw(array[1],array[2]等等.

但是如果我将数组放在for循环中并使用int变量,它只会绘制数组1,3和5.

for(cnt = 0;cnt <5;cnt++)
    {
        thiswindow.draw(topscores[cnt]);
        thiswindow.draw(topnames[cnt]);
        thiswindow.display();
    }
Run Code Online (Sandbox Code Playgroud)

c++ arrays sfml

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

无限数量的子弹

我尝试使用SFML.NET在C#上制作射击游戏,但是我无法想象如何能够射击超过1个子弹,因为现在我只有一个子弹类的空对象,当玩家按下Space时key此对象获取新子弹的链接.

所以,我有Bullet-class,null-object

public static Bullet bullet = null;
Run Code Online (Sandbox Code Playgroud)

和条件

if (Keyboard.IsKeyPressed(Keyboard.Key.Space)) 
{
   if(bullet == null) 
    bullet = new Bullet(t, p.rect.Left, p.rect.Top, p.reverse);
}
Run Code Online (Sandbox Code Playgroud)

子弹到达墙壁或敌人的子弹对象等于null.问题是能够在子弹到达墙壁或敌人之前射击更多的子弹(并消失).我认为这不是为每个可能的小母鸡制作空对象的好方法,因为那时我们的子弹数量有限.

.net c# sfml sfml.net

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

不改变值的功能

我正在编写一个2D引擎,这是我的问题:每个瓷砖都有一个'纹理'数字(0:网格,1:草等......)当我尝试改变这样的数字时:

maps[currentMapID].getLayerArray()[l].getTileArray()[t].setTexture(currentSelectedTexture);
Run Code Online (Sandbox Code Playgroud)

(l,t等......来自'for'循环.)

什么都没有改变,数字仍然是0.

这是代码.setTexture(..):

void tile::setTexture(int t)
{
    numTexture = t;
}
Run Code Online (Sandbox Code Playgroud)

创建测试图块时,此代码完全正常工作.

我的代码(类)的结构是:

Map > layer > tile. => all of them in a class wich handle graphics.
Run Code Online (Sandbox Code Playgroud)

我怀疑问题来自于此(同样map class,每个人都有一个std::vector<layer>类似的功能 - >):

std::vector<tile> layer::getTileArray()
{
    return tiles;
}
Run Code Online (Sandbox Code Playgroud)

它会std::vector<layer>从我的班级或副本中归还给我吗?如果它是副本,它可以解释图块的纹理编号保持不变.

如果它是副本,我怎么能改变tile.numTexture另一个类?指针?参考文献?(我真的不明白这个)

我也检查了currentSelectedTexture,那里没有问题.

c++ sfml

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

使用SFML制作自定义类型

我最近选择使用SFML,并且我决定使用它作为一种学习经验.我已经定义了一个类Ball,其中draw使用SFML绘制一个RectangleShape.当我尝试使用该window.draw()功能将此自定义类型绘制到屏幕时,我得到错误,因为Ball不是sf::Drawable.我很感激这方面的帮助,是SFML的新手.

c++ sfml

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

Xcode,SFML错误代码:库未加载

我试图通过链接到SFML库来启动一个基本的C ++项目。我已将SFML库解压缩到/ Users / mulperi / cpplib / sfml文件夹,并将其添加到Include Search PathLibrary Search Path中

我的代码很简单,我遵循了有关YouTube的教程(还尝试了其他现成的代码):

#include <iostream>
#include <SFML/Graphics.hpp>
int main() {
    sf::RenderWindow window(sf::VideoMode(640, 480), "First SML Window");
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            switch (event.type) {
                case sf::Event::Closed:
                    window.close();
                    break;
                default:
                    break;
            }
        }
        window.clear();
        window.display();
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

构建成功,因此路径应该正确。我没有窗口,但是我有这些输出:

线程1:

dyld`__abort_with_payload:
    0x10003b1e0 <+0>:  movl   $0x2000209, %eax          ; imm = 0x2000209 
    0x10003b1e5 <+5>:  movq   %rcx, %r10
    0x10003b1e8 <+8>:  syscall 
->  0x10003b1ea <+10>: jae …
Run Code Online (Sandbox Code Playgroud)

c++ macos xcode dyld sfml

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

标签 统计

sfml ×10

c++ ×9

opengl ×2

.net ×1

3d ×1

arrays ×1

c# ×1

class ×1

dyld ×1

linker ×1

macos ×1

oop ×1

opengl-1.x ×1

refactoring ×1

sfml.net ×1

sprite ×1

tile ×1

window ×1

xcode ×1