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

Pages: [1]
1
Graphics / Strange behaviour with setTextureRect flip
« on: June 11, 2016, 07:02:55 pm »
I found a strange bug while working on my game today.
I had to flip my sprites for different directions. I used to use setScale with (-1,1) and it worked great, but I had to manage positions etc. I then found out about negative width on the setTextureRect function and started using it.

Here's the problem (SFML 2.3).
When drawing a flipped sprite ( SPR.setTextureRect(sf::IntRect(width, 0, -width, height); ) and setting this sprite's position to a half pixel (0.5f, 1.5f ... X.5f) does not use the correct rectangle. It actually offsets it one pixel to the right, but ONLY at half pixel positions. I assume this is some kind of rounding error.

But why would the sprite's position have any impact on the texture rectangle?
I temporarily fixed it by casting my sprite's x position to int. You can't draw to half pixels anyway.

2
General / 'sf::Key' has not been declared
« on: December 18, 2011, 02:15:48 pm »
So I just recently built SFML2 and wanted to familiarize myself with the new stuff.
There I was, making a super simple program when it started complaining about sf::Key not being declared. I just thought that I made a typo or something but then I copy-pasted the code from here and it still complained.

What's the deal?

Here's what I got so far.

Code: [Select]

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

#include <iostream>




int main(){


    sf::RenderWindow mainWindow(sf::VideoMode(800, 600,32), "SFML window");
    mainWindow.Clear(sf::Color(46,40,35));


    sf::Text text;
    text.SetString("TEXT FOR THE SCREEN");
    text.SetPosition(200,200);

    mainWindow.Draw(text);
    mainWindow.Display();

    while(true){
        sf::Event currentEvent;
        mainWindow.PollEvent(currentEvent);
        if(currentEvent.Type == sf::Event::Closed){
            return EXIT_FAILURE;
        }

        if ((currentEvent.Type == sf::Event::KeyPressed) && (currentEvent.Key.Code == sf::Key::Escape)){ // here's the problem
            printf("%i\n", currentEvent.Key.Code);
            return EXIT_SUCCESS;
        }
    }


    return EXIT_SUCCESS;

}

3
Network / TCP Server, Wait() + Send
« on: January 16, 2011, 06:36:45 pm »
Hello,
I'm currently exploring the world of network programming. I started with the Selector example in the tutorial and kind of understood it all, except maybe the Wait function. I tried extending the example to be able to send messages from the server to the client but it seems like Wait is blocking anything from running.
Is there a place where I can read more about the uses of Wait and Selector?
I get that the GetSocketReady function returns a socket that has sent something to you but can you loop the selector and send to all sockets who are not currently sending to you?

Any hints on how to extend the example to be able to send from the server when it isn't receiving?

EDIT: Seeing as this is supposed to be a 2 player "match" game, do I even need the selector? There's the server player and the client player.
I could save some headaches, right?

4
Graphics / render at 2x?
« on: December 24, 2010, 10:14:57 pm »
Hello,
This is a seemingly simple question but anyways, here it goes.
How do I render my RenderWindow at 2x?
e.g. I have a drawing area of 320x240 and draw it all out. Then when actually displaying the drawn stuff I want it to be 640x480.

Allegro has strech_blit. It works like this:
stretch_blit(buffer, screen,0,0,320,240,0,0,640,480);
this streches the buffer(bitmap) with the size of 320,240 pixels to 640,480 pixels and blits it onto screen(bitmap which is displayed).

Is there a way to do this in sfml?

5
Graphics / [newb] Sprite for every instance?
« on: November 20, 2010, 06:06:31 pm »
I don't know a lot about SFML but it makes me think that you need an sprite "object" for every instance of an actor. Is that right?
I'm transitioning from Allegro where you just pass the image and blit the part you want with srcX,srcY,width,height from a BITMAP to a buffer(and finally to the screen). Is there a way to do that in SFML? I kinda don't trust "renderApp.draw(image);", it's too abstracted.
I really want to start using SFML seriously because of the networking capabilities.
I hope you can shed some light on my curiosity.

6
Graphics / Drawing questions.
« on: July 21, 2010, 12:33:29 pm »
Hello.
Is there a way to draw a sprite/image onto another sprite/image? I want to do some pre-draw manipulations like blends with alpha brushes I made and I can't figure out how. I find this drawing system to be kind of weird.
Maybe I'm just used to Allegro's method, which by the way, is great.

Anyway. Thanks in advance.

7
Graphics / [Solved]Why does this not work (Sprite SetImage problem)
« on: April 11, 2010, 03:59:03 pm »
Hey people
I "just" started using SFML and I am working on a SHMUP
I started by creating some nice functions to load images. But this:
Code: [Select]

    Player p(SHIP);
// OR
    p.assign(SHIP);
doesn't work.

It displays a white box where the ship would be.


main.cpp
Code: [Select]

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

#include "player.h"

#include <iostream>
#include <string.h>

using namespace sf;
using namespace std;


/***
*
*  int bulletLevel=0;
*  game.shootBullet( *OWNER* player, *TYPE* player.bulletLevel);
*  * Game spawnar då de nögvändiga bulletsen och skjuter dom åt OWNERn *
*
*
***/


Image loadSprite(string s);


int main(){

    RenderWindow app(VideoMode(160, 240, 32), "test::sfml");
    app.SetFramerateLimit(60);
    const Input& Input = app.GetInput();
    Clock clock;
    float rate;
    Event event;

    Image PlayerShip = loadSprite("gfx/ship.png");

    Image SHIP;
    SHIP.LoadFromFile("gfx/ship.png");
    SHIP.CreateMaskFromColor(Color(255,0,255));
    SHIP.SetSmooth(false);

    Sprite s(SHIP);
    Sprite f(PlayerShip);

    Player p;
    p.assign(SHIP);





    while (app.IsOpened()){
        rate = app.GetFrameTime();

        while (app.GetEvent(event)){
            if (event.Type == Event::Closed)
                app.Close();
            if ((event.Type == Event::KeyPressed) && (event.Key.Code == Key::Escape))
                app.Close();
        }

        if (app.GetInput().IsKeyDown(Key::Left))  p.move(4,1);
        if (app.GetInput().IsKeyDown(Key::Right)) p.move(6,1);
        if (app.GetInput().IsKeyDown(Key::Up))    p.move(8,1);
        if (app.GetInput().IsKeyDown(Key::Down))  p.move(2,1);



        p.update();




        app.Clear(Color(35, 35, 46));
        p.draw(app);
        //app.Draw(s);


        app.Display();
    }

    return EXIT_SUCCESS;

}

Image loadSprite(string s){

    Image i;
    if (!i.LoadFromFile(s)){ printf("WHATTA"); }
    i.CreateMaskFromColor(Color(255,0,255));
    i.SetSmooth(false);

    return i;
};


player.h
Code: [Select]
#ifndef PLAYER_H_
#define PLAYER_H_
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <string>


using namespace sf;

class Player{
public:
int x,y;
int velx,vely;
int speed;
int w,h;
int cx,cy;
int shoot_speed;
int dir;
Sprite frame;

Player();
Player(Image i);



void update();
void move(int direction, int type);
void assign(Image i);



void nextFrame();


bool off_screen();
void draw(RenderWindow &app);


};
#endif


player.cpp
Code: [Select]
#include "player.h"
#include <string>
#include <iostream>

#define LEFT    4
#define RIGHT   6
#define DOWN    2
#define UP      8
#define TILE_SIZE 16



Player::Player(){
x=32;
y=128;
velx=0;
vely=0;
};

Player::Player(Image i){
x=32;
y=128;
velx=0;
vely=0;
frame.SetImage(i);
frame.SetPosition(x,y);
};


void Player::assign(Image i){

frame.SetImage(i);
frame.SetPosition(x,y);

}
void Player::move(int direction, int type){
    dir = direction;
    if(direction == LEFT){
        velx=-1;
    } else if(direction == RIGHT) {
        velx=1;
    } else if(direction == DOWN) {
        vely=1;
    } else if(direction == UP) {
        vely=-1;
    }
};


void Player::update(){

    x+=velx;
    y+=vely;
    velx=0;
    vely=0;
    printf("%i %i \n",x,y);

};


void Player::draw(RenderWindow &app){

    frame.SetX(x);
    frame.SetY(y);
    app.Draw(frame);

};





Thanks for your time.

PS The images seem to load properly but does not get assigned to the Sprite.

Pages: [1]
anything