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

Pages: 1 2 3 [4] 5 6
46
General / Multiple inheritance
« on: January 18, 2012, 06:17:08 pm »
I'm implementing my own collision sistem with collision shapes, and I'm using sf::ConvexShape, sf::CircleShape and own clases for this.

I use a vector to hold all shapes and then check for collision. So I use a base class type, CollisionShape.

Code: [Select]
std::vector<CollisionShape*> m_shapeList;

I have my own shape classes like Box, Circle, Polygon... and some of them inherit sf::ConvexShape and use its methods. I have something like this.



Note that there are more shapes inheriting CollisionShape class.

I have a problem when I do this:

Code: [Select]
Polygon* polygon = new Polygon();
addShape(polygon);
...
void addShape( CollisionShape* shape )
{
    shape->SetOutlineColor(...);     <----------------------
    m_shapeList.push_back(shape);
}


I can't use sf::ConvexShape 's methods, so I could change CollisionShape pointer to sf::ConvexShape pointer. But I have more shapes inheriting other classes (a.s.a sf::CircleShape).

Any OOP idea for solving this? A better design?

Hope someone can understand my problem,
Thanks!

47
General discussions / The new time API
« on: January 14, 2012, 02:24:30 am »
It seems nice for me.
This way SFML still keeps satisfaying all of its users  :D

48
Graphics / [SFML 2] Gradient rectangle
« on: January 13, 2012, 06:56:19 pm »
Okay I understand.
Thanks Laurent.

49
Graphics / [SFML 2] Gradient rectangle
« on: January 13, 2012, 12:48:27 am »
Is any way for drawing a gradient rectangle of 2 colors using ConvexShape, like I used to do in SFML2(old api)?

Something like this, working against points with colors:
Code: [Select]

sf::Shape m_back;
m_back.AddPoint(0, 0, sf::Color(50, 250, 200));
m_back.AddPoint(800, 0, sf::Color(50, 250, 200));
m_back.AddPoint(800, 600, sf::Color(25, 80, 40));
m_back.AddPoint(0, 600, sf::Color(25, 80, 40));


Thanks.

50
Graphics / Buttons moving with view
« on: January 05, 2012, 11:50:41 am »
Draw the button on the default view:
Code: [Select]

...
set your view
draw player
reset default view //  window.SetView(window.GetDefaultView())  //
draw button
...

51
Network / how does a client find a computer running the server
« on: January 04, 2012, 06:31:26 pm »
You need to know the IP address of the computer running the server.

Otherwise, you can store the address in a MySQL data base when someone runs a server, and then get those addresses with the client. Use php + mysql and the HTTP client from SFML.

Cheers.

52
Graphics / Scrolling Text (Final Fantasy Like)
« on: December 28, 2011, 06:35:11 pm »
Something like that was answered here http://sfml-dev.org/forum/viewtopic.php?t=6490
 :D

53
General / Multiple Events Running At the Same Time?
« on: December 15, 2011, 07:38:43 pm »
Using a while loop with PollEvent function (GetEvent in SFML1.6) lets you to manage all events in one frame. Don't use if statements for this.

Cheers

54
General / typewriter effect like RPG games
« on: December 14, 2011, 05:47:26 pm »
Oh, i'm so sorry, I should have adviced about the SFML version.
 :wink:

55
General / typewriter effect like RPG games
« on: December 14, 2011, 04:48:02 pm »
You could use a Clock to control the time between characters, and use a variable to get a substring of the string.

You shouldn't use sleep functions, because they would pause the game every iteration.

Code: [Select]
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <sstream>

int main()
{
    // Create the main window
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");

    // Create a graphical text to display
    sf::Font font;
    if (!font.LoadFromFile("arial.ttf"))
        return EXIT_FAILURE;
    sf::Text text("", font, 50);

    sf::Clock timer;
    unsigned int character = 0;
    std::string str = "This is an example of typewriter \neffect, it uses one clock to control \nthe time. Check out the code, it's \neasy to understand!";

    // Start the game loop
    while (window.IsOpened())
    {
        // Process events
        sf::Event event;
        while (window.PollEvent(event))
        {
            // Close window : exit
            if (event.Type == sf::Event::Closed || (event.Type == sf::Event::KeyPressed && event.Key.Code == sf::Keyboard::Escape))
            window.Close();
        }

        if (timer.GetElapsedTime() > 50 && character < dialog.size())
        {
            timer.Reset();
            character++;
            text.SetString( sf::String( str.substr(0, character) ) );
        }

        // Clear screen
        window.Clear();

        // Draw the string
        window.Draw(text);

        // Update the window
        window.Display();
    }

    return EXIT_SUCCESS;
}


It's very easy to understand.

Cheers.

56
Graphics / Help in Animation.
« on: December 13, 2011, 08:38:18 am »
If you hold down de key, i'll be generating KeyPressed events and calling Sprite.Play() function every time. So you can disable key repeat with EnableKeyRepeat(bool) function.

57
Graphics / CreateMaskFromColor
« on: December 13, 2011, 12:19:10 am »
You could get the texture using GetTexture function and then get an Image using CopyToImage function of that texture. Finally, use CreateMaskFromColor function.

It may be a slow operation.

Cheers.

58
General / SFML Collision Resolution
« on: December 09, 2011, 11:52:02 am »
If you know the initial velocity and mass of the balls, the conservation of momentun tells us that the momentum of the system before the collision must be the same as the momentum after the collision:
Code: [Select]
momentum: p
mass: m
velocity: v

p = m * v

Conservation of Momentum:
Code: [Select]
m1 * v1 + m2 * u2 = m1 * v1' + m2 * u2'
For calculating velocities after collision, these formulas are used:
Code: [Select]
v1' = (2 * m2 * v2 + v1 * (m1 - m2)) / (m1 + m2)
v2' = (2 * m1 * v1 - v2 * (m1 - m2)) / (m1 + m2)

And you can get the final velocities only knowing the mass of the objects and their initial velocities.

Cheers

59
General / collsion detection
« on: December 03, 2011, 01:00:17 pm »
Quote from: "DigiByte"

@ julen26: So the function you showed as pseudo code, is for collision detection anywhere, at any side? I guess the arguments newY and newX are the places where to check if there is collision on newY and newX?

Not exactly, if you remove newX and newY arguments, that code should check a simple boundingBox collision.

But those arguments move the boundingBox of the first object to a certain position relative to the object, so you cant check collision 1 pixel left, 10 pixels right ...


60
General / collsion detection
« on: December 02, 2011, 09:23:03 pm »
You could use BoundingBox collisions, but doing a little change in boxes to check if there is collision left, right, up, down.

A pseudo-code for checking if ther is free place at a given point relative to the object:

Code: [Select]
bool collision(object, other, newX, newY)
{
    if (object.x + newX > other.x + other.width)
        return false;
    if (object.x + object.width + newX < other.x)
        return false;
    if (object.y + newY > other.y + other.height)
        return false;
    if (object.y + object.height + newY < other.y)
        return false;

    return true;
}


Checking left collision:
Code: [Select]
if ( !collision(object, other, -1, 0) )
    moveLeft();

And same for right, up and down...

Cheers

Pages: 1 2 3 [4] 5 6
anything