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

Pages: [1]
1
DotNet / Re: SFML Events w/C#.NET
« on: January 27, 2013, 10:17:36 pm »
Thank you for clarifying.

2
DotNet / SFML Events w/C#.NET
« on: January 27, 2013, 09:22:58 pm »
I'm trying to figure out how to register events in SFML.NET, and I'm clueless. I'm looking for tutorials, but a no go.

This is my code so far:
using System;
using SFML.Audio;
using SFML.Window;
using SFML.Graphics;

namespace Example
{
    class Program
    {
        static void OnClose(object sender, EventArgs e)
        {
            // Close the window when OnClose event is received
            RenderWindow window = (RenderWindow)sender;
            window.Close();
        }

        static void Main(string[] args)
        {
            // Create the main window
            System.Threading.Thread.Sleep(1000/50);
            RenderWindow window = new RenderWindow(new VideoMode(1024, 768), "Game");
            window.Closed += new EventHandler(OnClose);
            // Load a sprite to display
            Texture texture = new Texture("Graphics/mainCharStand.PNG");
            Sprite sprite = new Sprite(texture);
            // Start the game loop
            while (window.IsOpen())
            {
                // Process events
                window.DispatchEvents();
               
                // Clear screen
                window.Clear();

                // Draw the sprite
                window.Draw(sprite);

                // Update the window
                window.Display();
            }

        }
    }
}
 

Is this how you register events? Or am I mistaken.
window.Closed += new EventHandler(OnClose);

3
I'm getting a divide by zero exception when I try to draw to and display a window.

Main Class:
#include "stdafx.h"

bool keys[];
stickman* player;
sf::RenderWindow window(sf::VideoMode(640, 640), "StickRPG");

int main()
{
        player = new stickman(150, 300, 300);
        sf::Clock clock;
        window.setFramerateLimit(30);
    while (window.isOpen())
    {
                sf::Event event;
                while (window.pollEvent(event))

                {
                    if (event.type == sf::Event::Closed)
                        {
                                window.close();
                        }

                        // Drawing Code
                        window.clear();
                        player->draw(&window);
                        window.display(); // Sometimes error occurs here
                }
        }

        return 0;
}

stdafx.h:
#pragma once

#include "targetver.h"

#include <iostream>
#include <stdio.h>
#include <tchar.h>

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

#include "stickman.h"

stickman.h:
#ifndef __STICKMAN_H_INCLUDED__
#define __STICKMAN_H_INCLUDED__

class stickman
{
public:
        stickman(int size, int x, int y);
        virtual ~stickman();
        void draw(sf::RenderWindow *window);
protected:
        sf::Sprite cs;
        sf::Sprite llr;
        sf::Sprite lll;
        sf::Sprite lal;
        sf::Sprite lar;
        sf::Sprite ull;
        sf::Sprite ulr;
        sf::Sprite ual;
        sf::Sprite uar;
        sf::Vector2f armr;
        sf::Vector2f arml;
        sf::Vector2f legr;
        sf::Vector2f legl;
        sf::Vector2f p;
        sf::Vector2f n;
};

#endif

stickman.cpp:
#include "stdafx.h"

stickman::stickman(int size, int x, int y)
{
        double chest = size*.34;
        double lowerarm = size*.255;
        double lowerleg = size*.29;
        double upperarm = size*.16;
        double upperleg = size*.245;

        sf::Image ig;
        sf::Image ig1;
        sf::Image ig2;
        sf::Image ig3;
        sf::Image ig4;

        sf::Texture t;
        sf::Texture t1;
    sf::Texture t2;
        sf::Texture t3;
        sf::Texture t4;

        ig.create(2, floor(chest), sf::Color(255, 255, 255, 150));
        t.loadFromImage(ig);
        this->cs.setTexture(t);

        ig1.create(2, floor(lowerarm), sf::Color(255, 255, 255, 150));
        t1.loadFromImage(ig1);
        this->lal.setTexture(t1);
        this->lar.setTexture(t1);

        ig2.create(2, floor(lowerleg), sf::Color(255, 255, 255, 150));
        t3.loadFromImage(ig2);
        this->lll.setTexture(t2);
        this->llr.setTexture(t2);

        ig3.create(2, floor(upperarm), sf::Color(255, 255, 255, 150));
        t3.loadFromImage(ig3);
        this->uar.setTexture(t3);
        this->ual.setTexture(t3);

        ig4.create(2, floor(upperleg), sf::Color(255, 255, 255, 150));
        t4.loadFromImage(ig4);
        this->ull.setTexture(t4);

        this->n.x = x;
        this->n.y = y;
}


stickman::~stickman(void)
{
}
int round(double number);
void stickman::draw(sf::RenderWindow* window)
{
        this->cs.setPosition(this->n.x, this->n.y);
        this->ual.setPosition(this->n.x, this->n.y);
        this->uar.setPosition(this->n.x, this->n.y);
        this->uar.setRotation(45.0f);
        this->ual.setRotation(315.0f);
        this->lal.setPosition(this->ual.getPosition().x-round(this->ual.getGlobalBounds().height), this->ual.getPosition().y+round(this->ual.getGlobalBounds().width));
        this->lar.setPosition(this->uar.getPosition().x+round(this->uar.getGlobalBounds().height), this->uar.getPosition().y+round(this->uar.getGlobalBounds().width));
        window->draw(this->cs);
        window->draw(this->uar); // Error occurs here
        window->draw(this->ual);
        window->draw(this->lal);
        window->draw(this->lar); // Through here
}

int round(double number)
{
        int remainder = number-number;
        if (remainder >= 0.5) {
                return floor(number);
        } else {
                return ceil(number);
        }
}
 

I have been working on this the entire day, I have no idea what is the problem.

4
General / Re: Peculiar Link Error?
« on: January 03, 2013, 01:56:58 am »
So that's the problem. Your settings must be consistent (read the tutorial again if you don't know what you do).
I never knew it mattered, thank you.

5
General / Re: Peculiar Link Error?
« on: January 02, 2013, 08:14:32 am »
I linked it dynamically, I believe. But I defined static in the preprocessor anyways.

6
General / Peculiar Link Error?
« on: January 02, 2013, 07:57:03 am »
I am getting trouble from referencing a RenderWindow to another method.
I get this error:
error LNK2001: unresolved external symbol "public: static class sf::RenderStates const sf::RenderStates::Default" (?Default@RenderStates@sf@@2V12@B)
Here is the code in the main class that might assist you:
#include "stdafx.h"
stickman* player;
sf::RenderWindow window(sf::VideoMode(640, 640), "StickRPG");
player->draw(&window); // This is the piece of code that generates the error.
Here is the code in stdafx.h:
#ifndef STDAFX_H_
#define STDAFX_H_

#include "targetver.h"
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <stdio.h>
#include <tchar.h>
#include "stickman.h"

#endif /* STDAFX_H_ */
Here is the code in stickman.h:
#ifndef __STICKMAN_H_INCLUDED__
#define __STICKMAN_H_INCLUDED__

class stickman
{
public:
        stickman(int, int, int);
        virtual ~stickman();
        void draw(sf::RenderWindow *window);
protected:
        int size;
        double upperarmR;
        double upperarmL;
        double upperlegR;
        double upperlegL;
        double lowerarmR;
        double lowerarmL;
        double lowerlegR;
        double lowerlegL;
        double chest;
        sf::Sprite cs;
        sf::Sprite llr;
        sf::Sprite lll;
        sf::Sprite lal;
        sf::Sprite lar;
        sf::Sprite ull;
        sf::Sprite ulr;
        sf::Sprite ual;
        sf::Sprite uar;
        sf::Vector2f armr;
        sf::Vector2f arml;
        sf::Vector2f legr;
        sf::Vector2f legl;
        sf::Vector2f p;
        sf::Vector2f n;
};

#endif
Here is the method I am using in stickman.cpp:
void stickman::draw(sf::RenderWindow* window)
{
        this->cs.setPosition(this->n.x, this->n.y);
        this->ual.setPosition(this->n.x, this->n.y);
        this->uar.setPosition(this->n.x, this->n.y);
        this->ual.setRotation(315);
        this->ual.setRotation(45);
        window->draw(this->cs);
        window->draw(this->ual);
        window->draw(this->uar);
}

Thank you.

7
Graphics / Re: SFML 2.0 Image Dimension Setting Problems?
« on: December 26, 2012, 11:59:25 pm »
Thank you, it worked.

8
Graphics / SFML 2.0 Image Dimension Setting Problems?
« on: December 26, 2012, 11:42:32 pm »
I am attempting to create an image, as seen:
sf::Image i1(32, 32, sf::Color(0, 255, 0));
Although, for the first argument, 32, where I try to set the dimension, it gives me this error:
no instance of the constructor "sf::Image::Image" matches the argument list
Very peculiar, I'm rather new to SFML, and I have no idea how to fix this.

Pages: [1]