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

Pages: [1] 2
1
Graphics / Giving sf::RenderWindow.Draw() a pointer inside an array
« on: September 24, 2010, 03:08:09 am »
I see the light!

Thanks, if only I had thought to go and look up how array initilization works again. Thanks for pointing that out to me

Problem solved =)

//I feel like such a noob =P

btw, thank you for introducing me to Smart pointers and RAII. I'm a little short on programing concepts outside of the basic language tutorial

2
Graphics / Giving sf::RenderWindow.Draw() a pointer inside an array
« on: September 24, 2010, 02:36:06 am »
well, I think my indexes match my loop. 24 index locations in each direction, and 24 iterations of it, all 0-23. Now I'm not sure if  for loop would iterate and then run, but that could be fixed by switching it from an ++X to an X++. But I don't really see how that could effect my window crashing.

And I'm sure I would use them if I knew how =) I'm always up for becoming a better programmer though, especially cause I'm not a good one.

--edit--
looked up smart pointers, I think if I may rewrite it from scratch and include them when I'm done. And certainty in larger projects.

Also,  could a memory leak or a dangling pointer be whats causing this?

3
Graphics / Giving sf::RenderWindow.Draw() a pointer inside an array
« on: September 24, 2010, 02:10:59 am »
forgive me but I'm not exactly sure what you mean by subscripts,

The reason I am using pointers rather than an array of classes is because I think it should have a lower memory cost. I don't need 576 squares, just up to that. So I can easily track where the squares are on the grid and access them by allocating memory during runtime when I need it and sticking the pointer in the grid.

Since it is a tetris game, I have a small array that stores the pointers of the four active squares. I can manipulate them and move them how I wish and then update where they are on my grid (the array) easily and they will always stack nicely. Collision checking is easy and fast too, just check underneath the active blocks for a non active block or the floor Once one of them touches the bottom or another block, it is easy to freeze them in place and forget about them, making new blocks up top with pointers in both arrays.

I only have to worry about deleting them in lines or the entire screen, so I can simply delete a line on the large array, both pointer and memory, and then shift all blocks above it down. When time comes to end, its easy to just do that to the entire array.

Does that explain why I am using an array of pointers?

4
SFML projects / Sketch RPG
« on: September 24, 2010, 12:28:34 am »
Awesome! I really like this, I'm taking art lessons, but atm I'm no good at any kind. So sorry about that. I really did like your game a whole lot though. I would say already beyond my skill level, I'm still working on getting the bugs out of my tetris.

Also, big kudos on sticking with it a month. I have a lot of difficulty past that point.

Overall, Great job =)

5
Graphics / Giving sf::RenderWindow.Draw() a pointer inside an array
« on: September 24, 2010, 12:20:14 am »
Hello, I've been trying to figure this one out, I have a function that loops through an array of pointers to classes which have sprites, and then tells the Render Window to draw them. I'm not sure whats wrong, but whenever the line
Code: [Select]
Window.Draw(Array[X][Y]->BlockSprite);
is in the function (or a similar line anywhere else) the sfml render window will crash. When this line is not there, it is fine.

Here is the code for the function, and ask if there is anything else I can give you guys, thanks in advance.

Code: [Select]

Square * Array[23][23];// class Square has sf::Sprite BlockSprite;

void DrawManager()
{
    for (int X = 0; X < 24; X = X + 1)
    {
        for (int Y = 0; Y < 24; Y = Y + 1)
        {
            if (Array[X][Y] != 0)
            {
                Window.Draw(Array[X][Y]->BlockSprite);
            }
        }
    }
}


The pointers are set to zero if they are not pointing to anything, so its fairly self explanatory what this does... I think XD
Also, originally this was written so that the sprite was private and there was a public function that returned it, I got rid of it in troubleshooting and made the sprite public

6
General / Problem with program crashing as soon as activated
« on: February 25, 2010, 01:41:43 am »
ok, here we go, it still says not responding. Here is the condensed code I've compiled.

Code: [Select]

#include <SFML/Graphics.hpp>
using namespace std;

//------------------------------SF stuff------------------------------------------
    sf::RenderWindow Window;
//--------------------------End SF stuff------------------------------------------



int main(){
    Window.Create(sf::VideoMode(500, 300, 32), "Avian");
    int BattleOn = 4;
    while (BattleOn){

        }
}


It still crashed with a Window.Display()



-------------------edit---------------------------

and now its just my luck code::blocks is bugging out on me, I ran the exacutable in the snake game and took a look at the source code just before....
Now it gives me a window from mingw saying there is no disk in drive D, about a thousand times, or it says it uses an invalid compiler =(

7
General / Problem with program crashing as soon as activated
« on: February 24, 2010, 09:34:48 am »
Alright, I did that. and thanks, I actually had been wondering about that.
It still crashes, but I think im going to work on it more tomorrow, its twelve thirty at night here and I have to get up at six tomorrow. Thank you for your help. And if I can't solve it by this time on Wednesday I'll head back here.

Again, thanks a lot, its really great to have some help =)

8
General / Problem with program crashing as soon as activated
« on: February 24, 2010, 09:14:45 am »
Can I do that? Don't I need to declare it before I can use it in all of my functions?

Thanks for you patience... I can't help but feel really feel ignorant right now,

9
General / Problem with program crashing as soon as activated
« on: February 24, 2010, 09:10:13 am »
I just compiled it again and its doing something completely different... It shows me the white dots that are placeholders for images, and the buttons don't work, but it isn't crashing. And the above two problems I could probably fix myself.

Its really strange. But I don't really think there is a problem anymore.


----edit----
And once again its crashing, but everything loads, so its probably ok

10
General / Problem with program crashing as soon as activated
« on: February 24, 2010, 09:04:04 am »
Here are all the parts pertaining to SFML, as far as I can tell at least,



Code: [Select]

#include <iostream>
#include <fstream>
#include <string>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

using namespace std;

/// Entry point of application
///
/// \return Application exit code
///
//------------------------------SF stuff------------------------------------------
    sf::RenderWindow Window(sf::VideoMode(650, 400, 32), "Avian");
    sf::Clock Clock;
    sf::Image ZepImage;
    sf::Image BG1Image;
    sf::Image BG2Image;
    sf::Image BG3Image;
    sf::Image BG4Image;
//--------------------------End SF stuff------------------------------------------

class CannonBall{
    public:
    float mass;
    float X;
    float Y;
    float VelX;
    float VelY;
};

class Zepplin{
    public:
    float X;
    float Y;
    float BattleX;
    float BattleY;
    float Speed;
    float Health;
    sf::Sprite ZepSprite;
    CannonBall Balls[10];
}PlayerZepplin;

int WKeyDown(){
    if(Window.GetInput().IsKeyDown(sf::Key::W)){
        return 1;
    }
}
int SKeyDown(){
    if(Window.GetInput().IsKeyDown(sf::Key::S)){
        return 1;
    }
}
int AKeyDown(){
    if(Window.GetInput().IsKeyDown(sf::Key::A)){
        return 1;
    }
}
int DKeyDown(){
    if(Window.GetInput().IsKeyDown(sf::Key::D)){
        return 1;
    }
}

float GetTime(){
    return Clock.GetElapsedTime();
}
float Time;

class Background{
    public:
    sf::Sprite BGSprite;
    float X;
    float Y;
}BG1, BG2, BG3, BG4;

void ScrollBG(Background BG){
    if (!(BG.X < -210)){ //if the BG isn't very far left
        BG.X = BG.X - 2;
    }
    else{
        BG.X = 1390;//three 400 -210, allows four different backgrounds
    }
}

void ZepBattle(){
    int BattleOn = 4;
    while (BattleOn){
        while (Window.IsOpened()){
        Time = GetTime();
        Window.Clear();
        //---------------------------------------------------------------
        if (WKeyDown()){
            PlayerZepplin.BattleY = PlayerZepplin.BattleY + ((20 * (Time/GetTime())) * PlayerZepplin.Speed);
        }
        if (SKeyDown()){
            PlayerZepplin.BattleX = PlayerZepplin.BattleX - ((20 * (Time/GetTime())) * PlayerZepplin.Speed);
        }
        if (AKeyDown()){
            PlayerZepplin.BattleX = PlayerZepplin.BattleX - ((20 * (Time/GetTime())) * PlayerZepplin.Speed);
        }
        if (DKeyDown()){
            PlayerZepplin.BattleX = PlayerZepplin.BattleX + ((20 * (Time/GetTime())) * PlayerZepplin.Speed);
        }
        //---------------------------------------------------------------

        ScrollBG(BG1);
        ScrollBG(BG2);
        ScrollBG(BG3);
        Window.Draw(BG1.BGSprite);
        Window.Draw(BG2.BGSprite);
        Window.Draw(BG3.BGSprite);
        Window.Draw(BG4.BGSprite);
        Window.Draw(PlayerZepplin.ZepSprite);
        Window.Display();
        }
        }

    }

void Initalize(){
    if(!ZepImage.LoadFromFile("Zep.png"))
    PlayerZepplin.ZepSprite.SetImage(ZepImage);
    PlayerZepplin.ZepSprite.SetCenter(9.5f,9.5f);
    PlayerZepplin.ZepSprite.SetPosition(200,200);
    PlayerZepplin.Speed = .95f;
    if(!BG1Image.LoadFromFile("BG1.png"))
    if(!BG2Image.LoadFromFile("BG2.png"))
    if(!BG3Image.LoadFromFile("BG3.png"))
    if(!BG4Image.LoadFromFile("BG4.png"))
    BG1.BGSprite.SetImage(BG1Image);
    BG2.BGSprite.SetImage(BG2Image);
    BG3.BGSprite.SetImage(BG3Image);
    BG4.BGSprite.SetImage(BG4Image);
}

void Menu(){
}

int main(){

    Initalize();
    Menu();
    ZepBattle();


}



I apologize for putting it all in there, I just don't know another way to do it.

Also, no I haven't looked at the Code::Blocks page, it really didn't occur to me. THough I don't know what I would be looking for.

11
General / Problem with program crashing as soon as activated
« on: February 24, 2010, 08:33:35 am »
I am using MinGW as far as I know (I'm actually not too knowledgeable on that) And the problem is that whenever I compile and run the program crashes immediately, the window does pop up, but shows nothing. The first ten times this happened it slowed down my computer considerably, now it just shows up as a regular non-responsive program.

Here are my build messages and build log, I think they have the reason for the problem. Ask if you need any other information.


Build Messages:
Code: [Select]

||Info: resolving vtable for sf::Spriteby linking to __imp___ZTVN2sf6SpriteE |
||Info: resolving vtable for sf::Drawableby linking to __imp___ZTVN2sf8DrawableE |
||warning: auto-importing has been activated without --enable-auto-import specified on the command line.|
||=== Build finished: 0 errors, 1 warnings ===|



Build Log:
Code: [Select]

Compiling: C:\Users\Mike\Desktop\Projects\Xep\source1.cpp
Linking console executable: C:\Users\Mike\Desktop\Projects\Xep\source1.exe
Info: resolving vtable for sf::Spriteby linking to __imp___ZTVN2sf6SpriteE (auto-import)
Info: resolving vtable for sf::Drawableby linking to __imp___ZTVN2sf8DrawableE (auto-import)
C:\Program Files (x86)\CodeBlocks\MinGW\bin\ld.exe: warning: auto-importing has been activated without --enable-auto-import specified on the command line.
This should work unless it involves constant data structures referencing symbols from auto-imported DLLs.
Process terminated with status 0 (0 minutes, 1 seconds)
0 errors, 1 warnings
 
Checking for existence: C:\Users\Mike\Desktop\Projects\Xep\source1.exe
Executing: C:\Program Files (x86)\CodeBlocks/cb_console_runner.exe "C:\Users\Mike\Desktop\Projects\Xep\source1.exe" (in C:\Users\Mike\Desktop\Projects\Xep)
Process terminated with status -1073741510 (1 minutes, 3 seconds)
 


Thank you again. The sfml forums are some of the best when it comes to help and support. I am really appreciative ahead of time.



------Edit--------
Oh and I just realized it would be a good idea to mention this,  I have other SFML games that compile and run just fine on my computer. They use the same .dll's and the same linker and compiler. I guess this means the problem must be in the code somewhere. I just have no clue where.

12
Graphics / Creating sprites with different levels of transparency
« on: December 08, 2009, 06:14:04 am »
Hey, I'm back. Anyway I'll get straight to the point, its not an error, its a question. I have a sprite that is a small sphere and I would like to have it so the fringes are slightly transparent,. Is there any way to do this? I noticed that when I draw it, it is either all the way transparent or it is fully colored. it is a .png and is drawn perfectly in GIMP =)
But yea, not to important of a question, just a wondering

13
Graphics / Rotation changes every time A key is pressed
« on: November 09, 2009, 10:41:11 pm »
Hooray!!! Thanks to both of you =) I couldn't have done it without both of you. The darn things finaly working as it should. Thanks tons for your great patience and insight =)

14
Graphics / Rotation changes every time A key is pressed
« on: November 09, 2009, 08:52:15 pm »
Here, this is the entire thing now

I hope its not too confusing
sorry about this =(


Code: [Select]

#include <iostream>

using namespace std;


////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>


////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////

float DecimalCos(float Num){
    return (cos(Num*(3.14/180)))*(180/3.14);
}
float DecimalSin(float Num){
    return (sin(Num*(3.14/180)))*(180/3.14);
}

int main()
{
    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(1200, 600, 32), "SFML Graphics");
    int MouseX,MouseY;
    // Load the sprite image from a file
    sf::Image Image;
    sf::Image turret;
    sf::Image Missiletastic;
    sf::Image Kursor;
    float MissileSpriteRotation;
    if (!Image.LoadFromFile("Tank.png"))
        return EXIT_FAILURE;
    if (!turret.LoadFromFile("Turret.png"))
        return EXIT_FAILURE;
    if (!Missiletastic.LoadFromFile("Missile.png"))
        return EXIT_FAILURE;
    if (!Kursor.LoadFromFile("Cursor.png"))
        return EXIT_FAILURE;

    // Create the sprite
    sf::Sprite PlayerTank(Image);
    sf::Sprite PlayerTurret(turret);
    App.ShowMouseCursor(0);
    // Change its properties

    PlayerTank.SetPosition(200.f, 100.f);
    PlayerTank.SetCenter(25.f,27.f);
    PlayerTurret.SetCenter(25.f,25.f);

    float PlayerX;
    float PlayerY;
    float PlayerRotation;
    float SystemTime = App.GetFrameTime();
    sf::Event Mouse;

    sf::Sprite MissileSprite(Missiletastic);
    MissileSprite.SetCenter(5.f,8.f);
    sf::Sprite Cursor(Kursor);
    Cursor.SetCenter(25.f,25.f);
        sf::Event Event;

    // Start game loop
    while (App.IsOpened())
    {
        // Process events

        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        // Get elapsed time
        float ElapsedTime = App.GetFrameTime();
        MouseY = Event.MouseMove.Y;
        MouseX = Event.MouseMove.X;

       
        //Moves the turret along with the tank and moves the cursor
        PlayerTurret.SetX(PlayerTank.GetPosition().x);
        PlayerTurret.SetY(PlayerTank.GetPosition().y);
        Cursor.SetX(MouseX);
        Cursor.SetY(MouseY);
        // Moves the tank
        if (App.GetInput().IsKeyDown(sf::Key::D))  PlayerTank.Rotate(-100.0 * ElapsedTime);
        if (App.GetInput().IsKeyDown(sf::Key::A)) PlayerTank.Rotate( 100.0 * ElapsedTime );
        if (App.GetInput().IsKeyDown(sf::Key::W)){
            PlayerRotation = -1* PlayerTank.GetRotation() + 180 + 90;
            PlayerTank.Move(( DecimalCos(PlayerRotation)) * 5 * ElapsedTime, (DecimalSin(PlayerRotation)) * 5 * ElapsedTime);
        }
        if (App.GetInput().IsKeyDown(sf::Key::S)){
            PlayerRotation = -1* PlayerTank.GetRotation() + 180 + 90;
            PlayerTank.Move(( DecimalCos(PlayerRotation)) * 5 * ElapsedTime * -1, (DecimalSin(PlayerRotation)) * 5 * ElapsedTime * -1);
        }

            //fires the missile
            if (App.GetInput().IsKeyDown(sf::Key::Space) ){//and SystemTime + .0001 < App.GetFrameTime()
            MissileSprite.SetX(PlayerTurret.GetPosition().x);
            MissileSprite.SetY(PlayerTurret.GetPosition().y);
            MissileSprite.Rotate(PlayerTurret.GetRotation());
            SystemTime = App.GetFrameTime();
            }

             MissileSpriteRotation = -1* MissileSprite.GetRotation() + 180 + 90;
            MissileSprite.Move(( DecimalCos(MissileSpriteRotation)) * 10 * ElapsedTime, (DecimalSin(MissileSpriteRotation)) * 10 * ElapsedTime);

        //Sets the players turret rotation
        PlayerTurret.SetRotation (-1*static_cast<float>(atan2(static_cast<double>(MouseY - PlayerTurret.GetPosition().y),static_cast<double>(MouseX - PlayerTurret.GetPosition().x))* 180 / 3.14) - 90);


        // Clear screen
        App.Clear();

        // Display sprite in our window
        App.Draw(MissileSprite);

        App.Draw(PlayerTank);
        App.Draw(PlayerTurret);
        App.Draw(Cursor);


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

    return EXIT_SUCCESS;
}

15
Graphics / Rotation changes every time A key is pressed
« on: November 09, 2009, 08:43:07 pm »
Thanks a ton, that simplified my code a lot =)

But I still have the problem of the mouse jumping all over the place (or at least Im pretty sure thats it) whenever a button is pressed Mouse or keyboard.

Pages: [1] 2
anything