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

Pages: [1]
1
I don't know how to create a minimal example, but here's a link to the whole VS solution.

https://www.dropbox.com/s/fvp8j3642ob53c5/Asteroids.rar?v=0rc-s

2
Graphics / [SFML 2.0] Spawn projectiles to mouse pointer problem
« on: May 19, 2013, 01:18:39 pm »
Basically, I have a function that has a spaceship follow the mouse pointer, which works perfectly.

        void lookAtMouse(sf::RenderWindow &app)
        {
                sf::Vector2f curPos = sprite.getPosition();
                sf::Vector2i position = sf::Mouse::getPosition(app);

                const float PI = 3.14159265;

                float dX = curPos.x - position.x;
                float dY = curPos.y - position.y;

                float rotation = (atan2(dY, dX)) * 180 / PI;

                sprite.setRotation(rotation - 180);
        }
 

I've tried to modify this to work for the projectiles it shoots, however it doesn't work and causes all kinds of graphical glitches, which I think I know why.

void MoveBullet(int numOfBullets)
{
        for (int i = 0; i < numOfBullets; i++)
        {
                                        sf::Vector2f curPos = bullet[i].getPosition();
                                        sf::Vector2i position = sf::Mouse::getPosition(app.window);

                                        const float PI = 3.14159265;

                                        float dX = curPos.x - position.x;
                                        float dY = curPos.y - position.y;

                                        float rotation = (atan2(dY, dX)) * 180 / PI;

                                    if (bullet[i].exists) bullet[i].Move(dX, dY);
        }
}
 
How would I approach having the projectiles fire to wherever the mouse pointer is? I can provide full source if required.

3
General / Re: Linking sfml with g++
« on: May 17, 2013, 06:58:37 pm »
Try adding a file in /etc/ld.so.conf.d called "sfml-x86.conf" with the path of the SFML object files and run ldconfig as root, see if that changes anything.

4
Window / [SFML 2.0] 2D diagonal movement problem
« on: May 17, 2013, 06:52:15 pm »
Minor question that is probably me being a huge derp, but nevertheless I am momentarily stumped.

Basically, I'm trying to implement 2D movement, which works fine, however when I try to move diagonally, the sprite faces the right direction, but its coords don't change and it doesn't move.

if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)&&sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
   Ship_s.setRotation(135.f);
   Ship_s.move(7, 7);
}
 

5
Graphics / Re: SFML 2.0 - Movement lag issue
« on: May 13, 2013, 11:17:36 pm »
Same really, I just figured it was the code before my system. It manages to full whole games perfectly fine, I can get 50-60fps on most CS games.

6
Graphics / Re: SFML 2.0 - Move in direction faced
« on: May 12, 2013, 07:36:42 pm »
It's facing to the right as that seems to make it looks most normal.

I figure it's something in the maths, but I'm not sure what.

7
Graphics / Re: SFML 2.0 - Move in direction faced
« on: May 12, 2013, 06:39:51 pm »
Compass directions - North, South, East & West.

I originally had it by frametime, but it didn't change much.

8
Graphics / Re: SFML 2.0 - Movement lag issue
« on: May 12, 2013, 04:44:27 pm »
I've limited from 10-120 to no avail sadly.

9
Graphics / SFML 2.0 - Move in direction faced
« on: May 12, 2013, 04:42:47 pm »
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))  
              Ship_s.rotate(7.f);
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
              Ship_s.rotate(-7.f);
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))    
             Ship_s.move(cos(Ship_s.getRotation()*3.14159265/180)*3.f,sin(Ship_s.getRotation()*3.14159265/180)*-3.f);
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))  
             Ship_s.move(cos(Ship_s.getRotation()*3.14159265/180)*-3.f,sin(Ship_s.getRotation()*3.14159265/180)*3.f);

 

The above code works, however when I try to move the ship around the screen, it only moves in the correct direction in one of the compass directions.

What do?

EDIT: https://www.youtube.com/watch?v=0SRkzad7sVw&feature=youtu.be Here's a video of what happens.

10
Graphics / Re: SFML 2.0 - Movement lag issue
« on: May 10, 2013, 11:24:22 pm »
Nothing to update, crappy onboard. If the code seems fine, I guess I'll just have to live with it. Thanks anyway.

11
Graphics / SFML 2.0 - Movement lag issue
« on: May 10, 2013, 08:51:17 pm »
I'm fairly new to SFML 2.0, used SFML 1.6 for a while so not completely new to SFML.

Basically, since 2.0 was released I figured I'd rewrite the game I'm working on to use SFML 2.0. The process went smoother than I thought it would do, but I've hit a snag. It's not exactly a big error, but the movement in all directions is fairly jittery, even with VSync/framelimits.

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
//#include "projectile.h"
#include <iostream>

int main()
{
   sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Asteroids");
   sf::Texture Ship;
   sf::Texture Space;
   if(!Ship.loadFromFile("ship.png"))
           return EXIT_FAILURE;
   if(!Space.loadFromFile("space-1.png"))
           return EXIT_FAILURE;

   sf::Sprite Ship_s;
   Ship_s.setTexture(Ship);
   sf::Sprite Space_s(Space);
   Ship_s.setPosition(200.f, 100.f);
   Ship_s.setScale(1.f, 1.f);

   sf::Clock clock;
   App.setFramerateLimit(120);
   //App.setVerticalSyncEnabled(true);
   while (App.isOpen())
   {
      sf::Time dt=clock.restart();
      sf::Event Event;
      while (App.pollEvent(Event))
      {
         if (Event.type == sf::Event::Closed)
            App.close();
      }

     
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))  
              Ship_s.move(-1 * 100 *dt.asSeconds(), 0);
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
              Ship_s.move( 1 * 50 * dt.asSeconds(), 0);
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))    
              Ship_s.move( 0,-1 * 50 * dt.asSeconds());
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))  
              Ship_s.move( 0, 1 * 50 * dt.asSeconds());

      App.clear();
      App.draw(Space_s);
      App.draw(Ship_s);
      App.display();
   }
   return EXIT_SUCCESS;
}

 

If needed, I can post a video of what it looks like. Currently running this on the latest version of Fedora 18 x86_64 on an Acer Aspire 7730. Is there anything I can do to reduce the lag?

Pages: [1]