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

Pages: [1]
1
Graphics / Re: Drawing thousands of sprites
« on: March 05, 2011, 06:37:52 am »
Quote from: "SuperV1234"
Anyway, I have to draw a 64x64 tile-based map, where every Tile has a List<Entity> (linked list, or std::vector for C++ users), and every Entity has a Sprite object.


std::vector is a dynamic array.
std::list is a doubly linked list.

Somebody correct me if I'm wrong.

2
Graphics / Can I reload an image to an sf::Image object?
« on: February 27, 2011, 11:10:53 am »
LoadFromFile is costly, and should never be done more than once for the same image (unless it's no longer in memory), and certainly not every frame.

What you want is to do is pass around references/pointers of sf::Image objects. Create an image manager class to check for duplicates of filenames and the such, and return a reference based on that to use with sf::Sprite. And if it's the first time you're asking for an sf::Image of that filename, return a reference to a new one. Therefore, things are reused automatically and quickly, they're still in memory after all, until you choose to get rid of them. A std::map makes things like this pretty easy to implement I think.

As well, you can optimize things further by just prerendering your tiles into one big sf::Image using sf::RenderImage (in 2.0) before the game loop, because drawing one object every frame is more efficient than drawing several hundred/thousand.
http://www.sfml-dev.org/documentation/2.0/classsf_1_1RenderImage.htm

3
Window / Is this related to the ATI Bug? Crash on exit for Intel
« on: February 22, 2011, 06:22:36 pm »
I have a tester that has an odd problem that sounds quite reminiscent of the ATI bug. None of these bugs will happen to literally anyone else. This is on SFML 2.0. It is statically linked, and the problems do not show up on ATI cards, but it still sounds like the same thing.

This tester is using an Intel 4-series integrated GPU.
- Upon leaving the main, the program will crash. Same error as the ATI bug's.
- Going into fullscreen will also crash.

- The problem might be compounded by the fact that he's using a dual monitor setup on an old GPU/driver
- There are misc rendering issues on one of his screens, (I have a certain sf::Text object that will be rendered only on every other frame for example. This bug does not exist for anyone else)
- If he has the game on the other screen, it will render properly, but display at half the FPS. Turning off VSync will not fix this, either.
- The above 3 might be unavoidable, since I know that SFML does not support multiple screens.

These types of problems seem difficult to work with since it's only one person with a very specific setup that's getting them. I thought I might as well ask anyways.

4
Graphics / [Solved] Scrolling a view is creating odd sprite shaking
« on: February 21, 2011, 11:03:28 am »
Not really, but it is irrelevant to this situation. This problem does not change with just one of them on.

5
Graphics / [Solved] Scrolling a view is creating odd sprite shaking
« on: February 21, 2011, 06:41:07 am »
Okay, this is as minimal as I could get a complete example which demonstrates my issue. I'm probably missing something obvious, or I have some logic error somewhere.

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

int main(int argc, char **argv) {
    int x=0,xs=0,ys=0,speed=25;
    float left=0.0,right=0.0;

    sf::RenderWindow App(sf::VideoMode(1280, 720, 32), "Game");
    App.SetFramerateLimit(60);
    App.UseVerticalSync(true);
    sf::Image back;
    back.LoadFromFile("sky.png");
    sf::Sprite bg(back);
    bg.Resize(1280,720);
    sf::Image image;
    image.LoadFromFile("character.png");
    sf::Sprite sprite(image);
    sf::View BGCamera(sf::FloatRect(0,0,1280,720));
    sf::View Camera(sf::FloatRect(-200,-500,1280,720));

    while (App.IsOpened()) {
        sf::Event event;
        while (App.GetEvent(event)) {
            if (event.Type == sf::Event::Closed)
                App.Close();
        }

        const sf::Input& inputs = App.GetInput();
        if (inputs.IsKeyDown(sf::Key::Right))       xs=speed;
        else if (inputs.IsKeyDown(sf::Key::Left))   xs=-speed;
        else                                        xs=0;
        sprite.Move(xs,ys);
        if (xs) sprite.FlipX(xs<0);

        left=Camera.GetCenter().x-(Camera.GetSize().x/3);
        right=Camera.GetCenter().x+(Camera.GetSize().x/3);
        x=sprite.GetPosition().x;
        if (!xs)     xs=speed;
        if (xs<0)    xs=-xs;
        if (x<left)  Camera.Move(-xs,0);
        if (x>right) Camera.Move(xs,0);

        App.Clear();
        App.SetView(BGCamera);
        App.Draw(bg);
        App.SetView(Camera);
        App.Draw(sprite);
        App.Display();
    }
    return 0;
}


Fixed. The camera and the sprite must move at 100% the same speed. Marking this topic as solved, hopefully I can get this fixed in my game as well.

6
Graphics / With an Image, open new Form
« on: February 08, 2011, 11:48:56 pm »
Code: [Select]
sf::Vector2f mouse (App.ConvertCoords
         (App.GetInput().GetMouseX(),
          App.GetInput().GetMouseY()));


To get the mouse.

Get the Rect of your button, and then look up the sf::Rect "Contains()" function in the documentation.

7
Graphics / Collision detection between two sprites in different classes
« on: February 08, 2011, 11:00:23 pm »
First, I suggest the Bullet being a different class. And that the Player/Centipede/Bullet be derived from the same base class.

Then, I believe the easiest way in SFML to do bounding box detection is just to use Rect.Intersects(Rect). Then you can always get the Rect from one of your player classes like this:

Code: [Select]
FloatRect Entity::myRect() {
   return sprite.GetPosition().x,
          sprite.GetPosition().y,
          sprite.GetSize().x,
          sprite.GetSize().y,
}

bool Entity::Collides(Entity *e) {
   return myRect().Intersects(e->myRect());
}


If the Bullet, Centipede, and Player are all derived from Entity, it becomes really easy to track this. And you can always the hitboxes smaller/larger that way by just overloading the myRect() function.

For "deleting" the Centipede, I would flag it as dead, or set an "alive" bool to false. Then something in my Game class (or whoever has the instance) would come collect and destroy it. This way if you want to have multiple centipedes later on, you can just iterate through them in that function and see if any of them are dead yet.

Code: [Select]
void Game::Collision() {
   if (centipede) {
      if (p1->Collides(centipede))
         centipede->Kill(); // Kill() would just set alive to false.
   }
}

void Game::Recycle() {
   if (centipede) {
      if (!centipede->Alive()) { // Alive() would just be a getter of the alive status.
         delete centipede;
         centipede=NULL;
      }
   }
}


If you wanted something to happen first while the Centipede is dying, you could store a separate bool for alive and dead possibly. And then when alive is false and dead is false, do an animation, or fade it out, etc... until a certain point. Then when it reaches that certain point, set dead to true. Then the game can check if that dead bool is true, and come to delete it.

Then, you just stop calling the Centipede's functions when the centipede pointer is NULL, to prevent any dereferencing errors. For example:

Code: [Select]
if (centipede) centipede->Draw();

As the previous poster said, it's a pretty broad question, and there's several ways to go about it. If I had a little more information, I could probably help you out more.

8
Graphics / [Solved] Scrolling a view is creating odd sprite shaking
« on: January 29, 2011, 09:42:05 pm »
This is a problem that I've been trying to come back to for the last couple of weeks, and haven't figured it out. I'm trying to smoothly scroll the view when the player moves past a certain boundary in the view. The problem is, when the view and the sprite are both moving at once, it causes the sprite (yet not anything in the background in the same view) to "shake". It looks like it's teleporting slightly. When moving the sprite without moving the view, it does not shake, when moving the view and not the sprite, it does not shake. I am using SFML 2.0.

Code: [Select]
   // Fixed!
    // Set up boundaries based on the "Camera" View  
    double rightbound=Camera.GetCenter().x+(Camera.GetSize().x/3);
    double leftbound=Camera.GetCenter().x-(Camera.GetSize().x/3);
    double lowerbound=-Camera.GetCenter().y-(Camera.GetSize().y/3);
    double upperbound=-Camera.GetCenter().y+(Camera.GetSize().y/3);

    double camerax=x-oldX, cameray=y-oldY;

    if (!camerax)   camerax=15;
    if (!cameray)   cameray=15;
    if (camerax<0)  camerax=-camerax;
    if (cameray<0)  cameray=-cameray;
   
    // The x and y coords here are the ones my entity uses, which it passed directly to its sprite.
    if (y>upperbound)   Camera.Move(0,-cameray);
    if (y<lowerbound)   Camera.Move(0,cameray);
    if (x>rightbound)   Camera.Move(camerax,0);
    if (x<leftbound)    Camera.Move(-camerax,0);

    oldX=x; oldY=y;

Pages: [1]
anything