Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Weird drawing bug :S  (Read 2195 times)

0 Members and 1 Guest are viewing this topic.

Haikarainen

  • Guest
Weird drawing bug :S
« on: July 06, 2011, 05:11:32 pm »
Hello fellas, I started doing a game just a few minutes ago, it will be a small game and I do it just to motivate myself by actually creating a finished product.

However, I noticed a weird bug!
I've created a grid(32x32, consisting of an image) that draws perfectly, but then I'm trying to draw points in each grid intersection(16x16, image) , it draws like its edges was stretched out to fit the previous grid image, whos sprite is the same as the pointsprite.

Here is the code that draws the stuff(myGame::Draw()):
Code: [Select]

this->wndHandle->Clear();

sf::Sprite drawer;

for(int x = 0; x < 800; x+=32){
for(int y = 0; y < 600; y+=32){
drawer.SetPosition(x, y);

drawer.SetImage(this->img_grid);
this->wndHandle->Draw(drawer);

drawer.SetImage(this->img_point);
drawer.SetPosition(x-8, y-8);
this->wndHandle->Draw(drawer);
}
}

this->wndHandle->Display();


Here is result picture, with pasted original images used for grid and point:


And here are links to the project source:

myGame.cpp: https://legacy.sfmluploads.org/index.php?page=view_code&id=44

myGame.hpp: https://legacy.sfmluploads.org/index.php?page=view_code&id=45

main.cpp: https://legacy.sfmluploads.org/index.php?page=view_code&id=46


Its just like the sprite forgets is has a new image, like it forgets its size so it just draws out the closest neighbour or something. Is this supposed to happen?  It works perfectly fine if i seperate the gridsprite and the pointsprite

JAssange

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Weird drawing bug :S
« Reply #1 on: July 06, 2011, 05:34:10 pm »
I believe you need to resize the sprite or it will keep the old one.

Haikarainen

  • Guest
Weird drawing bug :S
« Reply #2 on: July 06, 2011, 05:38:40 pm »
Quote from: "JAssange"
I believe you need to resize the sprite or it will keep the old one.


My first thought as well.

Resize(Image->GetWidth(), Image->GetHeight()) do resize the sprite, but maintains the error(its just smaller lol).  Tested this after both setimage() as well.

Scale(1,1) Does nothing, Scale(0.5, 0.5) screws it up even more.


This has to be a bug somewhere, something left unclean in the sfml-graphics package..

Using SFML2 btw!

EDIT: Fixed! After browsing the source of Sprite.cpp i noticed the SetImage takes more than 1 argument:
Code: [Select]
void Sprite::SetImage(const Image& image, bool adjustToNewSize)
Its pretty selfexplanatory, i set the second one to true and now it works :D Think this should be default tho!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Weird drawing bug :S
« Reply #3 on: July 06, 2011, 05:48:31 pm »
Quote from: "Haikarainen"
Think this should be default tho!
This has already been discussed in the forum (can't find the threads).

The conclusion was that it is more meaningful and intuitive if SetImage() changes only the image and SetSubRect() only the sub-rect, unless explicitly otherwise specified.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Haikarainen

  • Guest
Weird drawing bug :S
« Reply #4 on: July 06, 2011, 05:55:02 pm »
Quote from: "Nexus"
This has already been discussed in the forum (can't find the threads).

The conclusion was that it is more meaningful and intuitive if SetImage() changes only the image and SetSubRect() only the sub-rect, unless explicitly otherwise specified.


Hmm, you really got a point there. *Systematic insight-ding* :D