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

Pages: [1] 2 3 4
1
Graphics / Lights with blending, doing something wrong.
« on: January 23, 2014, 12:38:54 pm »
I'm trying to implement some basic light using blending. It's based of this https://dl.dropboxusercontent.com/u/36451301/ld/ld27/index.html


I'm trying to implement it by doing it in a few small steps:
Quote
You must do it this way:
- fill a render-texture (which covers the whole window) with the dark color
- draw your light(s) to the render-texture with sf::BlendAdd
- draw the render-texture on top of your scene with sf::BlendMultiply

but for some reason the only thing I get is an completely black screen, I'm not sure what exactly I'm doing wrong. If I use Multiply when drawing the lightmap-buffer it litterly only shows black.

Here is a minimal code example:
int main()
{
        sf::Sprite s_lightmap;
        sf::Sprite s_light;

        sf::RenderTexture t_lightmap;
        sf::Texture t_light;

        t_lightmap.create(800,600);
        t_light.loadFromFile("light.png");

        sf::Color ambient(0,0,0,255);
        sf::Color lightColor(255,0,0,178);

        s_light.setTexture(t_light);
        s_light.setColor(lightColor);

        sf::RenderWindow window(sf::VideoMode(800,600,32),"Window");
        sf::Event event;

        while(window.isOpen())
        {
                while(window.pollEvent(event))
                {

                }
                window.clear(sf::Color::Blue);
                t_lightmap.clear(ambient);
                t_lightmap.draw(s_light, sf::BlendMode::BlendAdd);
                s_lightmap.setTexture(t_lightmap.getTexture());
                window.draw(s_lightmap, sf::BlendMode::BlendMultiply);
               
                window.display();
        }

        return 0;
}
 

2
SFML wiki / Is the page still around?
« on: December 06, 2013, 12:13:46 am »
I'm trying to hunt down the:  "[Tutorial]Stock all your resources in a single DAT file" but it appears as the links are broken. Is the tutorial still around somewhere? 

3
General / [SOLVED] Scaling the window and mouse offset issues
« on: November 13, 2013, 10:04:53 am »
SOLVED EDIT:
Silly me not properly checking the sf::View tutorial. The answer lies in converting between pixel to world coordinates!

http://www.sfml-dev.org/tutorials/2.0/graphics-view.php#showing-more-when-the-window-is-resized

ORIGINAL POST:

I'm currently working on my Zombie shooter that was originally for the GameBoy Jam. The resolution is 160x144px which is quite small, however we are allowed to scale the game (not the graphics itself) to make it larger.

sf::RenderWindow window(sf::VideoMode(160*4, 144*4, 32), "Doki Doki DX", sf::Style::Titlebar);
window.setView( sf::View(sf::FloatRect(0,0,160,144)) );
 

The code above is my window scaling code. It works flawlessly except the mouse has a weird offset from the REAL mouse which is a problem since you aim your gun with the mouse and will most likely open another app or click outside of the window seeing as it's not actually there.



In this picture the windows mouse cursor is actually outside of the window, whilst the game cursor (that takes the position of the cursor relative the window) is inside of the window. I can't properly move the mouse around without sliding outside of the window.

I have never scaled a game before and I'm not sure how to "fix" this?

In addition i need to be able to follow my character with a camera however the "mouse" don't keep it's relative position towards the character. I'm not really sure how to solve this, I'v been at it for a while (days) but I'm not sure how to figure out the new position of the...mouse.

I thought getting the new (relative to window) position would have returned the new position relative to where the current view is but that's not how it works.

4
#include "TextureLocator.hpp"

sf::Texture TextureLocator::textures[TIDS::UNIQUE_TIDS] = {sf::Texture()};

bool TextureLocator::init() {
        TextureLocator::textures[TIDS::PLAYER].create(5,5);
        TextureLocator::textures[TIDS::BULLET].create(1,1);
        TextureLocator::textures[TIDS::ENEMY].create(4,4);
        TextureLocator::textures[TIDS::EXPLOSION].create(16,16);
        return true;
}

sf::Texture& TextureLocator::get(TIDS id) {
        return textures[id];
}
 

I get a runtime error, why? Isn't this legal?
Quote
First-chance exception at 0x779422D2 (ntdll.dll) in Leklåda.exe: 0xC0000005: Access violation writing location 0x00000004.
Unhandled exception at 0x779422D2 (ntdll.dll) in Leklåda.exe: 0xC0000005: Access violation writing location 0x00000004.

These are the errors I get. I think they are related to initializing the static array in the .cpp file above. Feels pretty weird to me. Anyone want to shine some light on this.

Here is the callstack as well:

Quote
   ntdll.dll!779422d2()   Unknown
    [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]   
    Leklåda.exe!sf::priv::MutexImpl::lock(void)   Unknown
    Leklåda.exe!sf::Mutex::lock(void)   Unknown
    Leklåda.exe!sf::Lock::Lock(class sf::Mutex &)   Unknown
    Leklåda.exe!sf::GlResource::GlResource(void)   Unknown
    Leklåda.exe!sf::Texture::Texture(void)   Unknown
>   Leklåda.exe!`dynamic initializer for 'TextureLocator::textures''() Line 3   C++
    msvcr110d.dll!_initterm(void (void) * * pfbegin, void (void) * * pfend) Line 889   C
    Leklåda.exe!__tmainCRTStartup() Line 460   C
    Leklåda.exe!mainCRTStartup() Line 377   C
    kernel32.dll!75a2336a()   Unknown
    ntdll.dll!77959f72()   Unknown
    ntdll.dll!77959f45()   Unknown


5
General / Re: Running my game in Linux
« on: September 11, 2013, 03:35:28 pm »
Yeah found it! Thanks!

I have a side question, but when I want to shipp my game for Linux - how does one statically link? Because right of now, I get errors when trying ( even though I have compiled them as static ). ( Undefined references to X ). Or I heard there is a -R command you can send to the linker which forces the binary to look at a specific place. Is that how you do it?

6
General / Re: Running my game in Linux
« on: September 11, 2013, 02:55:12 pm »
which IDE are you using? isn't there an option to build and run?
the .so files are created when you compile SFML. they are in the folder /lib inside your build directory.
try copy/pasting them to your project (or executable) directory

I'm using CodeLite, which when I install it is given a locked "root"-access only (  hence I need to start it with sudo command via terminal ). It works super fine, it's just that the .so files aren't located ( I'm linking towards a custom path /home/SFML2.1/lib ). I tried the "make install" but that didn't work either ( though they are installed, but apparently not in the right map ).

I tried adding the binary together with the .dll's in a seperate map, but it didn't work...I feel that I need to add them to some random map in linux, but I don't know which.

7
General / Running my game in Linux
« on: September 11, 2013, 12:49:11 pm »
I'm currently running Linux ( Ubuntu ) to be specific and I'v managed to build SFML2.1 from the sources. My only problem now is that I'm not sure how to run my binary ( it compiles just fine ).

It complains about missing the specific .so files - I'm guessing the binary dosen't look in the right place. I know this isn't technically speaking an issue of SFML but I figured ( since it's related ) people here would know what to do.

I followed this guide here about compiling and installing sfml om my system:
http://sfmlcoder.wordpress.com/2011/08/16/building-sfml-2-0-with-make-for-gcc/

So, anyone know how to make sure my binary finds my .so files?

( I know I can do LD_LIBRARY_PATH if I run it from the terminal but I want to be able to just "Run" it like normal without the terminal, so there got to be a map )

8
General / I'm getting errors when trying to build sfml2 in Ubuntu
« on: May 10, 2013, 01:17:54 pm »
I recently merged from Windows to Ubuntu and so far it's going fairly well. Now I'm trying to set up a development environment thus I need to freshly build SFML and I was following this guide http://sfmlcoder.wordpress.com/2011/08/16/building-sfml-2-0-with-make-for-gcc/:

I installed all the dependencies and ran cmake and then make and all goes well until it's time to build the sound files. I get an error:
Quote
[ 87%] Building CXX object src/SFML/Audio/CMakeFiles/sfml-audio.dir/SoundFile.cpp.o
/home/vkarlsson/Skrivbord/SFML-master/src/SFML/Audio/SoundFile.cpp: In static member function ‘static sf_count_t sf::priv::SoundFile::Stream::read(void*, sf_count_t, void*)’:
/home/vkarlsson/Skrivbord/SFML-master/src/SFML/Audio/SoundFile.cpp:388:56: error: no matching function for call to ‘min(sf_count_t&, sf::Int64)’
/home/vkarlsson/Skrivbord/SFML-master/src/SFML/Audio/SoundFile.cpp:388:56: note: candidates are:
In file included from /usr/include/c++/4.7/bits/char_traits.h:41:0,
                 from /usr/include/c++/4.7/string:42,
                 from /home/vkarlsson/Skrivbord/SFML-master/src/SFML/Audio/SoundFile.hpp:34,
                 from /home/vkarlsson/Skrivbord/SFML-master/src/SFML/Audio/SoundFile.cpp:28:
/usr/include/c++/4.7/bits/stl_algobase.h:187:5: note: template<class _Tp> const _Tp& std::min(const _Tp&, const _Tp&)
/usr/include/c++/4.7/bits/stl_algobase.h:187:5: note:   template argument deduction/substitution failed:
/home/vkarlsson/Skrivbord/SFML-master/src/SFML/Audio/SoundFile.cpp:388:56: note:   deduced conflicting types for parameter ‘const _Tp’ (‘long int’ and ‘sf::Int64 {aka long long int}’)
In file included from /usr/include/c++/4.7/bits/char_traits.h:41:0,
                 from /usr/include/c++/4.7/string:42,
                 from /home/vkarlsson/Skrivbord/SFML-master/src/SFML/Audio/SoundFile.hpp:34,
                 from /home/vkarlsson/Skrivbord/SFML-master/src/SFML/Audio/SoundFile.cpp:28:
/usr/include/c++/4.7/bits/stl_algobase.h:233:5: note: template<class _Tp, class _Compare> const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
/usr/include/c++/4.7/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
/home/vkarlsson/Skrivbord/SFML-master/src/SFML/Audio/SoundFile.cpp:388:56: note:   deduced conflicting types for parameter ‘const _Tp’ (‘long int’ and ‘sf::Int64 {aka long long int}’)
make[2]: *** [src/SFML/Audio/CMakeFiles/sfml-audio.dir/SoundFile.cpp.o] Error 1
make[1]: *** [src/SFML/Audio/CMakeFiles/sfml-audio.dir/all] Error 2
make: *** [all] Error 2

And I'm not sure how to proceed, I though someone here might know.

Kind regards Moonkis

9
General / Re: Collision detection and sliding alongside walls.
« on: April 13, 2013, 12:56:23 am »
I'm guessing is a 2D platformer, as you never said if it's a top down camera or what..

just when the character is falling and next to a wall? if you already have the collision, you are halfway there! you need to think how to SLOW THE DESCENT OF CHARACTER DOWN ;)

Aaaalso, I think you look into using gravity

I should have been a bit clearer about that, it's not a 2D platformer but a birdview(?) rougelike with free movement as opposed to a grid based one.

And I turned towards the forum because I have no idea how to implement it, I'v sketched with pen and papper, tried different approaches, this is where I came closes to a working collision detection between tiles and the player.


EDIT:
I manage to solve it by revamping the code  a bit, checking each axis seperatly:
Code: [Select]
void Player::update(float dt, const Tiles& tiles)
{
float x = m_x;
float y = m_y;

if( sf::Keyboard::isKeyPressed( sf::Keyboard::Up ) )
{
y -= m_speed;
}
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Down ) )
{
y += m_speed;
}
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Left ) )
{
x -= m_speed;
}
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Right ) )
{
x += m_speed;
}

// Find the nerest tiles around the player.
int startY = ( m_y - 32 ) / 32;
int startX = ( m_x - 32 ) / 32;
// We add 64 because we need to compensate the sprites width as well.
int endY = ( m_y + 64 ) / 32;
int endX = ( m_x + 64) / 32;

// Set up the movement variables.
bool moveX = true;
bool moveY = true;

// Iterate through the nerest tiles.
for( int sy = startY; sy < endY; sy++ )
{
for( int sx = startX; sx < endX; sx++ )
{
if( tiles[sx][sy] != 1 && tiles[sx][sy] != 5 )
{
// For each tile make a boundingbox.
sf::IntRect wall;
wall.top = sy * 32;
wall.left = sx * 32;
wall.width = 32;
wall.height = 32;

// Create two boundingboxes for the player, one for X-axis and one for Y-axis.
sf::IntRect xaxis(x+8,m_y+20,16,8);
sf::IntRect yaxis(m_x+8,y+20,16,8);

// If we intersect on the x-axis, prevent moving through the x-axis.
if( xaxis.intersects(wall) )
{
moveX = false;
}
// If we intersect on the y-axis, prevent moving through the y-axis.
if( yaxis.intersects(wall) )
{
moveY = false;
}
}
}
}
// If movement is true, then move accordingly.
if( moveX ) m_x = x;
if( moveY ) m_y = y;
}


10
General / [SOLVED]Collision detection and sliding alongside walls.
« on: April 12, 2013, 10:44:12 pm »
I'v been trying to get collision detection between the tiled world and my free moving objects to work, I'v been through MANY hiccups but I finally found a way to do the collision detection right, the only problem is I don't know how to make the player slide alongside a wall if he is moving in more than one direction and the other one is collision free.

This is what I have so far...it's working on the top and bottom walls but not the right and left:
void Player::update(float dt, const Tiles& tiles)
{
        float x = m_x;
        float y = m_y;
       
        if( sf::Keyboard::isKeyPressed( sf::Keyboard::Up ) )
        {
                y -= m_speed;
        }
        if( sf::Keyboard::isKeyPressed( sf::Keyboard::Down ) )
        {
                y += m_speed;
        }
        if( sf::Keyboard::isKeyPressed( sf::Keyboard::Left ) )
        {
                x -= m_speed;
        }
        if( sf::Keyboard::isKeyPressed( sf::Keyboard::Right ) )
        {
                x += m_speed;
        }
       
        /* Calculate the nerest tiles around the player. */
        int startY = ( m_y - 32 ) / 32;
        int startX = ( m_x - 32 ) / 32;
        int endY = ( m_y + 64 ) / 32;
        int endX = ( m_x + 64) / 32;
       
        for( int sy = startY; sy < endY; sy++ )
        {
                for( int sx = startX; sx < endX; sx++ )
                {
                        if( tiles[sx][sy] != 1 && tiles[sx][sy] != 5 )
                        {
                                sf::IntRect wall;
                                wall.top = sy * 32;
                                wall.left = sx * 32;
                                wall.width = 32;
                                wall.height = 32;
                                m_boundingbox.top = y+20;
                                m_boundingbox.left = x+8;
                                if(m_boundingbox.intersects(wall))
                                {
                                        sf::IntRect xaxis(x+8,m_y+20,16,8);
                                        sf::IntRect yaxis(m_x+8,y+20,16,8);
                                       
                                        if( !xaxis.intersects(wall) )
                                        {
                                                m_x = x;
                                        }
                                        else if( !yaxis.intersects(wall) )
                                        {
                                                m_y = y;
                                        }

                                        return;
                                }
                               
                        }
                }
        }
        m_x = x;
        m_y = y;
}
 



I'v been trying all day and I have no idea how to achieve this.

11
General / Re: I'm confused about collision detection.
« on: April 04, 2013, 06:32:33 pm »
There are tons of ways but if you are building a TILEbased game with a 2D array representing the position of the tiles then it's quite simple give that all the tiles are of the same size and shape.


With the camera you kinda calculate the offset and get an beginning position something like:

startX = static_cast<int>(camera.x / TILE_SIZE );

Then you can check between the boundaries of StartX and StartX + ScreenWidth/ TILE_SIZE


12
General / Re: I'm confused about collision detection.
« on: April 04, 2013, 04:38:53 pm »
bool Collision::IsCollided(Player *player, std::vector<Platform*> platformList)
Instead of passing it by value I suggest you pass it by (const) reference, because copying an entire vector of objects can be quite slow.


There are actually two parts when dealing with collisions, the first one is collision detection and the second one is collision response.

The reason why you can't move the player after it's first collision is because you don't move the player back until it's in a none collision phase, because you don't do that the player will always be in collision and not allowed to move.

This is commonly done by finding the intersection amount and moving the player back by that amount, in XNA you can get that information from the class, in SFML i think you will need to do it yourself, I imagine it to be something along the line of the delta between the player and platform.

if(Collision::IsCollided(player, currentLevel->GetAllPlatforms()))
I don't know what happens behind the scene here but going by the name of the function you should consider doing some culling so that you don't check for EVERY platform in the entire level, just the ones that has can be collided by the player ( i.e what is on screen ).

I'll leave the in depth information to the others!

13
That's not minimal. Read the link I gave you.

Also try other variants, like using a direct pointer instead of a function. Show the smallest possible code that still reproduces your problem, and show a single file that is self-contained, so that we can be sure there are no other issues in your code.

I'm sorry Nexus I should have been clearer in my opening post about the problem. Thank you for your help though and I'll check out map a bit more ( FYI, I am using RAII as much as possible, though I haven't made the move onto smart pointers yet. ).

That's not minimal. Read the link I gave you.
I think the problem here is, that one part needs to be build as library, he at least stated:
If I include the raw files i.e the headers and .cpp files to my project it works fine, loading and drawing.

So I'm guessing it could be a problem between static vs dynamic linking. It's usually never a good idea to mix those (except maybe C vs C++ libraries). So have you tried linking SFML & your lib dynamically or both statically?
Do you have a build script at hand, to create the library? I don't feel like writing one, but I'd gladly test things if there was one. :)

Btw. you should never use \ for paths, it should always be /. Windows doesn't have a problem with forward slashes. ;)

I was linking the executable statically towards SFML and dynamically towards my own library ( that linked statically towards SFML.... ).

I tried both statically and both dynamical and it worked flawlessly! Lesson learned, don't link libraries that have dependencies on each other differently.

Also:
Main.cpp
#include <stdio.h>

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

Jalle\Graphics.hpp:
#include <SFML\Graphics.hpp>
#include <string>
 

Does that mean you're also linking against SFML in the application itself?
Static linking SFML won't make any sense then...
Yes, I am ( or was ) linking statically towards SFML when compiling the library as well as when compiling the executable.

It made sense at the time xD
But if I don't link statically toward SFML when compiling the library I couldn't link towards it dynamically while linking towards SFML statically when building my application ...

14
Here is an minimal ( minimal ) example
Main.cpp:
#include <stdio.h>

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

int main(int argc, char **argv)
{
        sf::RenderWindow window;
        window.create(sf::VideoMode(600,400,32), "Window");
        sf::Event event;
        sf::Sprite sprite;
        sf::Texture* texture = loadAndReturn("victorsplash.png");
        sprite.setTexture(*texture);
        while( window.isOpen() )
        {
                while( window.pollEvent(event) )
                {
                       
                }
                window.clear(sf::Color::Black);
                window.draw(sprite);
                window.display();
        }
        delete texture;
        return 0;
}
 

Jalle\Graphics.hpp:
#ifndef _GRAPHICS_HPP
#define _GRAPHICS_HPP

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

sf::Texture* loadAndReturn(std::string file);

#endif
 

and Jalle\Graphics.cpp:
#include "Graphics.hpp"
#include <cstdio>

sf::Texture* loadAndReturn(std::string file)
{
        sf::Texture* texture = new sf::Texture();
        if( texture->loadFromFile(file) == false )
        {
                std::printf("Couldn't load file");
                delete texture;
                return nullptr;
        }
        return texture;
}
 

15
Trying something like this results in the same problem, basically returning a pointer will cause my error.
I'm sure the pointer itself is not the problem. Can you come up with a complete and minimal example? Are you sure the loading succeeds?
I could try to reduce it but it's pretty close to minimum.

Pages: [1] 2 3 4