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

Pages: [1]
1
Graphics / Re: white images
« on: August 20, 2012, 07:17:16 pm »
Thanks for the help. :)

Adding a cop constructor fixed it for me. Huzaas to you two!.

2
Graphics / Re: white images
« on: August 20, 2012, 05:32:53 pm »
#ifndef SHAPE_H
#define SHAPE_H

#include <SFML/Graphics.hpp>

class Shape
{
private:
        sf::Image image;
        sf::Sprite sprite;
        sf::Vector2<float> pos;
        sf::Vector2<float> dir;
        sf::RenderWindow *a;
        int radius;

public:

        Shape(int boundingRadius, sf::Vector2<float> position,sf::Vector2<float> direction, sf::Image i, sf::RenderWindow *window);
        void update();
        void draw();
        sf::Vector2<float> getPosition();
        int getRadius();

};

#endif

#include "shape.h"

Shape::Shape(int boundingRadius, sf::Vector2<float> position, sf::Vector2<float> direction,sf::Image i, sf::RenderWindow *window)
{
        image = i;
        pos = position;
        dir = direction;
        radius = boundingRadius;
        sprite.SetImage(image);
        sprite.SetPosition(pos);
        a = window;
}

void Shape::draw()
{
        a->Draw(sprite);
};
sf::Vector2<float> Shape::getPosition()
{
        return pos;
};
int Shape::getRadius()
{
        return radius;
};

void Shape::update()
{

        pos = pos+dir;
        sprite.SetPosition(pos);
       
        if(pos.x<-20)
        {
                dir.x = dir.x *(-1);

        }
        if(pos.x>560)
        {
                dir.x = dir.x *(-1);
        }
        if(pos.y<-20)
        {
                dir.y = dir.y *(-1);
        }
        if(pos.y>360)
        {
                dir.y = dir.y *(-1);
        }

};


Also I use sfml 1.6 atm because I was hacing some trouble with sfml2 .

3
Graphics / Re: white images
« on: August 20, 2012, 05:16:59 pm »
But the Shape class contains an sf Image so when I create them wouldn't the image be saved there? Since in the Shape constructor I set the image to the image in the argument.

4
Graphics / white images
« on: August 20, 2012, 04:17:53 pm »
My little program was working fine until I moved the code that loads the images from main in to another class.
Instead of my images I only get white squares.

This is my current code:

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

#include "shapeHandler.h"

using namespace std;

        // Create the main window
    sf::RenderWindow App(sf::VideoMode(640, 400, 32), "SFML Window");
        ShapeHandler shapes;

int main(){

        shapes.init(&App);
    // Start main loop
   while (App.IsOpened())
    {
               
                App.Clear();
                shapes.draw();
                App.Display();
                shapes.update();
    }

    return EXIT_SUCCESS;

}

#ifndef SHAPEHANDLER_H
#define SHAPEHANDLER_H

#include <vector>
#include "shape.h"
#include <SFML/Graphics.hpp>

class ShapeHandler
{
        private:
                std::vector<Shape> shapeList;
                sf::Image Image;
        public:
                ShapeHandler();
                void update();
                void init(sf::RenderWindow* r);
                void draw();
};

#endif

void ShapeHandler::init(sf::RenderWindow* r)
{
        Image.LoadFromFile("circle.png");
        Shape circle(40,sf::Vector2<float>(5,5),sf::Vector2<float>(-1,1),Image,r);     
        Image.LoadFromFile("square.png");
        Shape square(40,sf::Vector2<float>(80,85),sf::Vector2<float>(0,1),Image,r);    
        Image.LoadFromFile("star.png");
        Shape star(40,sf::Vector2<float>(35,25),sf::Vector2<float>(1,0),Image,r);      
        Image.LoadFromFile("stary.png");
        Shape stary(40,sf::Vector2<float>(15,65),sf::Vector2<float>(1,-1),Image,r);    
        Image.LoadFromFile("triangle.png");
        Shape triangle(40,sf::Vector2<float>(35,95),sf::Vector2<float>(-1,-1),Image,r);

        shapeList.push_back(circle);   
        shapeList.push_back(square);   
        shapeList.push_back(star);     
        shapeList.push_back(stary);    
        shapeList.push_back(triangle);
};


And here is the code when it worked:

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

#include "shape.h"

using namespace std;

        // Create the main window
    sf::RenderWindow App(sf::VideoMode(640, 400, 32), "SFML Window");


int main(){

        sf::Image Image;
        Image.LoadFromFile("circle.png");
        Shape circle(40,sf::Vector2<float>(5,5),sf::Vector2<float>(-1,1),Image,&App);  
        Image.LoadFromFile("square.png");
        Shape square(40,sf::Vector2<float>(80,85),sf::Vector2<float>(0,1),Image,&App); 
        Image.LoadFromFile("star.png");
        Shape star(40,sf::Vector2<float>(35,25),sf::Vector2<float>(1,0),Image,&App);   
        Image.LoadFromFile("stary.png");
        Shape stary(40,sf::Vector2<float>(15,65),sf::Vector2<float>(1,-1),Image,&App); 
        Image.LoadFromFile("triangle.png");
        Shape triangle(40,sf::Vector2<float>(35,95),sf::Vector2<float>(-1,-1),Image,&App);

    // Start main loop
   while (App.IsOpened())
    {
               
                App.Clear();

                circle.draw();

                App.Display();

                circle.update();



    }

    return EXIT_SUCCESS;

}

5
Graphics / Re: Stitching an image
« on: July 21, 2012, 06:16:03 pm »
Using SFML 1.6 so I guess I'll have to upgrade and I wont be creating very large images so texture size limit wont be a problem.

I find it unnecessary to iterate trough all tiles when I don't have a need for it, any animation will be done on another level. The tiles are more of a way of generating data for the chunk which holds them.


6
Graphics / Stitching an image
« on: July 21, 2012, 03:37:33 pm »
Is it possible to stitch together an image from several smaller ones? I haven't been able to figure it out how to do it yet. I got an array with tiles and instead of iterating trough this array each loop to grab every single tile I'd like to create just one large image or sprite and draw.

Pages: [1]