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

Pages: 1 ... 3 4 [5] 6 7 ... 12
61
Graphics / How to move a sprite without leaving multiple copies?
« on: September 12, 2011, 02:57:42 pm »
You need to follow this logic:
-Process Events/Physics
-Then Clear the window from the previous frame
-Call Draw for the objects to be drawn
-Display

In your code it should be:
Code: [Select]
while(Window.IsOpened())
{
   sf::Event event;
while(Window.GetEvent(event))
{        
if(event.Type == sf::Event::Closed)
{
Window.Close();
}
if((event.Type == Event.KeyPressed) && (event.Key.Code == Key::Left))
{

Sprite.Move(-10.0, 0);
}
}
Window.Clear()
Window.Draw(Sprite);
Window.Display();
}


Some extra: You'll want to deal with real-time inputs since in your case you want to move the sprite, right?
For that you need to create the following condition outside the event loop (for SFML 2.0):
Code: [Select]

while(Window.IsOpened())
{
   sf::Event event;
while(Window.GetEvent(event))
{
if(event.Type == sf::Event::Closed)
{
Window.Close();
}
}
if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Left)
Sprite.Move(-10.0, 0);

Window.Clear()
Window.Draw(Sprite);
Window.Display();
}

62
General discussions / The new graphics API in SFML 2
« on: September 12, 2011, 02:47:47 pm »
This question is coming from someone who knows nothing about this subject but I got curious:
If sf::Text was to be removed, what other ways would there be to display a simple text?

63
System / Using threads to load stuff
« on: September 08, 2011, 04:25:03 pm »
Quote from: "Richy19"
Why do you have

loadingThread.Wait();

Here: http://www.sfml-dev.org/tutorials/1.6/system-threads.php
On the section: Terminating a thread

Quote
The only way to safely terminate a running thread is simply to wait for it to finish by itself. To wait for a thread, you can use its Wait() function


Though the tutorial is for SFML 1.6, some parts might still apply to 2.0.

64
Graphics / VSync does not work properly!
« on: September 07, 2011, 04:49:28 pm »
I'm also having some trouble with v-sync.

Every time I start an SFML application for the first time, the framerate is always between 22 and 33 FPS.
However after closing and re-opening the same application, the framerate backs up to 56 and 62, but I never get a precise 60 or 59.5 like I did on SFML 1.6.

Could I fix this somehow?

System:
Windows 7 Pro (x64)
ATI HD4870 (driver up-to-date, no clock changes, default factory settings)

65
General / Simple operator overloading question
« on: August 26, 2011, 01:15:57 am »
Oh boy, this isn't the first time I forget to use const references.

Quote
Your implementation is misleading: it replaces the contents of the text instead of concatenating to the current string.

I know, In this case I wanted it to overwrite the previous value but you're right, the operator can be misleading. I think I'll end up changing it to a function.

Thank you.

66
General / Simple operator overloading question
« on: August 24, 2011, 09:38:54 pm »
Hey, Sorry for bumping the topic again but I've ran into another problem.
I'm was trying to make a class that worked like std::cout but for displaying text easily with SFML.

I did the following for outputting:
Code: [Select]
template<class T>Label & Label::operator << (T &input)
{
std::ostringstream ss;
ss << input;
   //text is an sf::Text Object from the class
text.SetString(ss.str());
return *this;
}


This works if I do, for example:
Code: [Select]
double i=0.0;
LabelObject << i;


But it doesn't work if I do:
Code: [Select]
LabelObject << 0.0;
I get the error "no operator found which takes a right-hand operand of type 'double' (or there is no acceptable conversion)".
I'm not sure what's the difference and the problem here. What could be wrong?

Thanks in advance.

67
General / Cant find lots of stuff in 2.0
« on: August 23, 2011, 12:26:36 am »
Are you including the correct Headers?
I.E. Sound.hpp for sf::Sound.

68
General / taskbar slow
« on: August 22, 2011, 11:22:22 pm »
Hi, I think this is already a known issue:
https://github.com/SFML/SFML/issues/69

69
General / Best container
« on: August 15, 2011, 03:10:29 am »
Awesome! I started by correcting the swap'n'pop method and I ended up with this code:
Code: [Select]
typedef std::vector<block>::iterator vectorBlocksIt;
for(vectorBlocksIt it = vectorBlocks.begin(); it != vectorBlocks.end(); it++)
{
//Move the Objects
it->Update();
//Swaping Method
if(it->VerifyBorderCollision())
{
vectorBlocksIt itend = vectorBlocks.end() - 1;
std::swap(*itend, *it);
vectorBlocks.pop_back();
}
else
renderwindow.Draw(it->shapeBlock);
}

The code works, and it's also much faster than using erase().
I had no more delays or flickering but unfortunately there was just one visual problem:
When the if(it->VerifyBorderCollision()) method is hit, on the objects that are spawned each period, a strange counter-clockwise blinking effect runs through the blocks. What's causing this? Is the method not fast enough?

As for the remove_if it that worked perfectly. I haven't used functors before so this was good to learn about them, thank you for all the help.

Cheers.

70
General / Best container
« on: August 14, 2011, 04:26:35 am »
I've tried implementing both a swap and the remove_if methods but I'm not having much success. I know this is related to the basics of STL rather than SFML but could I get a small helping hand in here?

Here's what I'm doing for the swap method (I've switched to using iterators this time too):
Code: [Select]
for(vectorBlocksIt it = vectorBlocks.begin(); it != vectorBlocks.end(); it++)
{
//Move the Objects
it->Update();
//verify if they're touching the borders and erase if they are
if(it->VerifyBorderColision())
{
std::swap(vectorBlocks.end(), it);
vectorBlocks.pop_back();
}
renderwindow.Draw(it->shapeBlock);
}

This gives me a fatal error. I'm pretty sure the problem is in swap but I'm unsure what's wrong.

For the remove_if method I couldn't find a clear explanation on how to use this function (at least for my newbie level), so what I've tried was:

Code: [Select]
for(vectorBlocksIt it = vectorBlocks.begin(); it != vectorBlocks.end(); it++)
{
//Move the Objects
it->Update();
std::remove_if(vectorBlocks.begin(), vectorBlocks.end(), it->VerifyBorderColision());
renderwindow.Draw(it->shapeBlock);
}

This gives me an unhandled exception but I'm probably using this function incorrectly anyway.

How could I fix this? For both methods I mean.
Sorry about the newbie questions and thanks for the help so far.

71
General / Best container
« on: August 13, 2011, 06:25:52 am »
Quote from: "Laurent"
You must give us more details.

Sorry, I guess I didn't explain it very well. I don't really now how to explain it though so I made a kind-of-minimal example that does what I usually experience.
It's pretty large though, but I think the only interesting part begins on the main function. I posted it on Pastebin (Link) as it's easier to read there. If it's still pretty large to be minimal I'll try to chop off some code.
In this example whenever an object starts getting near the limits of the window, they start "slowing down" until they get erased. I notice this especially on the right-midle objects. On slower machines some blocks start flickering a lot when it starts erasing (But maybe it's not std::vector's fault?).
Here's a preview of the block slowing down:


Quote from: "Laurent"

However there are "tricks" that can make a std::vector efficient at removing in the middle: if elements are cheap to copy, and must not be ordered in the container, you can swap the element to remove with the last element, so that you always remove the last element which is a very fast operation.

I wasn't aware of that, but isn't swap usually a heavy action? Guess I'm going to try it out.

Quote from: "Laurent"

So, the important questions are:
- access how?
- insert/delete where?

I'm used to inserting objects in a linear sequence such as in std::vector with push_back().
In the code I posted I insert new objects with push_back(), access objects that are touching the borders of the window by their index and use erase() to remove them. I think this is what I'm generally after, but is there a better way?

Thanks for all the help and excuse my bad English.

72
General / Best container
« on: August 12, 2011, 07:55:56 am »
Hi,
I was wondering which container would be the best to use to manage a large number of objects (1000 and up). When I say "best" I mean the fastest to access, delete, add new members, etc.

I usually use std::vector but I've read before that it's quite inefficient and I'm starting to believe that this is true since I notice many flickering objects when many are being added and deleted at the same time.

Which container would be the best to use in this situation? Are there any alternatives besides std containers? What if I use an object array (for example: object
  • )? No, maybe I'm going too deep.

73
General discussions / sf::Texture implemented in SFML 2
« on: August 07, 2011, 04:18:22 pm »
Think I understand these more clearly now.
Kind of panicked a little because I was actually working on a pixel-perfect collision algorithm when this commit came out and I thought I would need to change a bunch of code, but turns out nothing much changed I guess.

Thank you.

74
General discussions / sf::Texture implemented in SFML 2
« on: August 07, 2011, 12:33:58 am »
If it's not possible to retrieve the pixel data from sf::texture, how can I store/make my own data for pixel-perfect collision?

75
Graphics / bullet keeps following the mouse
« on: July 31, 2011, 10:14:43 pm »
I think what you're looking for is sf::Vector2:
http://www.sfml-dev.org/documentation/2.0/classsf_1_1Vector2.php

Pages: 1 ... 3 4 [5] 6 7 ... 12
anything