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.


Topics - TheEnigmist

Pages: 1 [2]
16
Graphics / Manage dynamic sprites on screen
« on: January 21, 2012, 04:44:46 pm »
I'm enjoying with SFML and i was thinking about FPS and bullets. So i thought:
-player fires unknown number of bullets;
-all bullets must be destroyed or game will go in memory leak;
So i was learning about dynamic sprite on screen and deleting them after X coords reach App.Width/2.
My code works fine (i spent 2h to make it work), but my question is, there is better way to manage this problem or my code is already optimized?
Code: [Select]

#include <SFML/Graphics.hpp>
#include <iostream>
#include <list>

int main()
{
sf::RenderWindow App(sf::VideoMode(800,600,32),"SFML AnimTest",sf::Style::Titlebar | sf::Style::Close);
App.SetFramerateLimit(300);
sf::Event event;

sf::Texture bulletTexture;
bulletTexture.LoadFromFile("data/img/fire.png");

sf::Sprite *bulletSpritePtr=NULL;

std::list<sf::Sprite *> bulletList;
std::list<sf::Sprite *>::const_iterator bulletIterator;

float speed = 400.0f;

while(App.IsOpen()){

float FPS = App.GetFrameTime() / 1000.f;

if (App.PollEvent(event))
{
if (event.Type == sf::Event::Closed || (event.Type == sf::Event::KeyPressed && event.Key.Code == sf::Keyboard::Escape))
App.Close();
if(event.Type == sf::Event::MouseButtonPressed && event.MouseButton.Button == sf::Mouse::Left){
bulletSpritePtr= new sf::Sprite(bulletTexture);
bulletSpritePtr->SetPosition(sf::Mouse::GetPosition(App).x,sf::Mouse::GetPosition(App).y);
bulletList.push_back(bulletSpritePtr);
bulletSpritePtr=NULL;
}
}

//MOVE BULLETS
if(!bulletList.empty()){
for (bulletIterator = bulletList.begin(); bulletIterator != bulletList.end(); bulletIterator++){
(**bulletIterator).Move(speed * FPS, 0);
if((**bulletIterator).GetPosition().x > App.GetWidth()/2)
bulletSpritePtr=*bulletIterator;
}
}

//DELETE ALL BULLETS > APP.WITH / 2
if(bulletSpritePtr!=NULL){
bulletList.remove(bulletSpritePtr);
bulletSpritePtr=NULL;
}

App.Clear(sf::Color::Black);

if (!bulletList.empty())
for(bulletIterator = bulletList.begin(); bulletIterator != bulletList.end(); bulletIterator++)
App.Draw(**bulletIterator);

App.Display();
}
return EXIT_SUCCESS;
}

17
General / Wrong mouse coordinates
« on: January 21, 2012, 03:41:43 pm »
I've discovered that Mouse.GetPosition() return mouse position on desktop and not take care of REnderWindow i made... this code:
#include <SFML/Graphics.hpp>
#include <iostream>

Code: [Select]
int main()
{
sf::RenderWindow App(sf::VideoMode(800,600,32),"SFML AnimTest",sf::Style::Titlebar | sf::Style::Close);
sf::Event _event;

while(App.IsOpen()){

std::cout << sf::Mouse::GetPosition().x << "  "<< sf::Mouse::GetPosition().y<<std::endl;

if (App.PollEvent(_event))
{
if (_event.Type == sf::Event::Closed || (_event.Type == sf::Event::KeyPressed && _event.Key.Code == sf::Keyboard::Escape))
App.Close();
}
App.Clear(sf::Color::White);
App.Display();
}
return EXIT_SUCCESS;
}


And here the screens:
http://img220.imageshack.us/img220/4075/76593094.jpg
http://img220.imageshack.us/img220/4075/76593094.jpg

The red arrows point to mouse when i made the print, first on top-left of my desktop, then on bottom-right. As you can see on console my desktop top-left coordinates are 0,0 and not my SFML window. Why? Is it a bug or not?

18
Graphics / Sprite doesn't move!
« on: January 20, 2012, 03:53:06 pm »
I've a little tutorial code to test Move() func of a prite.
But the sprite doesn't want ot move, here my little full code:
SFML 2
Code: [Select]

int main()
{

sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML",sf::Style::Close | sf::Style::Titlebar);
sf::Texture HeroIMG;
sf::Sprite HeroSprite;
float Speed=400.0f;
HeroIMG.LoadFromFile("data/img/hero.jpg");
HeroSprite.SetTexture(HeroIMG);
HeroSprite.SetPosition((float)App.GetWidth()/2-(HeroSprite.GetGlobalBounds().Width/2),(float) App.GetHeight()/2-(HeroSprite.GetGlobalBounds().Height/2));

// Start game loop
while (App.IsOpen())
{
float test = App.GetFrameTime() / 1000;
// Process events
sf::Event Event;
if (App.PollEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();

if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Escape))
App.Close();
}

if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Left))
HeroSprite.Move(-Speed * test, 0);
if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Right))
HeroSprite.Move( Speed * test, 0);
if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Up))
HeroSprite.Move(0, -Speed * test);
if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Down))
HeroSprite.Move(0,  Speed * test);


App.Clear();
App.Draw(HeroSprite);

// Display window contents on screen
App.Display();
}

return EXIT_SUCCESS;
}

I tried to:
- change test from float to Uint32;
- delete /1000;
- change /1000 in *1000;
- put left/right/up/down events inside App.PollEvent;

19
General / Setting SFML properties on VS2010 with 1 click!
« on: January 17, 2012, 12:23:58 am »
Hi all,
sorry for my bad english :lol:.
I want to share with all this guide for setting SFML proprieties for all new VS2010 projects. Hope it helps some ppl, if not Leaurent can destroy this thread :lol:
PS: Yes, i used paint to take pics :lol:
(I used to be photoshop user, then i took a ban in the program).

Let's start!
Open a new project in VS2010 (Console application in this example).
Go to View->Property Manager
1
Right click on your project -> Add New Project Property Sheet...
2
Choose a Name and Location where you want store this personal setup.
SFML and Desktop in my example.
3
Click Add and you should have something like this:
4
Now right click on one of 2 SFML -> Properties
5
You should see SFML Property Page!
Go to VC++ Directories and select Include Directories, then click on the right -> Edit, we are adding our SFML includes:
6
Now in Include Directories double click on empty space and you shoud see something like this:
7
Click on suspension points and find your SFML's include folder, Program Files (x86)\SFML\include in my example.
8
Add that folder and then click OK
9
Repeat this step for Library Directories to add SFML's lib folder
10
You should have something like this after these steps:
11
Now go to C/C++ section and in General->Additional Include Directories do the same as Include Directories of VC++ Directories section:
12
Go in Preprocessor and add in Preprocessor Definitions SFML_DYNAMIC or SFML_STATIC, i choose SFML_DYNAMIC in this example:
13
Now go in Linker section -> Input and add in Additional Dependecies all libs like in picture:
14
If you want, you can personalize your setting. In this example i added this string in Pre-Build Event so when i build my project it will copy all .dll in the outdir folder.
15
Now if all is went well we can build with success a stupid SFML program like this:
16
As you can see, it copies all dll in my out dir!
Now let's test this setup for a new project.
Start a new project and try to include a SFML .hpp. You cannot do it of course:
17
We have to use our personal property sheet.
Let's add it. Go to Property Manager, right click on your proyect -> Add Ecisting Property Sheet...
18
Search your .props file and open it:
19
You should see your sheet in Property Manager as this:
20
Let's write the stupid SFML program:
21
22
Build succeeded! Yeah.
thx for reading :D

20
General / Start a game w/o console
« on: July 23, 2011, 04:35:53 pm »
I came back some day ago on this project and i see it changed a lot :D Before I made stupid windows for console application, but now i want to try to open a win32 window. I made this stupid code for example:
Code: [Select]

#include <SFML/Graphics.hpp>

int main()
{
sf::RenderWindow App(sf::VideoMode(1024,768,32),"Test Game",sf::Style::Close);
sf::View camera;
camera.SetSize(App.GetWidth(),App.GetHeight());

sf::Image background, Ship;
if ((!background.LoadFromFile("Images/background.png")) || (!Ship.LoadFromFile("Images/ship.jpg")))
{
return EXIT_FAILURE;
}

sf::Sprite sfondo (background);
sf::Sprite nave (Ship);

App.Clear();

sf::Event Eventi;

while (App.IsOpened())
{
while (App.PollEvent(Eventi))
{
switch (Eventi.Type)
{
case sf::Event::Closed:
App.Close();
break;

case sf::Event::KeyPressed:
if (Eventi.Key.Code == sf::Keyboard::Escape)
{
App.Close();
}
break;
default:
break;
}
}

App.Draw(sfondo);
App.Display();

}

return 0;
}

But when i start the program open the windows and close it faster. What do i wrong? :O
Sorry for bad eng :(

21
Graphics / How to take screenshots
« on: May 12, 2011, 11:53:22 pm »
I'm looking for comand to take a screenshot with SFML 2.0
The App.Capture of 1.6 doesn't work in 2.0 and i didn't find the good comand to do it.
I need to make a menĂ¹ with last frame of the game under it.
So i want to do this
Take screen-> take it in memory -> use the comande Image.LoadFromMemory -> show it under menu interface.
Can i do it? :)

22
Audio / Getting crazy with audio
« on: May 11, 2011, 03:58:56 pm »
I know that you are working on it, but yesterday my little stupid project runs well. Now when i lunch it will crash with this error:


I can't use any sound on my project now :/

23
General discussions / Build SFML 2.0
« on: May 10, 2011, 08:44:59 pm »
I'm new on C++ world.
I want to build SFML 2.0 fot Visual Studio 2010 x86.
I downloaded Cmake, but i'm not able to make a folder with file like SFML 1.6 that you can download from the site.
So my question is:
Can you help me to buil everything from sfml 2.0 with cmake?
(everithing= include/lib/dll/examples ecc)
I don't understand how do it from the tutorial :( i'm really noob :( help me :D

Pages: 1 [2]