Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Creating a 2D world in QT with bitmap
Forum Updated to NodeBB v4.3 + New Features

Creating a 2D world in QT with bitmap

Scheduled Pinned Locked Moved Game Development
6 Posts 2 Posters 4.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    browser90
    wrote on last edited by
    #1

    Hi guys,

    I'm searching for how to put two images above eachother and then make a part of the foreground image transparant so that it is like a hole and you see the second image? Because I want to use this for my worms game if you shoot in the map that a part of the map is gone like a hole and you see the background image?

    I already got this:

    @#include <QApplication>
    #include <QGraphicsEllipseItem>
    #include <QGraphicsScene>
    #include <QGraphicsView>

    int main( int argc, char **argv )
    {
    QApplication app(argc, argv);

    QGraphicsScene scene;
    scene.setSceneRect( -100.0, -100.0, 500.0, 500.0 );

    QGraphicsView view( &scene );
    view.setRenderHints( QPainter::Antialiasing );
    QGraphicsPixmapItem item(QPixmap(":/images/test1.jpg"));
    QGraphicsPixmapItem item2(QPixmap(":/images/test2.jpg"));

    scene.addItem(&item2);
    scene.addItem(&item);

    view.show();

    return app.exec();
    }@

    But I don't know how to make a part of it transparant? I tried with alpha and setmask but doens't work.

    Kind regards,

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jake007
      wrote on last edited by
      #2

      Hi!

      Consider displaying the image ( crater, demolished area or whatever you like), over background.
      It'll be much easier, and for processor I would say that also much faster.
      Also, if you wrap your code in @, it will syntax highlight it.

      Regards,
      Jake


      Code is poetry

      1 Reply Last reply
      0
      • B Offline
        B Offline
        browser90
        wrote on last edited by
        #3

        Oké, but then we still need to show only the thing that is destroyed so we still need to see what is destroyed? That isn't possible if we just paste it over the other image because then if there is something small there is always a big crater over the whole place...

        But thanks for your help already :-)

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jake007
          wrote on last edited by
          #4

          If you are having interactions with entities, than it isn't background any more.
          Have background completely separate ( for example sky).
          Land and other entities are then shown over background.
          Than, if you need to delete part of land, you only calculate are the effect, create new image, and copy that part of background onto the newly created image. Again, you show the image over land.
          You can also use polygons, for better collision detection etc.

          Or you could also resize the image of an crater and show it again :).


          Code is poetry

          1 Reply Last reply
          0
          • B Offline
            B Offline
            browser90
            wrote on last edited by
            #5

            Yes I get that, but my only point is how can I remove something of the first image, I don't find functions to do that in Qgraphics

            1 Reply Last reply
            0
            • J Offline
              J Offline
              Jake007
              wrote on last edited by
              #6

              That's because, you can't just create a "hole" in the image.

              But, you can write your own function, which will change any necessary pixel at that image to transparent.


              Code is poetry

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved