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

Pages: [1]
General / Re: Can't even do the simplest thing right
« on: January 18, 2013, 06:22:27 pm »
You shouldn't call Display() every shape iteration otherwise you'll only see one shape at a time. Also you then don't want the sleep call with in the loop, otherwise it will sleep every time one shape is drawn instead of between the frames.

PS. BONUS:  just for testing and learning, is there any simple way to make them bounce off on the border of the screen?
Depends on your definition of 'simple'. ;)
SFML doesn't provide sprite.bounce() or whatever, so you'll have to do the collision checking and response on your own. Depending on what you want to achieve, this can get quite complex or be very simple.

hmm as it is now it just stacks the figures, so it doesn really clear the display in every iteration, plus the for loop does 1500 shapes and then goes back to the main loop so that would't be an issue.

I'm going to look into the sleep thing, thanks!

I'm leaving the bounce thing for another moment

I don't have much time to test and analyze this through yet I will give you some tips.

If you are going to use iostream don't use cstdio(stdio.h) and the same applies backwards, that's mixing C and C++ which isn't exactly a good practice. Also use the c-libraryname, instead of libraryname.h in order to mantain the consistency in your programming.

Check that the random values are being assigned correctly, sometimes some freaky errors can be avoided by checking the data of the values you are assigning.

Make a minimal example in order to realize what is it that makes them not move, the amount of code for a trivial problem such isn't good. Make it as small as possible while reproducing the problem.

SFML 2.0 is far better than 1.6 as it fixes many bugs and has a better graphics API with many new features for both high and low level rendering. 1.6 may be "stable", but it is actually deprecated in many aspects and hasn't been touched in two years.

Read this: http://en.sfml-dev.org/forums/index.php?topic=5559.0 and this: en.sfml-dev.org/forums/index.php?topic=10306

The recommendations of eXpl0it3r apply very well and may solve the problem though it may (unlikely) be somewhere else.

I'm following a series of tutorials that use 1.6 so I'm not quite ready to jump to 2.0 yet..

General / Can't even do the simplest thing right
« on: January 18, 2013, 05:51:11 pm »
#include <SFML/Graphics.hpp>
#include <stdio.h>
#include <iostream>
#include <time.h>

using namespace std;

void inicializar_semilla() {
int aleatorio_mod255() {
int n = 0;
n = (rand() % 254 + 1);
return n;

double aleatorio_mod10() {
double n = 0.0;
n = (drand48() * (10.0-1.0));
return n;

double aleatorio_mod1000() {
double n = 0.0;
n = (drand48() * (1000.0-500.0));
return n;

double aleatorio_mod100() {
double n = 0.0;
n = (drand48() * (100.0-50.0));
return n;

int main () {
int colorR = 0, colorG = 0, colorB = 0;
double x1 = 0.0;
double x2 = 0.0;
double y1 = 0.0;
double y2 = 0.0;
double m1 = 0.0;
double m2 = 0.0;
int i;
sf::RenderWindow Screen (sf::VideoMode (800, 600, 32), "Title");
sf::Shape Rect [1500];
float x;
float y;

while(Screen.IsOpened ()){

    sf::Event Evento;;
    while(Screen.GetEvent (Evento)){
        if (Evento.Type == sf::Event::Closed || Evento.Key.Code == sf::Key::Escape)

    }//End of Evento loop

    for (i = 0; i < 1500; i++){
        x1 = aleatorio_mod1000();
        x2 = aleatorio_mod1000();
        y1 = aleatorio_mod1000();
        y2 = aleatorio_mod1000();
        colorR = aleatorio_mod255();
        colorG = aleatorio_mod255();
        colorB = aleatorio_mod255();
        printf("%d, %f", colorR,x1);
        Rect[i] = sf::Shape::Rectangle (x1,x2,y1,y2, sf::Color(colorR,colorG,colorB));
        m1 = aleatorio_mod100();
        m2 = aleatorio_mod100();
        Screen.Draw (Rect[i]);
        Rect[i].Move (m1, m2);

} //End of Game Loop

return 0;

I was messing with shapes and I got a sqare moving, thats nice, so I said to myself: What about I create multiple rectangles at once and make them move on the screen.

I used two random functions to set the size, color and speed of said rectangles random, I wanted tons of colors on my screen.

Okay, I advanced a bit, now it displays random rectangular shapes of various colors BUT they don't move at all, once the next shape is loading the rest stops moving I think thats the problem. Is there any way for me to make them move permanently?

Thank you

PS. BONUS:  just for testing and learning, is there any simple way to make them bounce off on the border of the screen?

Pages: [1]