我正在使用SFML库在C ++上进行伪绘画(在C ++中接近零体验)。 我做了一个单独的功能来编辑图像,“工具0”基本上是一支铅笔。当我尝试将此args传递给我的函数时,它不起作用,但是当我执行同样的操作而不将其传递给drawOnImage函数时,它将正常工作。 我在显示的代码中剪掉了多余的部分
我尝试将鼠标位置的x和y作为单独的args传递(不使用Vector),但这无济于事
void drawOnImage(sf::Color color, int tool, sf::Texture canvas, sf::Image image, sf::Vector2i vector);
int main()
{
sf::Image image;
image.create(windowWidth, windowHeight, sf::Color::White);
sf::Texture canvas;
sf::Color currentColor = sf::Color::Black; // Color
int currentTool = 0; // instrument that is currently chosen
sf::Sprite sprite;
int mousedown = 0;
mainWindow.setFramerateLimit(60);
canvas.loadFromImage(image);
sprite.setTexture(canvas);
while (mainWindow.isOpen())
{
canvas.loadFromImage(image);
sf::Event event;
while (mainWindow.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
mainWindow.close();
else if ((event.type == sf::Event::MouseMoved) && (mousedown == 1))
{
canvas.update(mainWindow);
drawOnImage(currentColor, currentTool, canvas, image, sf::Mouse::getPosition(mainWindow));
}
else if (event.type == sf::Event::MouseButtonPressed)
{
mousedown = 1;
drawOnImage(currentColor, currentTool, canvas, image, sf::Mouse::getPosition(mainWindow));
//image.setPixel(sf::Mouse::getPosition(mainWindow).x, //IT WORKS but drawOnImage does not
sf::Mouse::getPosition(mainWindow).y, sf::Color::Black);
}
void drawOnImage(sf::Color color, int tool, sf::Texture canvas, sf::Image image,sf::Vector2i vector) {
if (tool == 0) {
image.setPixel(vector.x,vector.y, sf::Color::Black);
}
}
我敢肯定,我只是不了解某些c ++功能,例如传递对象的地址而不是名称,但我自己无法弄清楚