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

Pages: [1] 2
1
General / Re: Game randomly no longer working
« on: February 17, 2015, 02:53:38 am »
Well I don't know what's going on now. I tried starting from scratch, and now nothing works. I created a fresh SFML project in Xcode using the template, which has always worked for me, but now when I run, the window opens and the sprite "cute_image" briefly shows up on the window and then the program crashes. It says there is a "EXC_BAD_ACCESS" on Thread 1 at the line "window.draw(sprite)".

What have I done wrong? I haven't changed any settings in the template or in Xcode as far as I'm aware. I haven't downloaded a new version of SFML either.

I have found why it wasn't working on Windows though: code::blocks won't properly execute std::uniform_real_distribution, which my code uses, even when I tell it to use C++11, so not sure how to get around that, but I guess I can just use 'rand()'.

2
General / Re: Game randomly no longer working
« on: February 10, 2015, 07:01:54 pm »
I have been, it is essentially just drawing a few sprites with one texture and is still returning weird memory issues in Xcode. All my other SFML projects that I haven't even opened in weeks now don't work either in Xcode, returning strange memory errors I have never encountered before. I have even't used the word "new" or used pointers in any of my code (have used references as parameters in methods).

SFML appears to be working fine on the Windows computer, so I will try to narrow it down on there if I can, but I don't just want to completely abandon ever using my laptop again to make SFML projects. Thus why I uploaded the files, I've eliminated everything, and along the way, every single error is memory related in Xcode. Also it makes no sense why in Xcode my sprites should be moving as my mouse moves, there is nowhere in my "main" that I call anything mouse related nor should they move if I am just pressing WASD to move the view.

3
General / Game randomly no longer working
« on: February 10, 2015, 05:55:14 am »
So I have been pulling hairs out trying to figure what has gone wrong. My game has been behaving as expected for at least a week and all of a sudden when I tried running it today, it acted out. It started randomly moving sprites all over the screen if I moved my mouse or pressed a key (it was designed to move the view only if WASD was pressed and it did do that up until today). Once I exited the program Xcode would spit out the same error: "memory read failed for 0x41a00000".

I tried making the same project on my Windows computer. Configured SFML for Code::Blocks and I know it works because I made some simple SFML games to test. This game compiles fine, but it just produces a blank white window that doesn't respond.

I am attaching the three files used since they are each around 200 lines long, so if anybody has any ideas that would be awesome thanks.

4
Graphics / Re: Mouse Drag Box
« on: January 05, 2015, 11:47:00 pm »
D'oh! I didn't realize I left my creation of the 'MouseEvent' object in the loop, come to my rescue again Ixrec, thanks again for like the millionth time haha.

Thanks as well eXpl0it3r, I reorganized the method as you suggested so I didn't have to use the real-time 'isButtonPressed' in the method and just the Pressed/Released events.

5
Graphics / Mouse Drag Box
« on: January 05, 2015, 07:39:44 pm »
So I am trying to implement a mouse drag box where as long as the mouse left-click is held, a box is drawn positioned at the point of the original click and drawn out from that original click to the mouse cursor's current position, like you would use in an operating system's file explorer to select multiple files or in a RTS game to select multiple units.

My implementation below somewhat works with this problem: it draws a rectangle positioned at (0,0), not the starting click position, and draws out to where the mouse is currently, however, it doesn't fully draw it, it just flashes briefly (and doesn't even fully draw, it draws like a very random portion of it) and disappears when I'm no longer dragging the mouse.

The latter I'm guessing is because I'm using 'sf::Event::MouseMoved', but any other implementations I tried involving 'sf::Event::MouseButtonPressed' or 'sf::Event::MouseButtonReleased' using if, for, or while loops didn't even draw the rectangle at all, so I am at a loss. There are a few discussions I've seen in the forum, and I've tried implementing similarly or even exactly, and it doesn't produce any better of a result, if anything at all.

class MouseEvents
{
//will probably make all of these variables and methods static later
private:
    sf::Vector2i mousePosOnClick;
    sf::Vector2i mousePosOnHold;
   
public:
    sf::RectangleShape mouseDrawnBox;
   
    void mouseDrawBox(sf::Event &event)
    {
        if( (event.type == sf::Event::MouseButtonPressed) && (event.mouseButton.button == sf::Mouse::Left) )
        {
            mousePosOnClick.x = event.mouseButton.x;
            mousePosOnClick.y = event.mouseButton.y;
        }

        if( (event.type == sf::Event::MouseMoved) && (sf::Mouse::isButtonPressed(sf::Mouse::Left)) )
        {
            mousePosOnHold.x = event.mouseMove.x;
            mousePosOnHold.y = event.mouseMove.y;
           
            //I will add logic for negative values in 'size' later, just want something to work at all first
            sf::Vector2f size( (mousePosOnHold.x - mousePosOnClick.x), (mousePosOnHold.y - mousePosOnClick.y) );
            mouseDrawnBox.setPosition(mousePosOnClick.x, mousePosOnClick.y);
            mouseDrawnBox.setSize(size);
           
            mouseDrawnBox.setFillColor( sf::Color(0,0,255) );
        }
    }
};

int main()
{
while (window.isOpen())
    {
        sf::Event event;
        MouseEvents mouseEvent;
       
        while (window.pollEvent(event))
        {
            // Close window : exit
            if (event.type == sf::Event::Closed) {
                window.close();
            }

            // Espace pressed : exit
            if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
                window.close();
            }

            mouseEvent.mouseDrawBox(event);
        }

        window.clear();
        window.draw(mouseEvent.mouseDrawnBox);
        window.display();
    }
   
    return EXIT_SUCCESS;
}

6
General / Re: Diagonal movement with fixed speed
« on: January 05, 2015, 07:38:36 pm »
Ah that makes a lot more sense then, thank you so much. When I was using the real-time event, it would often not register a click or it would register multiple clicks for the few milliseconds I clicked.

I will have to give the distinction between real-time and event-based inputs some more study then, thanks again for all the help.

7
General / Re: Diagonal movement with fixed speed
« on: January 04, 2015, 09:40:39 pm »
Would you mind elaborating on the conceptual errors and architectural problems? What exactly is wrong with using my original code (with corrections using your suggestions) as such:

int main(...)
{
    //other stuff

    while (window.isOpen())
    {
        // Process events
        sf::Event event;
        while (window.pollEvent(event))
        {
            // Close window : exit
            if (event.type == sf::Event::Closed) {
                window.close();
            }

            // Espace pressed : exit
            if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
                window.close();
            }
           
            ship.isClickedOn(window);
            ship.beginMoving(window, event);
        }
       
        sf::Time deltaT = clock.restart();

        ship.moveTo(deltaT);

        window.clear();
        window.draw(ship);
        window.display();
    }
   
    return EXIT_SUCCESS;
}
 

The only distinction I see is that you used:
        if(event.type == sf::Event::MouseButtonPressed) {
            if(event.mouseButton.button == sf::Mouse::Left) {
Where instead I used:
        if( sf::Mouse::isButtonPressed(sf::Mouse::Left) ) {

Thanks for the idea of the unit vector, I was thinking of using the distance formula, normalization wasn't too far off I suppose haha.

8
General / Diagonal movement with fixed speed
« on: January 04, 2015, 07:35:13 pm »
So I have the class below which will move to the location of the mouse after the "M" key is pressed (was originally going to use right-click, but it isn't registering my trackpad's right clicks), provided the sprite was clicked on first. Obviously I want it to be able to do this multiple times and at a fixed speed, so this presents two problems with my implementation:

1) If I tell the ship to move to a point whose x AND y coordinates are smaller than the current position, it just teleports there instantly; if the ships moves to point whose x OR y coordinate is smaller than the current position, it reaches the point in the appropriate amount of time ('timeToReach'), but then it just flies past and keeps moving on forever in that direction.

2) I am just not sure how exactly to implement fixed speed; 'moveToRightClick' will cause the ship to traverse any distance, big or small, in 'timeToReach' amount of time. How do I get it to move with a fixed speed of let's say 20 pixels a second, for example?

class Ship : public sf::Sprite
{
public:
    int posX, posY;
    bool clickedOn = false, moving = false;
    sf::Vector2i moveToPoint;
   
    Ship(int x, int y, sf::Texture &texture) : posX(x), posY(y)
    {
        setPosition(x, y);
        setTexture(texture);
        setColor( sf::Color(0,255,0) );
    }
   
    void isClickedOn(sf::Window &window)
    {
        sf::FloatRect spriteBounds = getGlobalBounds();
       
        if( sf::Mouse::isButtonPressed(sf::Mouse::Left) )
        {
            sf::Vector2i mousePos = sf::Mouse::getPosition(window);
           
            if( spriteBounds.contains(mousePos.x, mousePos.y) )
            {
                clickedOn = true;
            }
        }
    }
   
    void beginMoving(sf::Window &window, sf::Event &event)
    {
        //using sf::Event as a parameter to place in the event processing loop
        //to check if button is pressed and/or released
        sf::FloatRect spriteBounds = getGlobalBounds();
       
        if( clickedOn )
        {
            if( (event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::M) )
            {
                sf::Vector2i mousePos = sf::Mouse::getPosition(window);
               
                if( !( spriteBounds.contains(mousePos.x,mousePos.y) ) )
                {
                    clickedOn = false;
                    moving = true;
                    moveToPoint.x = mousePos.x;
                    moveToPoint.y = mousePos.y;
                }
            }
            if( sf::Mouse::isButtonPressed(sf::Mouse::Left) )
            {
                sf::Vector2i mousePos = sf::Mouse::getPosition(window);
               
                if( !( spriteBounds.contains(mousePos.x,mousePos.y) ) )
                    clickedOn = false;
            }
        }
    }
   
    void moveTo(sf::Time delta, int timeToReach)
    {
        if(moving)
        {
            sf::Vector2f currentPos = getPosition();
           
            float newX = (moveToPoint.x - posX) / timeToReach;
            float newY = (moveToPoint.y - posY) / timeToReach;
            newX *= delta.asSeconds();
            newY *= delta.asSeconds();
           
            move(newX,newY);
           
            if( (currentPos.x >= moveToPoint.x) && (currentPos.y >= moveToPoint.y) )
            {
                setPosition(moveToPoint.x, moveToPoint.y);
                moving = false;
                posX = moveToPoint.x;
                posY = moveToPoint.y;
                //if newX < 0 && newY < 0, then teleports to point instantly
                //if newX < 0 or newY < 0, then goes to point in correct time, but then keeps moving past
            }
        }
    }
}

9
General / Re: Simultaneous Drawing/Rendering
« on: January 04, 2015, 03:06:38 am »
Ah I see, thank you again then for pointing that out, didn't think about float modulo.

I do have another question, although it is quite a bit unrelated to what we've discussed in this topic. Don't know if I should make another topic, private message you (if you don't mind), or just to carry on here.

10
General / Re: Simultaneous Drawing/Rendering
« on: January 03, 2015, 01:05:59 am »
Thank you for clarifying the proper usage of clear and display as well as clarifying the game loop, helped to produce the result I was looking for.

Going back to the large theta, yes, sine and cosine will of course return the same results, but I'm concerned that after a while 'theta' might eventually reach the maximum possible value for an integer (2147483647 isn't it?) or a double since it will infinitely increase and thus cause an error.

11
General / Re: Simultaneous Drawing/Rendering
« on: January 02, 2015, 02:33:44 am »
Shouldn't I call clear inside 'someFun' as well? The display idea makes sense, I am still unclear though how your code will work. What would the loop that calls your 'draw' look like inside the game loop?

Also since 'theta' would keep incrementing, wouldn't this eventually cause the game to crash since 'theta' would keep increasing towards infinity?

What is the point of needing a Time object if we're only using it as a float value? Can't I just use '0.01' instead of deltaTime? Or have deltaTime be of float type?

12
General / Re: Simultaneous Drawing/Rendering
« on: January 02, 2015, 01:43:57 am »
Forgot to say the last block of code is inside a game loop, specifically 'while (window.isOpen())'.

That's what I figured though, but I can't think of how to get the sprite to move in orbit without calling draws in 'someFun', since not having it in there never lets the window to display since it will always be in the while loop of 'someFun'.

Also, sorry, few small edits, didn't mean to have a draw call for the parent in 'someFun'.

13
General / [Solved] Simultaneous Drawing/Rendering
« on: January 02, 2015, 01:18:29 am »
I am attempting to implement the following: a variable (large) number of stars are going to be drawn, which is easy enough, already implemented that. Each star though will have a variable number (< 10) of planets orbiting them, with each planet being constantly in motion regardless of its visibility, but will only be drawn if they are clicked on. What I am concerned with is the actual orbital motion behavior, the code below I am using has two problems:

First is that it is not orbiting at the speed I want it to (want one orbit to take 10 seconds as I said in the comments in my code below) and second is that running the third block of code causes the 'test' planet to complete one orbit, disappear, then the 'other' planet completes one orbit, disappears, and starts again from the beginning. I obviously want them to be visible at the same time, not one and then the other.

class Star : public sf::Sprite
{
private:
    void Init(int xCoord,int yCoord)
    {
        setPosition(xCoord,yCoord);
    }
public:
    int xPos;
    int yPos;
   
    Star(int inX, int inY) : xPos(inX), yPos(inY)
    {
        Init(xPos,yPos);
    }
}

class Celestial : public sf::Sprite
{
public:
    void someFun(int radi, Star &parent,sf::RenderWindow &in)
    {
        double twoPi = 2*Pi;
        double orbSpeed = (twoPi*radi) / 10; //divide by '10' because want 10 sec orbit
        double s = orbSpeed*0.1; //multiply by '0.1' because want it to move every 0.1 seconds
        double increment = s / radi;
        double theta = 0.00;
       
        while(theta < twoPi)
        {
            in.clear();
            theta += increment;
           
            if(theta == twoPi)
                theta = 0;
           
            double paramX = radi*cos(theta) + parent.xPos;
            double paramY = radi*sin(theta) + parent.yPos;
           
            setPosition(paramX,paramY);
           
            in.draw(*this);
            in.display();
        }
    }
}

test.someFun(100,sol,window);
other.someFun(140,sol,window);

14
General / SFML 2.1 with Xcode 6
« on: December 30, 2014, 02:34:43 am »
So I created a few projects with Xcode using the new templates that were on the website and using SFML for C++11 and everything worked, but today I created a new project from the template using the exact same settings, with not a single file in my computer changed/moved/deleted, and I get the compile errors:

clang: error: unknown argument: '-frameworksfml-system'
clang: error: unknown argument: '-frameworksfml-window'
clang: error: unknown argument: '-frameworksfml-graphics'
clang: error: unknown argument: '-frameworksfml-audio'
clang: error: unknown argument: '-frameworksfml-network'

What happened? I literally did nothing different and I fail to see what I possibly could've done.

15
Yes what you said was what I meant. Thank you for the clarification, I figured it involved those reference operators, but I have been having trouble understanding there exact meaning. The link you provided had some great answers which clarified greatly, so thank you for that and apologies for asking a question that I realize now might've been more appropriate in a general C++ forum.

Pages: [1] 2
anything