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

Pages: [1] 2
1
General / wrong mouse coordinates and yes i did search in google
« on: January 29, 2012, 06:40:24 pm »
Hello guys
First of all I did go and search before i post this topic and i found a lot of posts about this topic but my problem is a bit wired.

My window is 800, 600 and when i print the mouse coordinates i get x from -500 to 1300 and Y from -200 to 800.

how can i make the lowest value for x 0 and biggest 800 and for y 0 and 600?

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

#include <string>
#include <iostream>

#pragma comment(lib, "sfml-window-d.lib")  
#pragma comment(lib, "sfml-graphics-d.lib")  
#pragma comment(lib, "sfml-system-d.lib")  

int main()
{
sf::RenderWindow Window(sf::VideoMode(800, 600, 32), "HI");

while(Window.IsOpen())
{

std::cout<<sf::Mouse::GetPosition(Window).x << " ";
std::cout<<sf::Mouse::GetPosition(Window).y << "\n";

Window.Clear();
Window.Display();
}
return 0;
}

2
General / does SFML 1.6 support OpenGL 4.0 context?
« on: January 23, 2012, 08:41:33 pm »
Hello guys
I was just wondering does SFML support window mode for OpenGL 4.0 context?
I heard that SFML uses OpenGL 1.1 context. I'm just starting to learn OpenGL and I was wondering can use both OpenGL 4.0 and SFML 1.6 without any problem?

3
Graphics / Buttons moving with view
« on: January 05, 2012, 10:46:28 am »
Hello guys
I have a sprite called button and my player sprite.
now i have a problem where the button sprite is moving with the screen. How can i only move the screen without moving the button sprite?

4
General / typewriter effect like RPG games
« on: December 14, 2011, 01:21:32 pm »
Hello
I want to make a typewriter effect where text get displayed letter by letter like in RPG games.

I did some coding and got it to work in windows console but i can't figure out how to do it in SFML.

here is an example on how i want this.


here is the code working
Code: [Select]

#include <iostream>
#include <string>
#include <windows.h>

using namespace std;

int main() {

string Text = "This Text should be display letter by letter like a typewriter :D\n if this works I would be freak'n happy xD";

for (int x = 0; x < Text.length(); x++) {
          cout << Text[x];
          Sleep(100);
     }

     system("pause");
     return 0;
}

5
General / Dynamic library for commercial project ?
« on: December 09, 2011, 12:25:58 pm »
Hello
Right now i have linked my project with static library, and I'm planing on selling my game. So my question is, do i need to change my project linking to dynamic and use dll files for a commercial project?

also I read the SFML License and it says that i can use the library for commercial project and all i have to do is just to acknowledgment that i used sfml in my game. well what about the other library's that's sfml is using? do i need to do anything about it?

I just want to know what do i have to do to not get sued by SFML group or by other library like OpenAL, GLEW, freetype etc...

6
Graphics / animation drop frame rate from 60 to 10fps?
« on: November 01, 2011, 07:29:06 pm »
Hello guys
what do you think of my animation? it works perfectly, but i though maybe someone has some comments on the code. is there a better way to code it. any advice you can give me is much appreciated.

[Added]
ok i have discovered something where if you use this code with a lot of images, the frame rate drops from 60fps to 10fps and the gpu usage go to 70-90%.

and i have a 5970 graphic card with two gpus !!
any idea how to solve this problem?


[Added last (New)]
very very weird problem. if i add this line of code the frame drop from 60FPS to 7FPS !!!!!

Code: [Select]

std::cout<< clock.GetElapsedTime()<< "\n";  //DROP FRAME RATE



feel free to use this code in your project.
Code: [Select]

#include <SFML\Graphics.hpp>
#include <iostream>

int main()
{
sf::Image image1, image2, image3, image4, image5;
sf::Sprite sprite1;

image1.LoadFromFile("water1.png");
image2.LoadFromFile("water2.png");
image3.LoadFromFile("water3.png");
image4.LoadFromFile("water4.png");
image5.LoadFromFile("water5.png");

sprite1.SetImage(image1);

sprite1.SetPosition(200,200);

    sf::RenderWindow window(sf::VideoMode(800, 600, 32), "sftool::animation sample");

sf::Clock clock;

    while (window.IsOpened())
    {
        sf::Event Event;
window.SetFramerateLimit(60);

        while (window.GetEvent(Event))
        {

        }

float time1 = clock.GetElapsedTime();
float time2 = clock.GetElapsedTime();
float time3 = clock.GetElapsedTime();
float time4 = clock.GetElapsedTime();
float time5 = clock.GetElapsedTime();

std::cout<<time1 << "\n";

        // Draw everything.
        window.Clear();

window.Draw(sprite1);

if(time1 >= 0.2)
{
sprite1.SetImage(image2);
window.Draw(sprite1);
}

if(time2 >= 0.6)
{
sprite1.SetImage(image3);
window.Draw(sprite1);
}

if(time3 >= 1.0)
{
sprite1.SetImage(image4);
window.Draw(sprite1);
}

if(time4 >= 1.4)
{
sprite1.SetImage(image5);
window.Draw(sprite1);
clock.Reset();
}

        window.Display();
    }
 
    return EXIT_SUCCESS;
}
[/code]

7
Graphics / trying to make enemy walk in a specific direction
« on: October 31, 2011, 02:22:56 pm »
Hello
i'm trying to make an image to move in a specific direction. for example i want it to first move right, if it reach 50 pixel it stops and then move down, if it reach 50 pixel again it moves left and so on. but the problem is when it try to move left it can't, it just start to shake and not move.

here is the code:
Code: [Select]

#include <SFML\Graphics.hpp>
#include <iostream>

class mov
{
public:
mov();
~mov();
void drawmap(sf::RenderWindow &window);

private:
sf::Image grassimage, dirtimage;
sf::Sprite grasssprite, dirstsprite;
};



Code: [Select]

#include "mov.h"


mov::mov()
{
dirtimage.LoadFromFile("dirt.png");
dirstsprite.SetPosition(0,0);
}


mov::~mov()
{
}

void mov::drawmap(sf::RenderWindow &window)
{
float ElapsedTime = window.GetFrameTime();
dirstsprite.SetImage(dirtimage);

int posX = dirstsprite.GetPosition().x;
int posY = dirstsprite.GetPosition().y;

int Speed = 8;

int Up = -10;
int Down = 10;
int Right = 10;
int Left = -10;

dirstsprite.Move(Right * ElapsedTime * Speed, 0);

if(posX >=50)
dirstsprite.Move( -(Right * ElapsedTime * Speed), Down * ElapsedTime * Speed);

if(posY >=50)
dirstsprite.Move( Left * ElapsedTime * Speed, -(Down * ElapsedTime * Speed));

window.Draw(dirstsprite);

}




Code: [Select]
#include <SFML\Graphics.hpp>
#include "mov.h"

int main()
{
sf::RenderWindow window(sf::VideoMode(800,600,32),"AI Follow Grass Road");

mov SM;

while(window.IsOpened())
{
window.SetFramerateLimit(60);

sf::Event Event;
while(window.GetEvent(Event))
{

}

window.Clear();
SM.drawmap(window);
window.Display();
}
return 0;
}

8
Network / why use Encrypted Packet?
« on: September 10, 2011, 12:34:57 am »
Hello everyone

I was just wondering what is the point of using Encrypted Packets ? I read about it in the SFML network tutorial and i really didnt understand it very well.

http://www.sfml-dev.org/tutorials/1.6/network-packets.php

is there any point to it ?
i though it would be just easier to just write a struct and send it.

thanks.

9
Graphics / Bullet problem
« on: July 24, 2011, 02:28:30 pm »
hay guys

ok so i have made a bullet array and when i click the left button on the mouse the bullet get the player position and move from there, but the problem is whenever i click on the mouse it doesn't generate a new Bullet but it just remove the old one and get the player position again and move from there.

can you guys please help? thankx

Code: [Select]

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

int main()
{
   sf::RenderWindow Window(sf::VideoMode(800, 600, 32), "Zombie Game Alpha");

   sf::Image PlayerImage, BulletImage;
   sf::Sprite PlayerSprite, BulletSprite[10];

   PlayerImage.LoadFromFile("player.png");
   BulletImage.LoadFromFile("bullet.png");

   PlayerSprite.SetImage(PlayerImage);

for(int x=0; x<=9; x++)
BulletSprite[x].SetImage(BulletImage);

   PlayerSprite.SetPosition(200,200);

   bool Draw=false;
   int Counter=0;

   while(Window.IsOpened())
   {
      sf::Event Event;

 float ElapsedTime = Window.GetFrameTime();

 if (Window.GetInput().IsKeyDown(sf::Key::W))  PlayerSprite.Move(0, -425 * ElapsedTime);
      if (Window.GetInput().IsKeyDown(sf::Key::S))  PlayerSprite.Move(0,  425 * ElapsedTime);
      if (Window.GetInput().IsKeyDown(sf::Key::A))  PlayerSprite.Move(-425 * ElapsedTime, 0);
      if (Window.GetInput().IsKeyDown(sf::Key::D))  PlayerSprite.Move(425 * ElapsedTime, 0);
     
 while (Window.GetEvent(Event))
      {
         if (Event.Type == sf::Event::Closed)
            Window.Close();
         if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
            Window.Close();

if(Event.Type == sf::Event::MouseButtonPressed && Event.MouseButton.Button == sf::Mouse::Left)
{
Draw=true;
Counter++;
for(int x=0; x<=Counter; x++)
BulletSprite[x].SetPosition(PlayerSprite.GetPosition().x,PlayerSprite.GetPosition().y);
}

      }
 
 Window.Clear();
      Window.Draw(PlayerSprite);

 if(Draw==true)
 {
 for(int x=0; x<=Counter; x++)
 {
BulletSprite[x].Move(200 * ElapsedTime, 0);
Window.Draw(BulletSprite[x]);
 }
 std::cout << Counter;
 }
      Window.Display();
   }
}

10
Graphics / Lighty font !! :D
« on: July 10, 2011, 05:08:20 pm »
hay guys
i saw this picture and i liked the way the font looks, it look like a neon sign.
any idea how can i do that in sfml ?
thank everyone :D


11
Network / network based game - network newbie
« on: July 08, 2011, 12:20:48 pm »
hello everyone
i have been working on a top down 2d shooter and its almost finished and all is left is to implement network to the game.
now i have been able to make a server and a client successfully where the server sends a message and the client receive it, but i dont know how to send the player stats and movement and enemy's and all that.

so can you guys help please, keep in mind this is my first time to make a network based game

thank you all

12
Graphics / if key pressed and released draw image doesnt work
« on: July 07, 2011, 03:57:10 pm »
hello everyone
i have an image and i want when i press key::M to draw the image but it isnt working

i tried this but the image disappear when releasing M key
Code: [Select]

if(Game.GetInput().IsKeyDown(sf::Key::M))
Game.Draw(Sprite);


i also tried this and it works perfectly but when i move the mouse  the image disappear
Code: [Select]

while(Game.IsOpened())
{
sf::Event Event;
while(Game.GetEvent(Event))
{
}

Game.Clear();
if(Event.Type == sf::Event::KeyReleased && Event.Key.Code == sf::Key::M)
Game.Draw(Sprite);
Game.Display();


i also tried this but it doesn't work at all
Code: [Select]

while(Game.IsOpened())
{
sf::Event Event;
while(Game.GetEvent(Event))
{
if(Event.Type == sf::Event::KeyReleased && Event.Key.Code == sf::Key::M)
Game.Draw(Sprite);
}

Game.Clear();
Game.Display();


please can someone help  :(

13
Graphics / Draw map from text file
« on: July 03, 2011, 10:49:15 pm »
hello everyone

so i'm trying to make a load map function and draw map function but i cant get it to work correctly, here is the code.

Code: [Select]

#include <SFML\Graphics.hpp>
#include <iostream>
#include <string>
#include <fstream>

int Map[100][100];
int loadCounterX=0;
int loadCounterY=0;

int mapSizeX;
int mapSizeY;

bool once=false;

void LoadMap (const char *filename)
{
std::ifstream openfile(filename);
if(openfile.is_open())
{
while(!openfile.eof())
{
if(once==false)
{
openfile>>mapSizeX>>mapSizeY;
once = true;
}
openfile >> Map[loadCounterX][loadCounterY];
loadCounterX++;
if(loadCounterX>=mapSizeX)
{
loadCounterX=0;
loadCounterY++;
}
}
}
}

void DrawMap()
{
for(int i=0; i<mapSizeX; i++)
for(int a=0; a<mapSizeY; a++)
Game.Draw(Map[i][a]);
}


int WindowWidth = 800, WindowHight = 600, ColorDepth = 32;
std::string WindowTitle = "The Final Game !!!";

sf::RenderWindow Game(sf::VideoMode(WindowWidth, WindowHight, ColorDepth), WindowTitle);

int main()
{
sf::Event Event;

const char *tiles[2];
tiles[1]=("Data/Images/grass.png");
tiles[2]=("Data/Images/dirt.png");

Game.SetFramerateLimit(60);

while(Game.IsOpened())
{
while(Game.GetEvent(Event))
{


}


Game.Clear();
Game.Display();
}

return 0;
}


text file
10 2
1111111111
0000000000


14
Graphics / move sprite in the opposite direction and bullet problem
« on: June 23, 2011, 07:48:52 pm »
hello everyone

i'm trying to make an enemy sprite to move to the end of the screen which is right and then move back to the start of the screen (left), but i only could make move in one direction i cant make it move in the opposite direction.

Code: [Select]


   while (App.IsOpened())
   {
int X = sprbox.GetPosition().x;
int Y = sprbox.GetPosition().y;

if(X<=700)
sprbox.Move(100* ElapsedTime, 0);

else
sprbox.Move(-200* ElapsedTime, 0);
}


[Edit]
Quote from: "section_two"

You can do something like:

Code: [Select]
 
   ...
   int dir=1;
   ...
   while (App.IsOpened())
   {
         ...
         if(X>=700)dir=-1;
         if(X<=0)dir=1;
         sprbox.Move(100 * dir * ElapsedTime, 0);
         ...
   }



that didnt work i tried it but still didnt work.
alos i have another problem where i want if you press Space bar the bullet will move through the screen, i did that but i have to keep pressing space, however i solved that problem latter by doing this
Code: [Select]

sf::Event event
while (window.GetEvent(event))
{
    if (event.Type == sf::Event::KeyReleased && event.Key.Code == sf::Key::Space)
    {
        bullet.moveme(App,ElapsedTime);
    }
}


but the problem is i have to press space to move the bullet about 2px, so i keep pressing space to move the bullet which is not what i want.

15
Graphics / trying to do fire animation
« on: June 19, 2011, 11:32:47 pm »
hello everyone
so i have 7 images of fire and i was trying to make an animation with them but from the looks of it i failed.

i looked at http://www.sfml-dev.org/wiki/en/sources/frame_anim_animated but i didn't really understand a lot from it but i did my best.

here is what i did

Code: [Select]
int main()
{
Event Event;
Clock Clock;


//Create SFML windows
RenderWindow Game(VideoMode(800,600,32), "Game");

Image Img1;
Sprite Sprt1;
Image Img2;
Sprite Sprt2;
Image Img3;
Sprite Sprt3;
Image Img4;
Sprite Sprt4;
Image Img5;
Sprite Sprt5;
Image Img6;
Sprite Sprt6;
Image Img7;
Sprite Sprt7;

Img1.LoadFromFile("1.png");
Sprt1.SetImage(Img1);
Sprt1.Move(100,100);
Img2.LoadFromFile("2.png");
Sprt2.SetImage(Img2);
Sprt2.Move(100,100);
Img3.LoadFromFile("3.png");
Sprt3.SetImage(Img3);
Sprt3.Move(100,100);
Img4.LoadFromFile("4.png");
Sprt4.SetImage(Img4);
Sprt4.Move(100,100);
Img5.LoadFromFile("5.png");
Sprt5.SetImage(Img5);
Sprt5.Move(100,100);
Img6.LoadFromFile("6.png");
Sprt6.SetImage(Img6);
Sprt6.Move(100,100);
Img7.LoadFromFile("7.png");
Sprt7.SetImage(Img7);
Sprt7.Move(100,100);

Game.UseVerticalSync(true);

//Game loop
while(Game.IsOpened())
{

float Framerate = 1.f / Clock.GetElapsedTime();
Clock.Reset();

//Event handle loop
while(Game.GetEvent(Event))
{

if(Event.Type == Event::Closed)
Game.Close();

if (Game.GetInput().IsKeyDown(Key::Escape))
Game.Close();

if (Game.GetInput().IsKeyDown(Key::Num1))
StartPlaying();

if (Game.GetInput().IsKeyDown(Key::Num2))
Settings();
}

String Text("Press 1 to start playing the game\n"
"Press 2 to open Settings\n"
"Press ESC to Exit the game\n");

Text.SetColor(Color(255, 0, 0));
Text.Move(100.f, 100.f);

//Clear the game window
Game.Clear();

//Display Text
Game.Draw(Text);
//
for(int x=1; x<=7; x++)
{
Game.Draw(Sprt1);
Game.Draw(Sprt2);
Game.Draw(Sprt3);
Game.Draw(Sprt4);
Game.Draw(Sprt5);
Game.Draw(Sprt6);
Game.Draw(Sprt7);
}
//Display SFML graphics to window
Game.Display();

}
return 0;

}


the end result is all i see is Sprt7 and it doesnt loop again to draw Sprt1 i dont know why is that

Pages: [1] 2