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

Pages: [1]
1
Graphics / Collision detection between two sprites in different classes
« on: February 08, 2011, 05:25:21 am »
Right now what my program does is this:
It creates and renders a Player sprite, a Bullet sprite, and a Centipede sprite. The Bullet and Player sprite are in one class, and the Centipede sprite in a different class. The Bullet sprite is 'parented' to the Player sprite: When it moves, the Bullet moves too.
When I press spacebar, the bullet sprite changes color and moves until it reaches the top of the screen. When it does, it changes it's color back to white, and continues following the Player sprite. However, when the Bullet sprite touches the Centipede sprite, (It's X coordinate is greater then it's left corner, but less then it's right corner, etc.) I want the Centipede sprite to disappear to show it's been hit.
What would be the best way to do this? (The player has a reference of the Centipede instance, so I can just call a function)
Do I remove the entire instance of the Centipede class using the delete command, or just the sprite? Do I just set the color of the sprite to black?

2
General / Program extremely laggy?
« on: February 08, 2011, 01:32:28 am »
....whoops.

3
General / Program extremely laggy?
« on: February 08, 2011, 12:02:28 am »
I made a simple program, and it's extremely laggy, taking up 98% of my CPU. Why is this? Did I do something wrong?
Code: [Select]
#include <SFML/Graphics.hpp>
#include "Player.h"
int main()
{
//Create main window, using the best available resolution, and make the reference
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Window");
sf::RenderWindow &rApp = App;

//Control framerate to reduce CPU usage
App.SetFramerateLimit(30);

//Reference Classes
Player player(rApp);

//This is the main loop, it will loop until you exit the system.
while (App.IsOpened())
{
//Here we process the events list
sf::Event Event;
while (App.GetEvent(Event))
{
//Close window: exit
if (Event.Type == sf::Event::Closed)
{
App.Close();
}
//Clear the screen with a color
App.Clear();
//Here you will draw all of the stuff in the frame buffer
player.Update();
//Render the frame on screen
App.Display();
}
}
return EXIT_SUCCESS;
}


And Player.h:
http://pastebin.com/AA0wwrP6
Player.cpp:
http://pastebin.com/QXNPkurf

4
General / Access Violation in VS2010, but not in VS2008
« on: February 07, 2011, 07:20:07 am »
What the title says. I recently upgrading to VS2010, but when I try to run the program, it gives me an access violation. However, when I run the EXACT SAME code in VS2008, it doesn't crash, and it runs correctly. The program is just a basic main() function:
Code: [Select]
#include <SFML/Graphics.hpp>
int main()
{
//Create main window, using the best available resolution, and make the reference
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Window");

//Reference Classes

//This is the main loop, it will loop until you exit the system.
while (App.IsOpened())
{
//Here we process the events list
sf::Event Event;
while (App.GetEvent(Event))
{
//Close window: exit
if (Event.Type == sf::Event::Closed)
{
App.Close();
}
//Clear the screen with a color

//Here you will draw all of the stuff in the frame buffer

//Render the frame on screen
App.Display();
}
}
return EXIT_SUCCESS;
}


Why would it be glitching out like this?

5
Window / Input.GetMouseX and MouseY not returning anything? (SOLVED)
« on: February 04, 2011, 05:13:15 am »
Code: [Select]
sf::Input Input;
sf::Input &rInput = Input;
TowerManager TowerManager;
sf::Event Event;
int mouseX;
int mouseY;
// Start game loop
    while (App.IsOpened())
    {
mouseX = Input.GetMouseX();
mouseY = Input.GetMouseY();


That's just a fragment of a code, obviously, but the point's still there. When I output mouseX and mouseY (through cout), it says that they're zero. And the function I need to use them for confirms this; it also outputs zero.

Is this just a bug in the code, or am I doing something really stupid?

6
Graphics / subRect not moving with Sprite
« on: February 01, 2011, 07:43:22 am »
I'm trying to make a pong game, but the paddle can always go offscreen. So, to fix this, I was planning on doing this:
 
Code: [Select]
sf::Sprite PaddlePlayer::Update(sf::RenderWindow &App)
{
ElapsedTime = App.GetFrameTime();
if(App.GetInput().IsKeyDown(sf::Key::Down))
{
if(!rectPaddle.Contains(0, 240))
{
Paddle.Move(0, 150*ElapsedTime);
}
else
{
Paddle.SetY(240);
std::cout << "Y set to 240\n";
}
}
if(App.GetInput().IsKeyDown(sf::Key::Up))
{
if(!rectPaddle.Contains(0, 0))
{
Paddle.Move(0, -150*ElapsedTime);
}
else
{
Paddle.SetY(0);
std::cout << "Y set to 0";
}
}
return Paddle;
}

(rectPaddle is the subRect of sprite Paddle, so rectPaddle = Paddle.GetSubRect)
However, based on my results (the paddle always jumps back up to the top, no matter where it is.) I can assume that rectPaddle doesn't move with the sprite. I tried using the Offset function to get it to move, but since that is an offset, it doesn't set exactly to the sprite's location, at least for multiple times.

So my question is, how would I get the subRect to always be moving with the sprite, or at least find some way to detect if the sprite is off the screen or not?

7
Graphics / Default Code Problem, trying to use a RenderWindow as arg
« on: January 31, 2011, 11:48:41 pm »
Code: [Select]
   sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFMLApp");
sf::RenderWindow &rApp = App;
Player Player;
sf::Sprite spritePlayer = Player.Initialize();
    // Start game loop
    while (App.IsOpened())
    {
Player.Update(rApp);
sf::Event Event;
        while (App.GetEvent(Event))


Okay, so I'm using a reference now. I still get the same error.

8
Graphics / Default Code Problem, trying to use a RenderWindow as arg
« on: January 31, 2011, 04:01:18 pm »
That's what I thought....so I would need to use a pointer?

9
Graphics / Default Code Problem, trying to use a RenderWindow as arg
« on: January 31, 2011, 07:19:29 am »
Code: [Select]
#include <SFML/Graphics.hpp>
class Player
{
public:
int health;
int attackDamage;
int friendshipMeter;
int Move();
sf::Sprite SpritePlayer;
sf::Image ImagePlayer;
sf::RenderWindow App;
sf::Sprite Initialize()
{
ImagePlayer.LoadFromFile("squiddlePlayer.png");
SpritePlayer.SetImage(ImagePlayer);
return SpritePlayer;
}
void Update(sf::RenderWindow App)
{

float ElapsedTime = App.GetFrameTime();
// Move the sprite
if (App.GetInput().IsKeyDown(sf::Key::Left))  SpritePlayer.Move(-100 * ElapsedTime, 0);
if (App.GetInput().IsKeyDown(sf::Key::Right)) SpritePlayer.Move( 100 * ElapsedTime, 0);
if (App.GetInput().IsKeyDown(sf::Key::Up))    SpritePlayer.Move(0, -100 * ElapsedTime);
if (App.GetInput().IsKeyDown(sf::Key::Down))  SpritePlayer.Move(0,  100 * ElapsedTime);

// Rotate the sprite
if (App.GetInput().IsKeyDown(sf::Key::Add))      SpritePlayer.Rotate(-100 * ElapsedTime);
if (App.GetInput().IsKeyDown(sf::Key::Subtract)) SpritePlayer.Rotate( 100 * ElapsedTime);
}
};


Code: [Select]
#include "Player.h"
#include <SFML/Graphics.hpp>
int main()
{
    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "The Day the Unicorns Couldn't Play");
Player Player;
sf::Sprite spritePlayer = Player.Initialize();
    // Start game loop
    while (App.IsOpened())
    {
Player.Update(App);
sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        // Clear the screen (fill it with black color)
        App.Clear();
App.Draw(spritePlayer);

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

    return EXIT_SUCCESS;
}


Those are my two files, Main.cpp and Player.h. When I have the Player.Update(App) line in, the code doesn't compile. But it appears to be a error with the default code:
Code: [Select]
error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'
        c:\program files\sfml\sfml-1.6\include\sfml\system\noncopyable.hpp(57) : see declaration of 'sf::NonCopyable::NonCopyable'
        c:\program files\sfml\sfml-1.6\include\sfml\system\noncopyable.hpp(41) : see declaration of 'sf::NonCopyable'
        This diagnostic occurred in the compiler generated function 'sf::Window::Window(const sf::Window &)'


I don't understand why simply calling a function could call this error. Unless I can't use the RenderWindow as a argument? If I can't, then what can I do to have an update function?

Pages: [1]