Can I use sprites or images as buttons?

I'm trying to make a kind of simple "yes/no text adventure" game for class. Can I utilize sprites as a button? I know how to make sprites interact with each other, but I can't figure out bow to make mouse input interact with the sprite.

The only other thing I could think of to do is just make the buttons images instead of sprites, but even then I'm not sure how to get the mouse to interact with the buttons.

I'm also using an online IDE that my professor made, so unfortunately I can only tell you the libraries I'm using.

#include <iostream>

#include "graphic.h"

#include "sprite.h"

#include "mouse.h"

#include "keyboard.h"

using namespace std;

If there's a better way to do this without using either sprites or images please let me know!

Here's my code: I'm just trying to get the "No" button to cout something when pushed.

#include <iostream>

#include "graphics.h"

#include "sprite.h"

#include "mouse.h"

#include "keyboard.h"

using namespace std;

Sprite createNo() {

Sprite no;

no.width = 50;

no.height = 50;

no.centerY = 0;

no.centerX = 0;

no.url = "https://www.iwanttomakean.app/media/cckristo/optionNo.jpg";

return no;

}

int main() {

Sprite no = createNo();

while (!isKeyDown("Escape")) {

no.draw();

update();

clear();

if (isMouseDown(0)){

cout << "mouse is down";

}

}

return 0;

}

submitted by /u/AYF_Amph
[link] [comments]

* This article was originally published here

Related Posts

Leave a Reply

Your email address will not be published.