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 - Mortal

Pages: 1 2 [3] 4 5 ... 19
31
Graphics / Re: loadfromfile failing to load an image
« on: January 24, 2020, 07:24:05 pm »
"loadFromFile()" usually print an error message on console screen if it can't open the file. check it if there is a message. if not then make complete and minimal example that produce same error.

32
General / Re: Text
« on: January 15, 2020, 08:58:13 am »
you can achieve these condition states by introducing a boolean values in your game classes like "bool is_button_pressed;", "bool is_he_chose" ... etc;

and then let the classes that needs those boolean properties to access them. whether by a pointers to the classes or some kind of game patterns that lets the entities in a game reference each other.
 
it's an inefficient to delete/create text objects every time when the player pressed the button. better to not to draw the text and probably it needs a timer for how long text will be drawn.
however, i think your game won't has a performance issues. since, your game has a few game objects, no collision or physics involved.

in general, it's depend on your game design which class responsible about display the hint text and its life span.

33
General / Re: How to implement sprite group?
« on: January 10, 2020, 03:28:49 pm »
well, i have almost same error as you have it, i'm using visual studio 2015 [v140]-for widow 8.1.
i made test code to draw colorful circle shapes with "sf::CircleShape". to show the the error

i suspect it might be a bug with my compiler version. i'm using visual studio 2015 [v140] for window 8.1.

here my test code:
#include <SFML/Graphics.hpp>

int main()
{
        sf::RenderWindow window(sf::VideoMode(640, 480), "test!");

        std::vector<std::reference_wrapper<const sf::Drawable>> shapes_wrapper;

        sf::CircleShape shape(32);
        shape.setFillColor(sf::Color::Cyan);
        shapes_wrapper.push_back(shape);

        std::vector<sf::CircleShape> shapes;
        for (int i = 0; i < 2; i++) {
                shapes.push_back(sf::CircleShape(32));
                if (i == 0) {
                        shapes.back().setFillColor(sf::Color::Blue);
                        shapes.back().setPosition(window.getView().getCenter() / 4.0f);
                }
                else {
                        shapes.back().setFillColor(sf::Color::Magenta);
                        shapes.back().setPosition(window.getView().getCenter() / 2.0f);
                }
#if 0 // ugly error, it should accept it. <-- probably it's a bug
                shapes_wrapper.push_back(shapes.back());
#endif
        }

        sf::CircleShape test_shape(32);
        test_shape.setFillColor(sf::Color::Green);
        test_shape.setPosition(window.getView().getCenter() - window.getView().getCenter() / 4.0f);
        shapes_wrapper.push_back(test_shape);

        sf::CircleShape center_shape(32);
        center_shape.setFillColor(sf::Color::Yellow);
        center_shape.setPosition(window.getView().getCenter());
        shapes_wrapper.push_back(center_shape);

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

                window.clear(sf::Color::White);
                for (const auto& shape : shapes)
                        window.draw(shape);
                for (const auto& shape : shapes_wrapper)
                        window.draw(shape);
                window.display();
        }

        return 0;
}


EDIT: it looks the std::vector of sf::CircleShape objects cause the problem, i replaced it with std::list and it works. also, i have test it with sf::CircleShape pointers ad it works as expected.
std::list<sf::CircleShape> shapes;

or with smart pointer
std::vector<std::unique_ptr<sf::CircleShape>> shapes;

both worked fine in my code.

EDIT 2:
alright, according to https://en.cppreference.com/w/cpp/container/vector/push_back

Quote
If the new size() is greater than capacity() then all iterators and references (including the past-the-end iterator) are invalidated. Otherwise only the past-the-end iterator is invalidated.

that means we have at least to use reserve() the vector to guarantee that no reallocation will happen by the subsequent of push_back()

fix: in my code it needs to add this:
std::vector<sf::CircleShape> shapes;
shapes.reserve(2);
while in yours it needs to add this:
std::vector<Box> boxes;
boxes.reserve(10);

34
General / Re: Sprite Pointer?
« on: January 09, 2020, 11:19:06 pm »
i agree with Rosme about reading a c++ book. pointers and references are most important features in c++ language. if you had difficulties to grasp these concepts then you may consider to switch to other programming language that don't use low level features like java or c#.

to solve the compiler warning in you code, just assign the memory address of your main sprite to the pointer sprite by using the address-of "operator(&)" like this:

Selected_Piece = &Piece_1;

and you can use the pointer by dereference it. if you were needed it, with "operator(*)", like this:

window.draw(*Selected_Piece );

35
SFML projects / Re: Intel 8080 Emulator-Space Invaders
« on: January 06, 2020, 09:51:34 am »
hello fallahn  :)

i'm so glad that you like it, i really appreciated.

i can't thank you enough for the tutorial, it really helpful. i get it where the problem is, according to the tutorial, it appears i have mapped the mirrored RAM location at wrong address location. i have fixed that and the bug seems has gone away  :D

36
SFML projects / Intel 8080 Emulator-Space Invaders
« on: January 03, 2020, 06:42:50 pm »
i have managed to make simple a `Intel 8080` 8-bit microprocessor emulator for Space Invaders. however, there is good news and bad news.

the good news is, the sound is working fine with emulator unlike my previous Space Invaders clone https://en.sfml-dev.org/forums/index.php?topic=26821.0
which is still can't get it to working correctly.

the bad news emulator has a bug for some reasons the Space Invaders game crushed when the startup game demo run longer. honestly i don't know what actually cause it, is it a multi-threading issues or memory-corruption, i have no idea.

the cpu runs fine i have tested it with COM test-files.

EDIT: bug is fixed, now the emulator's working fine.

here a Demo of Space Invaders game:



37
Graphics / Re: White rectangle issue
« on: December 27, 2019, 05:58:20 am »
hi

it looks you passing textures container by value to player class constructor, this will make a new copy of passing objects. use reference or pointer to fix it like `Player(const std::vector<sf::Texture>& texturas)`

btw, since all textures have same file names except of its numbers, you can use `std::to_string()` with a for-loop.

std::vector<sf::Texture> texturas(5);
for (int i = 0; i < texturas.size(); i++) {
        texturas[i].loadFromFile("Idle (" + std::to_string(i+1) + ").png");
}

38
SFML projects / Space Invaders Clone
« on: December 26, 2019, 12:57:22 pm »
hello everybody

i just made simple Space Invaders clone that's mimic the original game as possible as i could. it uses the original ROM data of-course to achieve same game experience as playing the original except for cpu cycle time which's not effect the game-play itself but it effects the sound. the game currently has no sound. i'm working to solve this issue hopefully it does't take much time.

the game is not an emulator as what it seems to look like. it is different code made it with SFML/OpenGL.


Demo:




 

39
yeah, that's what i suspected too, the erase to left character is a different input entity. now it's clear.

unfortunately, i haven't worked on any mobile platforms yet. soon i'm gonna delve in it.

sorry i can't help much on this issue.

40
General / Re: Getting intersection direction/side.
« on: December 17, 2019, 06:09:36 pm »
you most welcome  :)

41
my laptop support arabic alphabet. i tried to generate your error but no avail every things looks work fine from SFML side.

just to clarify things:
does this "erase to left character" means "BackSpace" on the keyboard?

i made minimal example by using `'\b'` and `'\r'` which is working fine as i said before. other wise you have to write your own minimal example which's cause the issue to let the others to test your code and solve the problem.

#include <SFML/Window.hpp>

int main()
{
        sf::Window window({ 640 ,480 }, "test arabic alphabet");

        std::wstring arabic_str;

        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                        else if (event.type == sf::Event::TextEntered)
                        {
                                if (event.text.unicode == '\b')  // press backspace
                                {
                                        if (!arabic_str.empty())
                                                arabic_str.pop_back();
                                }
                                else if (event.text.unicode == '\r') // press enter/return
                                {
                                        if (!arabic_str.empty())
                                                arabic_str.pop_back();
                                }
                                else {
                                        arabic_str += event.text.unicode;
                                }
                        }
                }

                window.setTitle(arabic_str);
                window.display();
        }
}

42
General / Re: Getting intersection direction/side.
« on: December 15, 2019, 10:54:05 pm »
you should use sf::Sprite::getGlobalbounds() instead of the local to test for intersects.
you may try manifold for detecting the collision from every directions up/down or left/right, here an excellent tutorial in this topic with examples:

http://trederia.blogspot.com/2016/02/2d-physics-101-pong.html

43
Graphics / Re: Displaced bounding box of Node
« on: December 15, 2019, 10:42:43 pm »
i think you need to pass window to the `sf::Mouse::getPosition(window)` to get the relative mouse position to your app window.

44
SFML projects / Re: Screenshot Thread
« on: December 14, 2019, 03:16:54 pm »
Hi  :)

It's me again, still working on my opengl framework. It is a little bit getting mature to be as a regular game engine.

I’m currently studying/working on 3D primitive shapes and collision detection and learning the basics of 3D game physics.

I have made a demo showing what i have been implemented.It is again space invaders. Lol
It's my favourite arcade game and easy game to make.

I was concerned about performance and i had to have to test my opengl framework to its limit. It looks working fine. Even i haven’t done any kind of advanced optimization like multithreading or using SSE instructions or any thing similar.

here a 2.5D Space Invaders demo runs on regular and hell-bullets modes

Regular mode


Hell Bullets mode


45
General / Re: Help with basic fragment-shadered full-screen sprite
« on: February 12, 2019, 06:25:58 pm »
hi

no need to use sprite and texture to draw fragment shader. just use sf::RectangleShape to get fullscreen to draw on it. also, no need to provide the vertex shader. like so:

#include <SFML/Graphics.hpp>


#define GLSL120(src) "#version 120 core\n" #src

static const char* frag = GLSL120(

uniform float time;
uniform vec2 resolution;

float h(float i) {
        return fract(pow(3., sqrt(i / 2.)));
}

void main(void) {

        vec2 p = gl_FragCoord.xy*2. - resolution;

        float a = floor(degrees(4. + atan(p.y, p.x))*2.) / 4.;

        float d = pow(2., -10.*fract(0.1*time*(h(a + .5)*-.1 - .1) - h(a)*1000.));

        if (abs(length(p) - d*length(resolution)) < d*35.) {
                gl_FragColor = vec4(d*(h(a + .5)*3.));
        }
        else {
                gl_FragColor = vec4(0.);
        }
}

);

int main()
{
        sf::RenderWindow window({ 800, 600 }, "SFML Shader Example");
        window.setMouseCursorVisible(false);

        sf::RectangleShape fullscreen({ 800, 600 });
        sf::Shader shader;
        if (!shader.loadFromMemory(frag, sf::Shader::Fragment))
                return -1;

        shader.setUniform("resolution", sf::Vector2f({ 800, 600 }));

        sf::Clock clock;
        while (window.isOpen()) {
                sf::Event event;
                while (window.pollEvent(event)) {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }

                shader.setUniform("time", clock.getElapsedTime().asSeconds());

                window.clear();
                window.draw(fullscreen, &shader);
                window.display();
        }
}

Pages: 1 2 [3] 4 5 ... 19
anything