SFML community forums

Help => Graphics => Topic started by: cpl on September 04, 2007, 04:59:49 pm

Title: Problem with image loading!
Post by: cpl on September 04, 2007, 04:59:49 pm
Hi!

I have 2 pics that i want to use on a sprite. One of the pics is 100x100 and the other is 50x50 pixels.

Code: [Select]

sfImage image1;
sfImage image2;
   
image1.LoadFromFile("image1.bmp");
image2.LoadFromFile("image1.bmp");
   
sfSprite sprite(image1);

sprite.SetImage(image2);


When i'm trying to set a new image the the size doesn't change. So when i use sprite.SetImage(image2) the size is still the same size of image1. How do i do to set the size so it's the same as image2?
________
Lolol (http://lolol.net/)
Title: Problem with image loading!
Post by: ExcessNeo on September 04, 2007, 05:07:41 pm
You could try the Scale(float Factor) method in the sfSprite class.

Like so
Code: [Select]

sfImage image1;
sfImage image2;
   
image1.LoadFromFile("image1.bmp");
image2.LoadFromFile("image1.bmp");
   
sfSprite sprite(image1);

sprite.Scale(0.5f);
sprite.SetImage(image2);
Title: Problem with image loading!
Post by: cpl on September 04, 2007, 05:24:02 pm
No, that didn't work. When I'm drawing the sprite the image2 pic is displayed
4 times. When i tried scaling it there was no difference except it's all getting smaller.

Thanks for the quick reply, though.
________
ROOR BONGS (http://roorbongs.org)
Title: Problem with image loading!
Post by: ExcessNeo on September 04, 2007, 05:30:54 pm
Ok, this is the method that should work.

SetSubRect(const sfIntRect& SubRect)

Code: [Select]

sfImage image1;
sfImage image2;
   
image1.LoadFromFile("image1.bmp");
image2.LoadFromFile("image1.bmp");
   
sfSprite sprite(image1);

sfIntRect SubRect;
SubRect.Left = 0;
SubRect.Top = 0;
SubRect.Bottom = 50;
SubRect.Right = 50;

sprite.SetSubRect(SubRect);
sprite.SetImage(image2);
Title: Problem with image loading!
Post by: cpl on September 04, 2007, 05:33:54 pm
Yes, that did the job! Thanks a lot!
________
Ffm Babysitter (http://www.fucktube.com/categories/532/babysitter/videos/1)
Title: Problem with image loading!
Post by: ExcessNeo on September 04, 2007, 05:37:41 pm
No problem mate.
Title: Problem with image loading!
Post by: Mindiell on September 04, 2007, 05:46:50 pm
I don't think this is the good solution. What you do is having a 100x100 image and taking only the first 50x50 part...

My first question is :
- Why are you using the same sprite to draw 2 images ?
Title: Problem with image loading!
Post by: ExcessNeo on September 04, 2007, 06:00:57 pm
Quote from: "Mindiell"
I don't think this is the good solution. What you do is having a 100x100 image and taking only the first 50x50 part...

My first question is :
- Why are you using the same sprite to draw 2 images ?


I was going to have questioned his methods but I thought I'd rather provide a working and very valid solution to his problem, in the style of his code to save arguement.

Although I do agree with you that the simple solution is to create a new Sprite for each image.
Title: Problem with image loading!
Post by: cpl on September 04, 2007, 06:01:52 pm
Quote from: "Mindiell"
I don't think this is the good solution. What you do is having a 100x100 image and taking only the first 50x50 part...

My first question is :
- Why are you using the same sprite to draw 2 images ?


Well, I'm making a simple pong game and i want the paddles to be able to change size.
Perhaps it's better to use diffrent sprites for the different sizes instead of different images?

(I have always used this way when i'm doing applications in SDL and it's working fine)
________
Shemale Sex (http://www.fucktube.com/categories/36/shemale/videos/1)
Title: Problem with image loading!
Post by: cpl on September 04, 2007, 06:04:42 pm
Quote from: "ExcessNeo"
Quote from: "Mindiell"
I don't think this is the good solution. What you do is having a 100x100 image and taking only the first 50x50 part...

My first question is :
- Why are you using the same sprite to draw 2 images ?


I was going to have questioned his methods but I thought I'd rather provide a working and very valid solution to his problem, in the style of his code to save arguement.

Although I do agree with you that the simple solution is to create a new Sprite for each image.


Ok, this seems to be a better way of doing it. I guess I'll have to rewrite some code  :evil: .
________
TEEN XXX (http://www.fucktube.com/categories/39/teen/videos/1)
Title: Problem with image loading!
Post by: Mindiell on September 04, 2007, 06:32:58 pm
I really think that the best to do is to have different paddles on the image, and with the subRect sprite method, you can easily change the sprite displayed on the screen :

Code: [Select]

sfImage image("mypaddles.bmp");
sfSprite paddle;

paddle.SetImage (image);

//using the first paddle
// from (0,0) to (50,50)
paddle.SetSubRect(sfIntRect(0,0,50,50));
...
//Later in game, use the second paddle
// from (50,0) to (150,50) (same height, but larger)
paddle.SetSubRect(sfIntRect(50,0,150,50));


with this, you have only one image, and only one psrite, no ? :)
Title: Problem with image loading!
Post by: cpl on September 05, 2007, 11:41:17 am
Actually I've managed to solve the problem without altering my previous code.

Code: [Select]

if(paddleLeft->changeSize())
{
     delete paddleLeft;
     paddleLeft = new Paddle(image2,newXPos,newYPos);
}


Thanks for all the replys!
________
Naked (http://www.toyota-wiki.com/wiki/Daihatsu_Naked)