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

Pages: [1] 2 3
1
General / Re: Collision between mouse and convex shape
« on: June 22, 2015, 06:07:18 pm »
I'm pretty sure I wouldn't have such E-shape shapes in my project. But I thought about this problem shadowmouse mentioned. I might have a line crossing two edges of a shape, but the mouse could still be outside the shape. So I should keep a track of number of edges the line intersects and if this number is greater than 0 and is odd then mouse should be inside shape. If this number is even, I can assume the mouse is outside.

2
General / Re: Collision between mouse and convex shape
« on: June 22, 2015, 05:48:56 pm »
It sounds like a simple and fast solution, perhaps it might be the one I'm looking for since I'm detecting collision between mouse and shape only. Thanks.

3
General / Re: Collision between mouse and convex shape
« on: June 22, 2015, 05:20:51 pm »
Thanks for your answers. Yes, I know that collision detection is a really big topic, but I thought you might get me into solution that would be best suitable for convex shape. I'll read about SAT and try to do something with this array of bits and collision mask.

The thing is I need to check collision between mouse and a convex shape. I don't need to check collision between sprites or two shapes, I have a one point and I need to check if it's within a certain shape, so at least it's that easier.

4
General / Collision between mouse and convex shape
« on: June 22, 2015, 04:41:23 pm »
I'd like to detect collision between mouse and convex shape, but I have no idea how can I do that. I need a pixel-perfect collision, so getGlobalBounds() method won't do here. I need to know if the mouse is inside my convex shape or not. What's the best way to achieve that?

5
Graphics / Re: Nothing is drawn (inheriting from Drawable)
« on: April 10, 2015, 02:03:05 am »
Thanks, I fixed that and now it works! I'm glad and ashamed at the same time that I did a common mistake.

Quote from: zsbzsb
why are you basically implementing your own vector class?

Actually I'd like to check by myself if my own class will work faster than vector. At least writing this kind of vector class is a good practice.

6
Graphics / Nothing is drawn (inheriting from Drawable)
« on: April 10, 2015, 01:35:26 am »
Hello,

I'm starting this little project and I started with writing a Room class. Room is a single board that we see in the game, like a street, a lab room. Room consists of layers. This should allow me to do some nice work with z order. I don't know how many layers each room will have - one could have only 2 layers, second 5 layers and third 3 layers. So creating a simple array with a constant number of elements wouldn't do the trick, it would be useless consuming too much memory. Therefore I thought about vector. But personally I don't really like vector, it also can consume much memory. I decided to create my own easy template class for some dynamic array. I did that and I think it works okay right now (although there are some things that I could improve, but that's not a matter of my problem). Once I created my dynamic array class I, of course, began writing Room class. I started with a constructor, deconstructor and a method for adding layers. I've done drawing by making Room class inherit from Drawable (so in the game loop I can do something like this: window.draw(myroom)). I overrode draw method correctly, I think... And so, I created a Room object and I added one layer to it, pressed F7, then F5 and... Nothing is drawn. There's only a white sprite in the place where my background should be visible. This white sprite's position is the same as the position given in the parameter in the add layer function, so I think it kinda works... Something there works, but something doesn't. And I have no idea what doesn't. Here's the complete code I have (it's not long):

DArray.h
Code: [Select]
#ifndef DARRAY_H
#define DARRAY_H

#include <iostream>

using namespace std;

template<class Foo>
class DArray {
private:
struct node {
Foo data;
node* ptr;

node(Foo d) {
data = d;
ptr = NULL;
}
};
node* first;
int counter;

public:
DArray();
~DArray();
void push(Foo d);
Foo pop();
int size() const;
bool empty();
Foo& operator[](int i) const;
};

template<class Foo>
DArray<Foo>::DArray() {
first = NULL;
counter = 0;
}

template<class Foo>
DArray<Foo>::~DArray() {
while (!empty())
pop();
}

template<class Foo>
void DArray<Foo>::push(Foo d) {
if (empty()) {
first = new node(d);
}
else {
node* tmp = first;
while (tmp->ptr != NULL)
tmp = tmp->ptr;
tmp->ptr = new node(d);
}
counter++;
}

template<class Foo>
Foo DArray<Foo>::pop() {
if (!empty()) {
Foo d;
node* tmp;
tmp = first;
first = first->ptr;
d = tmp->data;
delete tmp;
return d;
}
}

template<class Foo>
int DArray<Foo>::size() const {
return counter;
}

template<class Foo>
bool DArray<Foo>::empty() {
if (first == NULL)
return true;
else
return false;
}

template<class Foo>
Foo& DArray<Foo>::operator[](int i) const {
node* tmp = first;

for (int j = 1; j < i+1; j++) {
tmp = tmp->ptr;
}

return tmp->data;
}

#endif

Room.h
Code: [Select]
#ifndef ROOM_H
#define ROOM_H

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

using namespace sf;
using namespace std;

struct Layer {
Texture tex;
Sprite spr;
//id, name

Layer() { }

Layer(const string path, Vector2f pos) {
tex.loadFromFile(path);
spr.setTexture(tex);
spr.setPosition(pos);
}
};

class Room : public Drawable {
private:
DArray<Layer> layers;
//int id;
//string name;

virtual void draw(RenderTarget& target, RenderStates states) const {
for (int i = 0; i < layers.size(); i++) {
target.draw(layers[i].spr, states);
}
}

public:
Room();
~Room();
void AddLayer(const string path, Vector2f pos);
//void RemoveLayer();
//show layers' names
};

#endif

Room.cpp
Code: [Select]
#include "Room.h"

Room::Room() {

}

Room::~Room() {

}

void Room::AddLayer(const string path, Vector2f pos) {
layers.push(Layer(path, pos));
}

GameApp.h
Code: [Select]
#ifndef GAMEAPP_H
#define GAMEAPP_H

#include <SFML\Graphics.hpp>
#include <iostream>
#include "Room.h"

using namespace sf;
using namespace std;

class GameApp {
private:
RenderWindow win;
bool fullscreen;
Event evt;
double dt, dwticks, dwnewticks;
Clock main_clock;

public:
GameApp();
~GameApp();
void Run();
//void ToggleFullscreen();
};

#endif

GameApp.cpp
Code: [Select]
#include "GameApp.h"

GameApp::GameApp() {
fullscreen = false;
dt = dwticks = dwnewticks = 0.f;

win.create(VideoMode(800, 600), "PNC", fullscreen ? Style::Fullscreen : Style::Default);
win.setFramerateLimit(60);
win.setVerticalSyncEnabled(true);
win.setMouseCursorVisible(true);
}

GameApp::~GameApp() {

}

void GameApp::Run() {
main_clock.restart();
dwticks = main_clock.getElapsedTime().asMilliseconds();

Room str;
str.AddLayer("data/rooms/str/gfx/bgr.jpg", Vector2f(0, 50));

while (win.isOpen()) {
if (win.pollEvent(evt)) {
if (Keyboard::isKeyPressed(Keyboard::Key::Escape) ||
evt.type == Event::Closed) {
win.close();
}
}
else {
dwnewticks = main_clock.getElapsedTime().asMilliseconds();
dt = dwnewticks > dwticks ? (dwnewticks - dwticks) / 4000.f : 0.f;
dwticks = dwnewticks;

win.clear(Color(0, 0, 0));
win.draw(str);
win.display();
}
}
}

main.cpp
Code: [Select]
#include "GameApp.h"

int main() {
GameApp game;

game.Run();

return 0;
}

When I replaced the const string path parameter in Layer constructor with Texture& t (and also did the same changes in add layer method) and then in the Run() method in GameApp class I created a texture:

Code: [Select]
Texture t;
t.loadFromFile("data/rooms/str/gfx/bgr.jpg");

and passed it to the parameter as this:

Code: [Select]
Room str;
str.AddLayer(t, Vector2f(0, 50));

it did the trick. Background shows correctly that way. But I want it to work also with that string parameter.

I'd be forever ashamed if I did something really stupid.

7
Graphics / Re: Font with outline is transparent
« on: December 18, 2014, 08:52:53 pm »
OK then, I thought it's actually white. Thanks!

8
Graphics / Font with outline is transparent
« on: December 18, 2014, 08:32:26 pm »
Hi there,

I downloaded this font: http://www.1001freefonts.com/snacker_comic.font. It is supposed to be white with black outline. But in my project I get this instead:
http://i.imgur.com/iLoo8ko.png
You see, outline is ok, it is black. But the rest of the font color is transparent and I don't know why. I saw that I have the same problem in Paint - this font just won't work properly.

In my project I have two variables, a font and a text, I load and set them as this:
//there's using namespace sf somewhere up there

Font snacker;
Text example;

snacker.loadFromFile("data/fonts/snacker.ttf");

example.setFont(snacker);
example.setCharacterSize(26);
example.setColor(Color::Black);
example.setStyle(Text::Regular);
example.setPosition(Vector2f(630, 360));
example.setString("Pizza Box");

Is there any chance that this font would work?

9
System / Smoothing mouse movement
« on: October 19, 2014, 06:07:42 pm »
Hi,

I'd like to move a sprite by moving a mouse. First, I decided to use a setPosition() method:

Code: [Select]
double mx, my;
mx = my = 0.f;

...

//in main loop
mx = Mouse::getPosition().x;
my = Mouse::getPosition().y;

mysprite.setPosition(mx, my);

And it actually did the trick, but it's definitely not the perfect solution. Because Mouse::getPosition() returns Vector2i the movement is not smooth and you can clearly see that. So I did this:

Code: [Select]
double mx, my, lastMX, lastMY;
mx = my = lastMX = lastMY = 0.f;

...

//in main loop
mx = Mouse::getPosition().x;
my = Mouse::getPosition().y;

mysprite.move((mx - lastMX), (my - lastMY));

lastMX = Mouse::getPosition().x;
lastMY = Mouse::getPosition().y;

It's not bad, the movement is smoother, but still I think it can be done better. I tried to multiply (mx - lastMX) and (my - lastMY) by deltatime and some constant speed, but that was... Ugh, not good. I'm out of ideas. What can I do to make a mouse movement smooth?

10
General / Re: Grid similar to that found in editors
« on: August 27, 2014, 07:05:49 pm »
OK, thanks! I will try that out :)

11
General / Grid similar to that found in editors
« on: August 27, 2014, 06:42:42 pm »
Hi,

I'm writing a program and I was wondering how to make a grid just like that which can be found in all sort of editors (UDK, UE4, 3d modelling apps). A grid which responds to mouse - which can be moved by dragging a mouse and can be scaled when we move mouse wheel. Any ideas how to do that?

12
I downloaded nightly build for Visual 2013 and now everything works. Thanks!

13
SFML 2.1, official binary. My IDE is Visual Studio 2013.

No, I haven't tried debugger. I'll give it a try.

14
I have a class that has Text and Font variables:

Code: [Select]
using namespace sf;

class MyClass {
private:
   Font times;
   Text song_name;

public:
   MyClass();
   ~MyClass();
   void DrawMethod(RenderWindow&);
};

In constructor I load font, I set song_name font, song_name character size, color - that works fine. But when I try to use setString I get an unhandled exception error.

Code: [Select]
MyClass::MyClass() {
   times.loadFromFile("C:/Windows/Fonts/times.ttf");

   song_name.setFont(times);
   song_name.setCharacterSize(16);
   song_name.setColor(Color::White);
   song_name.setStyle(Text::Bold);

   //***Above works!***
   //But this doesn't:
   song_name.setString("and here's some text");
}

Same happens when I try to draw my text:

Code: [Select]
void MyClass::DrawMethod(RenderWindow& win) {
   win.draw(song_name);
}

What's happening?

15
Audio / Re: How can I know if the song ended or not?
« on: June 08, 2014, 03:01:21 pm »
I know, but honestly I have no idea why SoundSource::Stopped is working and Music::Status::Stopped isn't. Perhaps it's something with my IDE and the version of SFML I am using. I'm working on Visual Studio 2013 and I currently have SFML 2.1 for Visual 2010.

Pages: [1] 2 3
anything