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.


Topics - TheDianamu

Pages: [1]
1
Graphics / SFML Button
« on: November 13, 2013, 07:54:40 am »
Hi, I made a small Button set since SFML doesnt have a button class directly inputted into it, so I tried to make my own, and I got this, you can add/change/modify it to your liking

//Get the position of the Mouse
int MouseX = sf::Mouse::getPosition().x;
int MouseY = sf::Mouse::getPosition().y;

//Create a Shape for the button
sf::RectangleShape button; //Doesnt have to be a rectangle

//Give the Button a color
button.setFillColor(sf::Color::Blue);

//Set size of the button
button.setSize(sf::Vector2f(100,48)); //Make it what ever you like

//Set the position of the button
button.setPosition(200,200);//or where ever you like

//The Fun Stuff!!
if(button.getGlobalBounds().width <=> MouseX
&& button.getGlobalBounds().height <=> MouseY){
//Do What you want to do with the button
button.setFillColor(sf::Color::Green);
}

 

Now this may not be the most efficient way to do this, but it worked for me when I tried it.

2
Graphics / Handleing First Chance Error when loading images
« on: November 02, 2013, 08:11:42 am »
Hi, whenever I run my application, and I want to set rect image to the grass. It keeps on giving me a first chance exception. Here is the 2 stacktraces

First-chance exception at 0x1004ab8d in Game.exe: 0xC0000005: Access violation writing location 0x00000000.
Unhandled exception at 0x1004ab8d in Game.exe: 0xC0000005: Access violation writing location 0x00000000.

I'm a little confused, could anybody tell me what is going on? I have added the code that is drawing and setting the rect on the screen below.

sf::RectangleShape rect;

sf::Texture* grass;
grass->loadFromFile("grass.png");

rect.setSize(sf::Vector2f(16,16));
rect.setTexture(grass);
rect.setPosition(x * 16, y * 16);
window.draw(rect);

window.setView(map_view);
window.display();

3
General / Entry point must be defined
« on: October 11, 2013, 02:25:20 pm »
Hi, I'm having troubles setting up:

I get  LINK : fatal error LNK1561: entry point must be defined with this code

#include "LEngine.h"
#include <SFML\Graphics.hpp>

void LEngine::Sprites(){
        sf::Texture t_grass;
        sf::Texture t_stone;
        sf::Texture t_water;

        t_grass.loadFromFile("grass.png");
        t_stone.loadFromFile("stone.png");
        t_water.loadFromFile("water.png");

        sf::Sprite grass;
        sf::Sprite stone;
        sf::Sprite water;

        grass.setTexture(t_grass);
        stone.setTexture(t_stone);
        water.setTexture(t_water);
}

void LEngine::Map(){
}

bool LEngine::Init(){
        window = new sf::RenderWindow(sf::VideoMode(800, 600, 32), "RPG");

        if(!window)
                return false;

        return true;
}

void LEngine::Events(){
        sf::Event evt;
        //Loop through all window events
        while(window->pollEvent(evt)){
                if(evt.type == sf::Event::Closed)
                        window->close();
        }
}

void LEngine::MainLoop(){
        while(window->isOpen()){
                Sprites();
                Map();
        }
}

void LEngine::boot(){
        if(!Init())
                throw "Could not initialize Engine";

        MainLoop();
}

4
General / Converting a sf::Image to a sf::Texture
« on: October 01, 2013, 12:36:53 pm »
Hi, I need to convert a image to a texture for my application, but I cannot find anywhere that tells you how to do so.

Could anybody link me to a post or a post some code or a way they would do it ?

Cheers TheDianamu

5
Graphics / setImage not a member of sf::Sprite
« on: September 29, 2013, 04:10:54 am »
I'm having troubles with my tile class for my engine. I'm using the SFML 2.1 and coding visual c++ 2010

I get the following on compile:
'setImage' : is not a member of 'sf::Sprite'

Tile.cpp:
#include "Tile.h"
#include <SFML\Graphics.hpp>

Tile::Tile(sf::Image& image)
{
        baseSprite.setImage(image, true);
}

Tile::~Tile()
{

}

void Tile::Draw(int x, int y, sf::RenderWindow* rw)
{
        baseSprite.setPosition(x, y);
        rw->draw(baseSprite);
}

Tile.h:

#ifndef _TILE_H
#define _TILE_H

#include <SFML\Graphics.hpp>

class Tile
{
private:
        sf::Sprite baseSprite;

public:
        Tile(sf::Image& image);
        ~Tile();

        void Draw(int x, int y, sf::RenderWindow* rw);
};

#endif

6
Graphics / How to fill the window with a texture/sprite
« on: September 20, 2013, 03:42:42 pm »
I'm trying to figure out a quick and simple way of filling the entire window or to a size say like

width of 200 sprites
height of 200 sprites

How would I go about setting the texture/sprite to fill that size? I have tried to use setRepeated, but that wasn't working.

Thanks in Advance

7
General / How to draw randomly for a game
« on: September 17, 2013, 10:15:46 am »
Hi, as you have read by a lot of people. I'm working on a game. I'm just thinking how to pre-load a map for my game, so that I have say 600x600 pixels, the map is drawn with a texture 600x600 pixels with a texture of 16, I know how to get the texture made, just don't know how to draw more textures onto the screen.

I was thinking of maybe if SFML has the ability do window.draw(sprite,x,y); where x and y are the positions of the texture/tile. But that would take too long, so I was wondering if there is a easy way to do it.

Regards TheDianamu

Thanks in advance

8
Graphics / sf::Keyboard Only move the Sprite in the direction once
« on: September 15, 2013, 08:09:49 am »
Hi, I'm working on a game and I'm stuck on Movement

I have the following code in my main.cpp

                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) sprite.move(-20,0);
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) sprite.move(20,0);
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) sprite.move(0,-20);
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) sprite.move(0,20);
 

Im just trying to figure out, why it isn't allowing me to move the sprite continually. Would I need to do something like
float speed = 5.f;
?

Thanks in advance.



Pages: [1]