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

Pages: 1 2 [3] 4
31
Graphics / Sprite collection implementation?
« on: October 27, 2011, 10:01:50 pm »
Currently I have a vector that contains all of Blocks to render on the screen, and another vector that contains all of the FloatRects for collision detection.  

I loop through each sprite in the block vector:

Code: [Select]

App.Draw(Blocks[i]);


And for collision, I loop through the FloatRects vector and check my collision logic against each part.

I don't plan on updating the ground or FloatRect vector after everything is generated, so I'm wondering if it's possible to make them into a collection so that I only need to draw one and check against one.  Essentially create a large image to draw, and create an obscure shape with the FloatRect.  

I'm not too sure about the FloatRect, because I assume the rectangle must be a rectangle.

I'm only interested in implementing this because occasionally my friends will fall through the ground, or the performance will get very slow occasionally.  I haven't encountered falling through the ground, but I assume it's because it hasn't reached that point in iteration just yet.

I was also thinking about looping through Blocks that are only in the view, but I'm not sure how to exclude blocks that aren't in the view.  I know how I can check to see if objects are viewable the player, but I'm not sure about removing them from the vector or excluding them from the loop.

Thanks for any help!

32
Graphics / sf::Texture.LoadFromMemory?
« on: October 26, 2011, 10:40:36 am »
@thePyro_13
@Laurent

Thanks for pointing me in the right direction!  If anyone is interested in a solution, here's what I've setup:

test.hpp
Code: [Select]

#ifndef TEST_HPP
#define TEST_HPP
char test_png[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20,
0x08, 0x02, 0x00, 0x00, 0x00, 0xfc, 0x18, 0xed, 0xa3, 0x00, 0x00, 0x00,
0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xae, 0xce, 0x1c, 0xe9, 0x00, 0x00,
0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0b, 0x13, 0x00, 0x00,
0x0b, 0x13, 0x01, 0x00, 0x9a, 0x9c, 0x18, 0x00, 0x00, 0x00, 0x07, 0x74,
0x49, 0x4d, 0x45, 0x07, 0xdb, 0x0a, 0x1a, 0x06, 0x2d, 0x30, 0xc3, 0x47,
0xff, 0xe7, 0x00, 0x00, 0x00, 0x19, 0x74, 0x45, 0x58, 0x74, 0x43, 0x6f,
0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65,
0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x47, 0x49, 0x4d, 0x50, 0x57,
0x81, 0x0e, 0x17, 0x00, 0x00, 0x02, 0x9f, 0x49, 0x44, 0x41, 0x54, 0x48,
0xc7, 0x8d, 0x56, 0x49, 0x72, 0xe4, 0x30, 0x0c, 0x03, 0xaa, 0xf4, 0xff,
0x4f, 0xe4, 0x3e, 0x2f, 0x24, 0x83, 0x39, 0x70, 0x11, 0xe5, 0xa5, 0x3b,
0x3e, 0x74, 0x62, 0x49, 0xe6, 0x02, 0x90, 0xa0, 0xf8, 0xef, 0xe7, 0x47,
0x02, 0x20, 0x90, 0x14, 0x04, 0x11, 0x14, 0x84, 0x78, 0x08, 0x8a, 0xa2,
0x20, 0x02, 0x22, 0x00, 0x42, 0x22, 0x08, 0x42, 0x12, 0x80, 0x5c, 0x17,
0xf2, 0x3b, 0x02, 0x22, 0x51, 0x7b, 0xcb, 0xcc, 0xc2, 0x94, 0x00, 0xa6,
0x55, 0x08, 0x20, 0x11, 0x5e, 0x04, 0x10, 0x69, 0x21, 0x0f, 0xe9, 0x38,
0x80, 0x8e, 0x25, 0xde, 0xf3, 0x40, 0x3a, 0x5e, 0x66, 0x1e, 0x06, 0x20,
0x88, 0xca, 0x7f, 0x05, 0x44, 0xd4, 0xdc, 0x06, 0x2f, 0xde, 0x21, 0x65,
0x36, 0xd3, 0x03, 0xc1, 0xf8, 0xb8, 0x2c, 0x2e, 0x73, 0x8b, 0x23, 0x22,
0xa9, 0x23, 0x24, 0x74, 0xe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 0x44, 0xae, 0x42,
0x60, 0x82,
};
#endif


Inside of my source file:
Code: [Select]

#include "test.hpp"
...
sf::Texture img_test;
sf::Sprite spr_test;
...

if (!img_test.LoadFromMemory(&test_png, sizeof(test_png)))
{
      //oh no!
}

spr_test.SetTexture(img_test);
spr_test.SetPosition(30, 30);

... Main Loop ...
App.Draw(spr_test);


And it's working out as expected!  Would this be an acceptable method for handling the assets that need to be included with the binary file?  Could there be any significant problems using this method?

33
Graphics / sf::Texture.LoadFromMemory?
« on: October 26, 2011, 09:10:40 am »
Currently I'm using Bin2C to generate a (*.c) file containing all of the information that makes up my image.  

Here's what the generated file looks like:
Code: [Select]

static unsigned char test_png[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20,
0x08, 0x02, 0x00, 0x00, 0x00, 0xfc, 0x18, 0xed, 0xa3, 0x00, 0x00, 0x00,
0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xae, 0xce, 0x1c, 0xe9, 0x00, 0x00,
0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0b, 0x13, 0x00, 0x00,
0x0b, 0x13, 0x01, 0x00, 0x9a, 0x9c, 0x18, 0x00, 0x00, 0x00, 0x07, 0x74,
0x49, 0x4d, 0x45, 0x07, 0xdb, 0x0a, 0x1a, 0x06, 0x2d, 0x30, 0xc3, 0x47,
0xff, 0xe7, 0x00, 0x00, 0x00, 0x19, 0x74, 0x45, 0x58, 0x74, 0x43, 0x6f,
0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65,
0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x47, 0x49, 0x4d, 0x50, 0x57,
0x81, 0x0e, 0x17, 0x00, 0x00, 0x02, 0x9f, 0x49, 0x44, 0x41, 0x54, 0x48,
0xc7, 0x8d, 0x56, 0x49, 0x72, 0xe4, 0x30, 0x0c, 0x03, 0xaa, 0xf4, 0xff,
0x4f, 0xe4, 0x3e, 0x2f, 0x24, 0x83, 0x39, 0x70, 0x11, 0xe5, 0xa5, 0x3b,
0x3e, 0x74, 0x62, 0x49, 0xe6, 0x02, 0x90, 0xa0, 0xf8, 0xef, 0xe7, 0x47,
0x02, 0x20, 0x90, 0x14, 0x04, 0x11, 0x14, 0x84, 0x78, 0x08, 0x8a, 0xa2,
0x20, 0x02, 0x22, 0x00, 0x42, 0x22, 0x08, 0x42, 0x12, 0x80, 0x5c, 0x17,
0xf2, 0x3b, 0x02, 0x22, 0x51, 0x7b, 0xcb, 0xcc, 0xc2, 0x94, 0x00, 0xa6,
0x55, 0x08, 0x20, 0x11, 0x5e, 0x04, 0x10, 0x69, 0x21, 0x0f, 0xe9, 0x38,
0x80, 0x8e, 0x25, 0xde, 0xf3, 0x40, 0x3a, 0x5e, 0x66, 0x1e, 0x06, 0x20,
0x88, 0xca, 0x7f, 0x05, 0x44, 0xd4, 0xdc, 0x06, 0x2f, 0xde, 0x21, 0x65,
0x36, 0xd3, 0x03, 0xc1, 0xf8, 0xb8, 0x2c, 0x2e, 0x73, 0x8b, 0x23, 0x22,
0xa9, 0x23, 0x24, 0x74, 0xe0, 0x69, 0x6d, 0xac, 0x17, 0x68, 0xf7, 0xe3,
0x20, 0x21, 0x05, 0xd0, 0x00, 0x97, 0xbb, 0xa7, 0xfd, 0x58, 0x91, 0xc0,
0xca, 0x5e, 0xe5, 0x94, 0xb8, 0x3f, 0x37, 0xf3, 0x75, 0x7e, 0x22, 0x2e,
0x2c, 0x77, 0x57, 0x30, 0x07, 0xd4, 0x66, 0xd9, 0x4f, 0xc3, 0xb1, 0x1a,
0xdf, 0x32, 0x82, 0x43, 0xe2, 0x4c, 0x08, 0xa4, 0x2a, 0x2a, 0xec, 0xd8,
0x0b, 0xd9, 0x4d, 0xf2, 0x1f,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7, 0x83, 0xa5, 0x5c, 0x59, 0x16, 0x03, 0x67, 0xf4,
0x4b, 0x5f, 0x29, 0x4e, 0x4d, 0x3d, 0x12, 0x7f, 0xe8, 0x32, 0x68, 0xdf,
0x01, 0x59, 0x43, 0x43, 0x58, 0x66, 0xc6, 0x37, 0x40, 0x4f, 0xf1, 0xd4,
0x98, 0x91, 0xb3, 0xae, 0xab, 0x55, 0xb2, 0xac, 0x13, 0xef, 0xbc, 0x1c,
0xd5, 0x3c, 0xe0, 0xc0, 0xff, 0xe2, 0xed, 0xdb, 0xbd, 0xe1, 0x4b, 0x6c,
0xcb, 0xdd, 0x46, 0x6f, 0x32, 0x4a, 0x76, 0xdf, 0x0d, 0x93, 0xed, 0x3d,
0x73, 0xd8, 0xd5, 0x9a, 0x92, 0x4d, 0x49, 0xe4, 0xa5, 0x67, 0xfa, 0x02,
0xc6, 0x90, 0xeb, 0xaf, 0x37, 0x21, 0xde, 0x68, 0xfe, 0x6b, 0x86, 0xcb,
0x5f, 0x3a, 0x59, 0xd7, 0x31, 0x5c, 0x99, 0xdd, 0xe7, 0xe2, 0x50, 0x6a,
0xed, 0x5b, 0x68, 0xee, 0xff, 0x07, 0xb7, 0x18, 0x41, 0x46, 0x68, 0x12,
0xa4, 0x87, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42,
0x60, 0x82,
};


I have a header file that contains:
Code: [Select]

static unsigned char *test_png;


Inside of my source file, I'm attempting with:
Code: [Select]

if (img_test.LoadFromMemory(&test_png, sizeof(test_png)))
{
     //oh no!
}


I'm compiling with:
Code: [Select]

g++ -o Testing test.c main.cpp -lsfml-graphics -lsfml-window


However, this message is returned:
Code: [Select]

Failed to load image from memory. Reason : Image not of any known type, or corrupt


I'm essentially trying to package the asset inside of my compiled binary.  I'm sure that I'm most likely using the methods or language conventions improperly.  I assume that the data I'm sending is not in a correct format for the LoadFromMemory method to understand, but I'm not exactly sure what I'm doing wrong.

Thanks for any help!

34
System / Callback a method inside of a class with sf::Thread?
« on: October 16, 2011, 01:30:13 am »
I've tried many different scenarios, but I can't seem to figure out.  Here's a basic example if what I'd like to do:

Code: [Select]

class Test
{
private:
ThreadHandle();
//
public:
Test();
void setup();
//
};


void Test::setup()
{
sf::Thread TestThread(&ThreadHandle);
TestThread.Launch();
}


I've also tried setting up the "TestThread" object in the header file, but it alerts me that "ThreadHandle" is not a data type.

Thanks for any help!

35
Audio / Music only plays if directly preceded by a loop? (SFML2)
« on: September 16, 2011, 09:32:30 pm »
I have this bit here:

Code: [Select]

sf::Music test;

if (!test.OpenFromFile("test.ogg"))
{
std::cout << "Oh No!" << std::endl;
}
elsae
{
test.Play();
}


Which doesn't play the audio!  However, if I append this right after "test.Play();"

Code: [Select]

for (;;);


The Music plays as expected.  I've also tried adding test.Play(); in the ::update(); method that's called every frame.

What could the issue be?  Thanks for any help!

36
General / SFML2 installation on Linux?
« on: September 16, 2011, 05:34:28 am »
I've moved the SFML directory inside of the "include" folder to /usr/include/c++/4.4, as well as all of the .a lib files into /usr/lib/gcc/i486-linux-gnu.  Are these locations the appropriate place for the files to reside?

Here's the bit that I'm testing:
Code: [Select]

#include "SFML/Graphics.hpp"

const int SCREEN_WIDTH = 550;
const int SCREEN_HEIGHT = 400;
const int SCREEN_BPP = 32;

sf::RenderWindow App;

int main(int argc, char** argv)
{
App.Create(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP), "Testing!");

while (App.IsOpened())
{
sf::Event event;
while (App.PollEvent(event))
{
switch (event.Type)
{
case sf::Event::Closed:
App.Close();
break;
}
}
}
return EXIT_SUCCESS;
}


I'm compiling with:
Code: [Select]

g++ -o test test.cpp -lsfml-graphics -lsfml-window


This is what is returned:
Code: [Select]

/tmp/ccrxrxoF.o: In function `main':
test.cpp:(.text+0x87): undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
test.cpp:(.text+0xc3): undefined reference to `sf::Window::Create(sf::VideoMode, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long, sf::ContextSettings const&)'
test.cpp:(.text+0x125): undefined reference to `sf::Window::Close()'
test.cpp:(.text+0x139): undefined reference to `sf::Window::PollEvent(sf::Event&)'
test.cpp:(.text+0x149): undefined reference to `sf::Window::IsOpened() const'
/tmp/ccrxrxoF.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x17c): undefined reference to `sf::RenderWindow::RenderWindow()'
test.cpp:(.text+0x181): undefined reference to `sf::RenderWindow::~RenderWindow()'
collect2: ld returned 1 exit status


What could the issue be?  Thanks for any help!

37
Graphics / Additional Windows?
« on: September 04, 2011, 03:40:13 am »
I have this bit here in a separate source file:
Code: [Select]

#include "SFML/Graphics.hpp"
#include "WindowTest.h"

const int SCREEN_WIDTH = 550;
const int SCREEN_HEIGHT = 400;
const int SCREEN_BPP = 32;

sf::RenderWindow Window;

int WindowTest()
{
Window.Create(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP), "LOL", !sf::Style::Resize | sf::Style::Close);

while (Window.IsOpened())
{
sf::Event event;
while (Window.PollEvent(event))
{
switch (event.Type)
{
case sf::Event::Closed:
Window.Close();
break;
}
}
}

return EXIT_SUCCESS;
}


I include it's header file, and I call "WindowTest();" whenever I'd like to open it.  However, currently this doesn't work too well.  The window does open, but it's occasionally a little shaky whenever I move it around.  I also can't close the first window until I close this window, and the first window's "Close" button blinks a little bit too.

Should I handle the second window's logical in a separate thread?  Or is there a better method to have multiple windows?

Thanks for any help!

38
General / sf::View offset?
« on: August 28, 2011, 09:34:52 am »
Thanks!  That's exactly what I was going for.  If anyone in the future is looking for a solution to a similar problem:

Code: [Select]

sf::Vector2f MousePos = App.ConvertCoords(event.MouseButton.X, event.MouseButton.Y, camera);

if (MousePos.x >= pos.x && MousePos.x < pos.x + 32 &&
       MousePos.y >= pos.y && MousePos.y < pos.y + 32)

39
General / sf::View offset?
« on: August 28, 2011, 08:12:41 am »
Currently I'm working with this:
Code: [Select]

if (event.MouseButton.Button == 0)
{
for (int i = 0; i < blocks.size(); i++)
{
sf::Vector2f pos = blocks[i].GetPosition();

if (event.MouseButton.X >= pos.x && event.MouseButton.X < pos.x + 32 &&
event.MouseButton.Y >= pos.y && event.MouseButton.Y < pos.y + 32)
{
blocks.erase(blocks.begin() + i);
break;
}
}
}


Which works pretty well!  However, whenever I alter the position of my "camera" view, of course it doesn't work anymore.  Is there an offset I could apply to the condition to correct the problem?

Also, would it be better to check sprite.GetPosition().X and .Y instead of creating a Vector2f each time?  Or is it not really too significant?

Thanks for any help.

40
General / Smoothest methods for movement?
« on: August 23, 2011, 02:02:04 am »
Inside of main.cpp file:
Code: [Select]

App.SetFramerateLimit(60);


Inside of my player.cpp file:
Code: [Select]

//speed = 1.0f;
//fric = 1.1f;
void Player::update()
{
App.Draw(self);

grav++;
y += grav;

if (right == true && left == false)
{
self.FlipX(false);
xs += speed;
}

if (right == false && left == true)
{
self.FlipX(true);
xs -= speed;
}

xs /= fric;
x += xs;

while (y >= 500)
{
y--;
grav = 0;
canJump = true;
}

self.SetPosition(x, y);
}


Currently the movement feels very choppy.

I've also tried experimenting around with not setting a Framerate Limit, and multiplying ElapsedTime with the values, but I've received different results on different machines.

I'm also aware that the while loop is most likely causing some of the choppy movement as well.  What other methods could I implement that would be more optimal?  It's also just meant for a pseudo ground at the moment.

I'm sure that what I'm currently doing isn't too practical, but I'd certainly like to learn how to make it more practical!  How do you guys like to setup your movement to make it smooth?

41
General / Passing "App" to my class's constructor? (solved!)
« on: August 21, 2011, 06:50:48 pm »
If anyone is looking for a solution to a similar problem, here's what I implemented:

player.h
Code: [Select]

public:
void update(sf::Sprite &spr_player);
...
//


player.cpp
Code: [Select]

void Player::update(sf::Sprite &spr_player)
{


main.cpp
Code: [Select]

bool setup()
{
if (!img_player.LoadFromFile("res/img/char/player.png"))
{
return false;
}

spr_player.SetTexture(img_player);

return true;
}

int main(int argc, char** argv)
{
...
if (setup() == false)
{
return EXIT_FAILURE;
}

Player player(20, 20);

while (App.IsOpened())
{
..
App.Clear();
App.Draw(spr_player);

player.update(spr_player);
App.Display();
}

return EXIT_SUCCESS;
}


I'm also probably going to create an array that holds all of the sprites that need displaying, and call App.Draw(spriteBatch[index]); in a for loop.

42
General / Passing "App" to my class's constructor? (solved!)
« on: August 21, 2011, 05:19:09 pm »
Quote from: "jkalmeij"
Your error happens to me sometimes when I'm typing  (while it's probably meant to be a sf::Sprite?).


Wow, that was it.  lol I can't believe I overlooked that I gave self the wrong type in my player.h file.  There currently are not any errors, however nothing is displayed.  Here's my Player's constructor:

Code: [Select]

Player::Player(float getX, float getY, sf::Texture getImg)
{
sf::Sprite self(getImg);
x = getX;
y = getY;

self.SetPosition(getX, getY);
}


(I also tried using .SetTexture(); as well)

main.cpp
Code: [Select]

sf::Texture img_player;

if (!img_player.LoadFromFile("res/img/char/player.png"))
{
return EXIT_FAILURE;
}

Player player(20, 20, img_player);

...

while (App.IsOpened())
{

App.Clear();
player.update(App);
App.Display();
}


Also, if it's helpful:
player.h
Code: [Select]

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

class Player
{
private:
float x, y, xs, ys, speed, fric;
bool right, left;
sf::Sprite self;
//
public:
Player(float getX, float getY, sf::Texture getImg);
void input(sf::Event event);
void update(sf::RenderWindow &App);
//
};


If I replaced it with this bit:
main.cpp
Code: [Select]

sf::Texture img_player;

if (!img_player.LoadFromFile("res/img/char/player.png"))
{
return EXIT_FAILURE;
}

sf::Sprite spr_player(img_player);
spr_player.SetPosition(10.0f, 10.0f);
while (App.IsOpened())
{

App.Clear();
//player.update(App);
App.Draw(spr_player);
App.Display();
}


The sprite is displayed on the screen.  What could I be doing wrong?

43
General / Passing "App" to my class's constructor? (solved!)
« on: August 21, 2011, 11:56:29 am »
I was able to eliminate all of the errors.  Currently I'm trying with:

player.h
Code: [Select]

public:
void update(sf::RenderWindow &App);


player.cpp
Code: [Select]

Player::Player(float getX, float getY, sf::Texture getImg)
{
sf::Sprite self(getImg);
...
}

void Player::update(sf::RenderWindow &App)
{
App.Draw(self);
}


main.cpp
Code: [Select]

App.Clear();
player.update(App);
App.Display();


The "App.Draw(self);" is causing the issue.  Without it, the code compiles without any errors.  Here are the errors returned:
Code: [Select]

player.cpp: In member function 'void Player::update(sf::RenderWindow&)':
player.cpp:37:15: error: no matching function for call to 'sf::RenderWindow::Draw(sf::Texture&)'


Also, I do have a really interesting C++ book that I like to read through sometimes.  Do you have any recommendations?

44
General / Passing "App" to my class's constructor? (solved!)
« on: August 21, 2011, 10:39:53 am »
Thanks for the help again!  Could you please elaborate on what you mean by initialization lists?  I've found a few articles, and it looked like they were pointing towards something like this:

player.h
Code: [Select]

public:
Player(sf::RenderWindow &getApp);
Player();


player.cpp
Code: [Select]

Player::Player(sf::RenderWindow &getApp) : App(&App)


I'm sure that what I'm currently trying to do looks pretty ridiculous, it certainly doesn't feel right.

45
General / Passing "App" to my class's constructor? (solved!)
« on: August 21, 2011, 09:14:46 am »
Quote from: "OniLink10"
You can't copy windows, which is what you're doing. Pass a reference to the window instead.


Thanks for the reply!  Here's what I'm currently trying:

player.h file
Code: [Select]

class Player
{
private:
sf::RenderWindow App;
..
//
public:
Player(sf::RenderWindow &getApp);
...
//
};


player.cpp
Code: [Select]

Player::Player(sf::RenderWindow &getApp)
{
App = getApp;
...
}


main.cpp
Code: [Select]

Player player(&App);


However, it appears that essentially the same message from the original post is returned.  What could the issue be?

Pages: 1 2 [3] 4
anything