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.


Topics - Stauricus

Pages: 1 [2]
16
General / designing seamless worlds?
« on: September 21, 2013, 08:53:01 pm »
hello everybody
today i'd like to ask how would you design a tiled seamless world?

i tried to create one, and so far it's working good.
i have a sf::View, and a slighter greater sf::Rect around it, so I only draw tiles that are inside the Rect before updating the View and drawing it to the screen. something like this:

void GameMap::drawMap(GameSys &game_sys_p){
    //get the drawArea (sf::Rect around the View)
    int mapX_min = game_sys_p.getDrawArea().left;
    int mapX_max = game_sys_p.getDrawArea().width;
    int mapY_min = game_sys_p.getDrawArea().top;
    int mapY_max = game_sys_p.getDrawArea().height;

    //search tiles inside the drawArea
    for (int mapX=mapX_min/32; mapX<mapX_max/32; mapX++){
        for (int mapY=mapY_min/32; mapY<mapY_max/32; mapY++){
            if (tiles_map[mapX][mapY].getType() == 1){
                sprite1.setPosition(mapX*32, mapY*32);
                game_sys_p.getGameWindow().draw(sprite1);
            }
        }
    }
}

but now i have to put characters in it. and this is a problem, since characters can walk almost on every pixel, and the tiles are drawn only at every 32 pixels. the only way i see to solve it is cycling trough ALL game characters and objects and checking it's positions every frame, to know if they are or not inside the drawArea. but i guess that it will make things too much slow. so i'm here asking the pros for any tips on that: how to optimize a seamless world?  :P
thanks in advance!

17
Graphics / how to subtract colors?
« on: September 15, 2013, 02:04:11 am »
hello everybody
i have an opaque object, and now i want to lessen it's alpha value.
there is no overload to the '-' operator, and trying something like
text_box.setFillColor(text_box.getFillColor() + sf::Color(0, 0, 0, -15));
doesn't work.

so, how can i subtract 15 from the alpha value? this is in a loop, to be subtracted by this amount many times.
thanks in advance!

18
Window / moving sf::View from sf::RenderWindow
« on: September 09, 2013, 06:54:46 pm »
hello everybody
is there any way to directly move the view copy stored in the window object?
sf::RenderWindow window;
sf::View view;

view.setCenter(sf::Vector2f(100, 0));
view.setSize(400, 400);
window.create(sf::VideoMode(400,400), "Test!");
window.setView(view);
 

according to this topic, i should call this line every time the view is changed, but it made my cpu usage go from less than 1% to about 48%
window.setView(view);

so, isn't there any way to directly move the view copy stored in the window object?
thanks in advance!

19
Window / emptying sf::Window from events?
« on: September 07, 2013, 10:57:23 pm »
hello everybody
i made a simple intro screen, where it fades in a image, waits for the user to press anything in the keyboard, and then fades out the image.

the problem is that if the user press any button before the image is completely showing in the screen,  it fades in and out directly (instead of fading in and only then accepting user inputs)

this is the code (game_sys_p is an object that holds the sf::Window; and intro1_spr is a sf::Sprite)

sf::Event intro_events;
    int fade_factor = 1;
    for (int i=0; i>=0; i+=5*fade_factor){
        game_sys_p.getGameWindow().clear(sf::Color(0, 0, 0, i));
        intro1_spr.setColor(sf::Color(255, 255, 255, i));
        game_sys_p.getGameWindow().draw(intro1_spr);
        game_sys_p.getGameWindow().display();
        if (i>=255){
            fade_factor=-1;
                while (intro_events.type != sf::Event::KeyPressed){
                    game_sys_p.getGameWindow().pollEvent(intro_events);
                    sf::sleep(sf::milliseconds(10));
                }
        }
        sf::sleep(sf::milliseconds(20));
    }

i believe this happens because sf::Event is queueing the events (and i think it is expected). is there any way to prevent that?
or any change i could do to the code to fix it? any suggestion is welcome :)

thanks in advance!

20
Audio / sf::music causes a crash?
« on: August 31, 2012, 12:23:31 am »
hello
i'm having a strange issue when i try to create a music object.
the program runs fine, but at the finish, windows give a error message "test.exe stopped working"

all i have to do is write sf::Music test! a minimal example that reproduces the problem:

#include "SFML/Audio.hpp"
int main(){
    sf::Music test;
    return 0;
}

in a complete example, the music DOES play, and the program runs fine. for some reason, it occurs after the 'return 0' from main().

in the console output:
process returned 255 (0xFF)

is this normal? the program runs fine, so i don't know...
i'm running on windows 7 SP1, SFML 2.0rc, Code::Blocks 10.05

thanks in advance!

21
Graphics / SFML2 blinking screen
« on: August 27, 2012, 03:54:27 pm »
hello everybody!
first, i'd like to thank the creator and contributors of this library. it's really easy to understand, and is helping me a lot in learning on how to make a game.

then, i have a question that i believe it's simple.
i have loaded a texture and then created a sprite. this sprite is a tile, so i draw it a lot of times in the screen. then i update the screen, and draw all over again.
the problem is that the screen blinks every time it draws the tiles. (it blinks all tiles at once, and not one at time)
i don't know what could be wrong.

this is how i made it:

#include "head.h"
int main(){
    sf::RenderWindow window(sf::VideoMode (480, 480), "Jogo2");
    window.setFramerateLimit(60);
    Mapa mapa;
    mapa.criarMapa();
    for (int i = 0; i<100; i++){
        window.clear();
        mapa.desMapa(&window); //[b]see note below for this[/b]
        sf::sleep(sf::milliseconds(10));
        window.display();
    }
    system("pause");
    return 0;
}

note: the line mapa.desMapa(&window) draws the tiles on the screen. it does the following:
    window->draw(sChaoPedr); //draw the sprite
    sChaoPedr.setPosition(mapX*48, mapY*48); //set the sprite position
for each tile.

for some reason, it seems that window.display() clears the screen! after this comand, the screen turns black. i don't know why.

do i have to create one sprite for each tile?
if anyone thinks the error is somewhere else, please let me know, so i'll put the whole code.

i'm working on windows 7 SP1, SFML 2.0rc, Code::Blocks 10.05 (and the default mingw and gcc shipped with it).

thanks in advance :)

Pages: 1 [2]