Pages:
Author

Topic: The Coding Thread - page 2. (Read 2753 times)

legendary
Activity: 1540
Merit: 1000
June 03, 2013, 04:06:09 AM
#33
Okay I have partially got things working, my only problem now is that I'm only able to specifically drag my sprite to the x and y coordinates of the cursor rather than all around.

Quote

    while (window.isOpen())
    {

    sf::Event event;
    while (window.pollEvent(event))

        if (sf::Mouse::isButtonPressed ( sf::Mouse::Left ) )


        {
            spritename1.move ( sf::Mouse::getPosition( window ).x >50, sf::Mouse::getPosition( window ).y >50 );
        }

legendary
Activity: 1540
Merit: 1000
June 02, 2013, 12:31:50 PM
#32
I found out in an old post finally how to do it

Correct snytax is:

Quote

    sf::Event event;
    while (window.pollEvent(event))

        if (sf::Mouse::isButtonPressed ( sf::Mouse::Left ) )


        {
            spritename1.move ( sf::Mouse::getPosition( window ).x, sf::Mouse::getPosition( window ).y );
        }

        {
            if (event.type == sf::Event::Closed)
                window.close();
            }



I was using the command separately and not in the right order, my only problem now is the warping.
legendary
Activity: 1540
Merit: 1000
June 01, 2013, 08:03:00 AM
#31
I'm working through some simple point and click mouse events and stuff but does anyone have any tips for how I could get the move command to work or if that's what is necessary at all? What I'm trying to do is to get my sprite to move to the position of where I left click like an RTS or point and click RPG, I haven't had problems with keyboard commands so far but this is causing problems for me.

Quote


    while (window.isOpen())
    {

    sf::Event event;
    while (window.pollEvent(event))

    if ( event.type == sf::Event::MouseButtonPressed )

    {

    if ( event.mouseButton.button == sf::Mouse::Left )

        {

            sf::Event.mouseButton.x << std::end1;
            sf::Event.mouseButton.y << std::end1;
            spriteplayerstanding1.move ( MouseButtonPressed );
        }

        {
            if (event.type == sf::Event::Closed)
                window.close();
            }

legendary
Activity: 1176
Merit: 1280
May Bitcoin be touched by his Noodly Appendage
May 27, 2013, 07:54:34 AM
#30
Same happened for me
I never managed to get SDL working even for small tasks whereas SFML is a pleasure to use
legendary
Activity: 1540
Merit: 1000
May 27, 2013, 05:20:35 AM
#29
I've been through some changes, because SDL just seems to be filled with outdated tutorials and such, I really can't be bothered combing through the code and fixing problem after problem that's completely unncessary. So I went and looked at SFML which seems to be much better supported and low and behold the commands provided in most tutorials work properly, I've been able to even get some basic interaction going with it. I'll have to have a think now on what I'm going to make and I have a basic platformer in mind, next up to learn will be sprites and collision I guess.

Quote


#include

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "Lethn 2D Engine");
    sf::CircleShape circle1 ( 20 );
    circle1.setPosition( 30, 30 );
    sf::CircleShape circle2 ( 20);
    circle1.setPosition( 200, 260 );
    circle2.setPosition( 600, 260 );
    circle1.setFillColor( sf::Color::Red );
    circle1.setOutlineColor( sf::Color::Magenta );
    circle1.setOutlineThickness( 3 );
    circle2.setFillColor( sf::Color::Blue );
    circle2.setOutlineColor( sf::Color::Cyan );
    circle2.setOutlineThickness( 3 );

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))


            if ( sf::Keyboard::isKeyPressed( sf::Keyboard:: W  ) )


            {
                circle1.move ( 0, -5 );
            }

            else if ( sf::Keyboard::isKeyPressed( sf::Keyboard:: A  ) )

            {
                circle1.move ( -5, 0 );
            }

            else if ( sf::Keyboard::isKeyPressed( sf::Keyboard:: D  ) )

            {
                circle1.move ( 5, 0 );
            }

            else if ( sf::Keyboard::isKeyPressed( sf::Keyboard:: S  ) )

            {
                circle1.move ( 0, 5 );
            }
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }


        window.clear();
        window.draw(circle1);
        window.draw(circle2);
        window.display();
    }

    return 0;
}


legendary
Activity: 1540
Merit: 1000
May 19, 2013, 05:53:37 AM
#28
Finally! Got it sorted! Image came out a bit weird but I think that's more to do with the resolution I used, thanks for the help again, here's the now updated and working code.

Quote

#ifdef __cplusplus
    #include
#else
    #include
#endif

#include

int main( int argc, char* args[] )

{

SDL_Init; ( SDL_INIT_EVERYTHING );
SDL_Surface* screen = NULL;
SDL_Surface* test = NULL;

screen = SDL_SetVideoMode( 500, 500, 32, SDL_SWSURFACE );


test = SDL_LoadBMP( "test.bmp" );

SDL_BlitSurface( test, NULL, screen, NULL );

SDL_Flip( screen );
SDL_Delay( 2000 );

SDL_FreeSurface( test );

SDL_Quit();

   return 0;
}


For future reference I think the biggest problem was  SDL_Init( SDL_INIT_EVERYTHING ); because on the tutorial he put that after the SDL_surface commands rather than before.
legendary
Activity: 1540
Merit: 1000
May 19, 2013, 05:41:53 AM
#27
Alright, thanks for the help, I'll steamroll through this like I've been doing with OpenGL Tongue just need to put the time in.
legendary
Activity: 4494
Merit: 3178
Vile Vixen and Miss Bitcointalk 2021-2023
May 19, 2013, 05:39:47 AM
#26
wow thanks a lot Foxpup, that's really interesting, he didn't seem to mention any of this in the troubleshooting for it and so on >_< and this is supposed to be a beginners tutorial lol! Tongue I copied it exactly just to see whether I was forgetting or something, looks like there are bits wrong with his code but I'll double check again and it looks like there are.
It's for beginning game programmers, ie, programmers who are experienced at writing other applications and wish to move on to the more specialised field of game programming. This tutorial assumes basic knowledge of C++. If you have never done much programming in C++ before, you should probably start with the basics before continuing.

Do you know of any up to date tutorials that won't bugger up on the latest version of SDL? I particularly like this library because it means I have to go and make some art assets right away which is nice, anime characters time woot! Cheesy
I'm pretty sure this tutorial is up to date with SDL 1.2 (the latest stable version). SDL 2 has a lot of changes, but I think it's mostly the addition of OpenGL and haptic support, I'm not sure how much (if any) of the 2D graphics stuff is being changed. Anyway, SDL 2 hasn't been officially released yet, so it's a moot point.
legendary
Activity: 1540
Merit: 1000
May 19, 2013, 04:49:22 AM
#25
wow thanks a lot Foxpup, that's really interesting, he didn't seem to mention any of this in the troubleshooting for it and so on >_< and this is supposed to be a beginners tutorial lol! Tongue I copied it exactly just to see whether I was forgetting or something, but it looks like there are bits wrong with his code, I'll double check again and it looks like there are.

Do you know of any up to date tutorials that won't bugger up on the latest version of SDL? I particularly like this library because it means I have to go and make some art assets right away which is nice, anime characters time woot! Cheesy
legendary
Activity: 4494
Merit: 3178
Vile Vixen and Miss Bitcointalk 2021-2023
May 19, 2013, 01:24:12 AM
#24
error: 'args' has not been declared
There must be no comma between char* and args[], as they're part of the same declaration (that you have a array of pointers called "args" of type "char"). With the comma, it thinks you have an anonymous pointer of type "char", and something completely separate called "args", though it doesn't know what this thing called "args" is supposed to be, hence the error.

error: 'SDL' was not declared in this scope
error: expected ';' before 'Init'
You need an underscore between SDL and Init, with no spaces. "SDL_Init" is one function. With a space, it thinks they are two separate functions called "SDL" and "Init" (which don't even exist, causing the first error), and expects a semicolon between them (you always need a semicolon between statements), which is the second error.

error: 'screen' was not declared in this scope
You forgot to declare it (or you declared it in the wrong place). You should have "SDL_Surface* screen = NULL;" immediately after (or immediately before) "SDL_Surface* test = NULL;".
legendary
Activity: 1540
Merit: 1000
May 18, 2013, 03:19:58 PM
#23
Quote

#ifdef __cplusplus
    #include
#else
    #include
#endif

#include

int main ( int argc, char*, args[] )
{


SDL_Surface* test = NULL;
SDL Init ( SDL_INIT_EVERYTHING );
screen = SDL_SetVideoMode ( 640, 480, 32, SDL_SWSURFACE );
test = SDL_LoadBMP ("Test.bmp");
SDL_BlitSurface (test, NULL, screen, NULL)
SDL_Flip ( screen );
SDL_Delay ( 2000 );
SDL_FreeSurface( test );
SDL_Quit();

return 0;

 }


From various posts and word on the internet I've found that SDL is apparently the library to use, I can see it combines it's code really well and you don't have to worry about downloading extensions for keyboard input like with GLFW so that's already a plus but, I've come across a problem. I'm following the tutorials here: http://lazyfoo.net/SDL_tutorials/lesson01/windows/codeblocks/index.php but the code won't compile! It's strange because the commands were registered by Codeblocks ( IDE I'm using ) and when I started up the SDL sample the code works absolutely fine.

Anyone got any advice? I'm going to get on this properly because I think SDL is a pretty nice library but I suspect I'll have to do some digging around like when I was just compiling basic OpenGL, I'm wondering if the code for this tutorial is out of date because the version of the library it said to download was much earlier, it's happened before with previous coding.

Quote

error: 'args' has not been declared
In function 'int SDL_main(int, char*, int*)'
error: 'SDL' was not declared in this scope
error: expected ';' before 'Init'
error: 'screen' was not declared in this scope

||=== Build finished: 4 errors, 0 warnings (0 minutes, 0 seconds) ===|


I think I'm just going to have to do what I did before and work with the sample and learn the code that way so Codeblocks doesn't break.
legendary
Activity: 1540
Merit: 1000
May 18, 2013, 06:28:41 AM
#22
I found a very nice tutorial on naming objects in OpenGL so you can start interacting with the OpenGL graphics you make, wish all tutorials were as detailed as this.

http://www.lighthouse3d.com/opengl/picking/
legendary
Activity: 1540
Merit: 1000
May 17, 2013, 06:33:03 PM
#21
LOL After all that raging I found that the problem was that I had downloaded 64 bit GLFW binaries instead of 32 bit, I feel like a noob even after all that coding Cheesy

Now I can begin work on my keyboard and mouse interaction Cheesy
staff
Activity: 3290
Merit: 4114
May 17, 2013, 01:50:09 PM
#20
print("We want a sub-forum")
user_input = input("What do you say staff?")
legendary
Activity: 1540
Merit: 1000
May 17, 2013, 01:00:39 PM
#19
Does anyone know of any up to date syntax for GLFW keyboard and mouse input? Or would you recommend something else? I'm searching around but I think I could use some help on this one.
legendary
Activity: 1540
Merit: 1000
May 16, 2013, 09:48:06 PM
#18
Quote
           
            glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
            glClear (GL_COLOR_BUFFER_BIT);

            glPushMatrix ();
            glTranslatef (-0.2f, 0.0f, 0.0f);
            glRotatef(theta, 0.0f, 1.0f, 0.0f);
            glBegin (GL_QUADS);
  
                              
                              glVertex3f (0.0f, -0.1f, 0.0f);
                              glVertex3f (-0.1f, 0.0f, 0.0f);
                              glVertex3f (0.0f, 0.1f, 0.0f);
                              glVertex3f (0.1f, 0.0f, 0.0f);
            glEnd ();
            glPopMatrix ();
            
            glPushMatrix ();
            glTranslatef (0.1f, 0.0f, 0.0f);
            glRotatef(theta, 0.0f, 1.0f, 0.0f);
            
            glBegin (GL_QUADS);

                              
                              glVertex3f (0.0f, -0.1f, 0.0f);
                              glVertex3f (-0.1f, 0.0f, 0.0f);
                              glVertex3f (0.0f, 0.1f, 0.0f);
                              glVertex3f (0.1f, 0.0f, 0.0f);
                              
            glEnd ();
            glPopMatrix ();

            SwapBuffers (hDC);

            theta += 1.0f;
            Sleep (1);
        }
    }


Must make it so I can click and drag these spinning squares Cheesy
legendary
Activity: 1540
Merit: 1000
May 16, 2013, 11:34:08 AM
#17
legendary
Activity: 1540
Merit: 1000
May 16, 2013, 11:24:46 AM
#16
Bah, does anyone know some good tutorials that show you how to combine OpenGL and C++ while I'm searching for them myself? The OpenGL tutorials are great and I have an easy time drawing basic stuff on it now but I need to look up how to properly combine everything so I can interact with the shapes I make Cheesy
newbie
Activity: 56
Merit: 0
May 15, 2013, 06:53:29 PM
#15
Nobody here's programming in LOLcode?  Seriously?  You should all try it.

Wikipedia: http://en.wikipedia.org/wiki/LOLCODE

The Hello World program:

HAI
CAN HAS STDIO?
VISIBLE "HAI WORLD!"
KTHXBYE


As you can see, its insane efficiency at any task combined with its extreme brevity makes it a must for any real coding project.
legendary
Activity: 1540
Merit: 1000
May 15, 2013, 05:58:48 PM
#14
Lets spam code all over this thread so the mods know there's demand for a category lolollool Cheesy
Pages:
Jump to: