Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - bakar12344

Pages: [1]
1
SFML projects / Lagging in My Game
« on: April 09, 2020, 01:17:21 am »
Hello ,  i am a newbie, i have a college assignment to make a game. But i have problem , sometimes my game have a lagging. this is some sources code inside main looping (i suspect this is happening because sf::Time.
sorry my english is very bad:)

Quote
for(int i = 0; i < batas; i++)
        {
            if(k == i)
            {
                //Random jenis buah
                randBuah = rand() % 3 + 1;
                buah.Buah("image/pir.png","image/apel.png", "image/jambu.png", randBuah);
                //Random posisi spawn buah
                x = rand() % 1100 + 1;
                buah.Set(x, y);
                hitBuah.Set(x+30, y+50);
                k++;
            }
            else continue;
        }
//Draw buah dan memberikan kecepatan
        detik = sf::seconds(1);
        for(int i = 0; i < batas; i ++)
        {
            //memberikan delay setiap perulangan
            //detik = sf::seconds(1);
            if(waktu.getElapsedTime() >= detik && i >= batas-1)
            {
                hitBuah.Draw(window);
                buah.Draw(window);
                batas++;
                waktu.restart();
            }
            else {
                hitBuah.Draw(window);
                buah.Draw(window);
                buah.Move(0, 0.5);
                hitBuah.Move(0, 0.5);
            }
        }

2
General / How to make spawn delay to my object
« on: March 12, 2020, 12:26:55 am »
Hello, I am a newbie.
I have problem with my program,i make a program to spawn some object falling from top with random area, but my object spawn together,can you teach me how to make my object spawn with some delay. Thanks

My Code

#include <SFML/Graphics.hpp>
#include <stdlib.h>
#include <time.h>

using namespace sf;

int main()
{
    srand(time(0));
    RenderWindow window(VideoMode(1200,600),"PROJECT");

    int k = 0;
    float x[50],xb[50],y[50];

    for(int i = 0; i < 50; i++){
        x[i] = 0;
        y[i] = 0;
    }

    Texture buah1,latar;
    buah1.loadFromFile("pir.png");
    latar.loadFromFile("background.png");

    Sprite pir(buah1),background(latar);

    while(window.isOpen()){
        Event tutup;
        while(window.pollEvent(tutup)){
            if(tutup.type == Event::Closed)
                window.close();
        }
        window.clear(Color::White);

        window.draw(background);

        for(int i = 0; i < 50; i++){
            if(k == i){
                xb[i] = rand() % 1200;
                x[i] = xb[i];
                k++;
                break;
            }
            else continue;
            }

        for(int i = 0; i < 50; i++){
            pir.setScale(0.2, 0.2);
            pir.setPosition(x[i],y[i]);
            y[i] += 0.5;
            window.draw(pir);
        }
        window.display();
    }
    return EXIT_SUCCESS;
}
 

Pages: [1]
anything