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

Pages: 1 ... 19 20 [21] 22 23 ... 34
301
Graphics / Re: Highlighting a sprite when mouse left clicks it
« on: June 02, 2015, 07:41:03 am »
For highlighting, I modified the color of the sprite.

So, by default a Sprite's color is solid black (0, 0, 0, 255), right? I change the color to be (128, 128, 128, 255), and call that my "base" color. That's a pretty standard grey. So your sprite will be a bit lighter when drawn than when you made it in a paint program, so you'll want to take that into account. Then, when I want to make the sprite show as highlighted, I add to it's current color by a certain amount. For me, I found adding by (40, 40, 40, 0) to look decent. I called this value my "color change".

For example, for a Button class I made:
const sf::Color COLOR_CHANGE = {40, 40, 40, 0};
const sf::Color BASE_COLOR = {128, 128, 128};

Button::Button(...)
{
  sprite.setColor(BASE_COLOR);
}

// when I want it to be highlighted
sprite.setColor(BASE_COLOR + COLOR_CHANGE);

// "unhighlight" it
sprite.setColor(BASE_COLOR);

// on press
sprite.setColor(BASE_COLOR - COLOR_CHANGE);

// unpress
sprite.setColor(BASE_COLOR);
 

Work decent enough for my purposes at least. Just another suggestion. :)

302
Feature requests / Re: setTextureOffset() / offsetTexture()
« on: June 01, 2015, 06:30:52 am »
This may be a bit naive, but doesn't sf::Sprite::setTextureRect accomplish pretty much the same thing?

303
You're moving dynamic with it's velocity after you handle the collision. So it's position gets updated relative to that. Handle the collision after moving, I bet that'd fix it.

304
Graphics / Re: Fastest way to update individual pixels
« on: May 29, 2015, 08:13:42 am »
I actually did something like this somewhat recently.

I created a heightmap editor for an old game that still has a community around it.

I essentially made it so 1 pixel represented one tile of the map (thus using a sf::VertexArray of sf::Points), though, this caused problems with zooming, so much like Nexus suggested, I ended up drawing first to a sf::RenderTexture, and then applying the sf::View to the window before drawing the sf::RenderTexture to the window. Works pretty well actually.

Take a look at the code if you want. It was mostly produced late at night, so forgive me on some of the code quality.

Based on what you said, you'd probably be most interested in main.cpp, minus the event handling. You might find some parts of the Map class helpful. HeightZone and HeightEntry will be largely irrelevant, unless you want to see some fun bit-twiddling. :)

305
Graphics / Re: making a rectangle enclosing a text
« on: May 26, 2015, 08:19:13 am »
Not sure if this will fix it, but sf::Font::getLineSpacing() won't do what you're wanting, I think.
I'd make the height of m_rect simply equal to m_text.getCharacterSize().

That way, you get the actual size of a character, rather than the bounding rectangle (which changes if the text changes).

306
Quote
What is static_cast used for, it's a type of conversion from what I understand but what difference does it do to using ( sf::Vector2f ), or does that not work?
static_cast is the preferred way of casting, go read this stackoverflow answer on the differences.

Quote
I can't see anything wrong with just using the vector's constructor here:
I had forgotten about the conversion constructor, hence the explicit cast.

Quote
is 2u supposed to be something specific or just half the window size?
Yes, just half the window size. The 'u' on the end explicitly makes the value an unsigned integer.
I did this because sf::Window::getSize() returns a sf::Vector2u, an unsigned integer vector, not a float vector.

Quote
From what I understand constexpr is like const used for objects and functions, does it have purpose for a simple data type?
Eh, I just like using it when I can, since it's sure to enforce compile-time constants, rather than possible run-time constants.

Quote
This captures the position of the mouse as the mousebutton is pressed and doesn't update right?
Correct, that will only update when a mouse button was pressed or released. I made the assumption that most projectiles don't change direction much after being fired.

Quote
As for using CENTER as a whole, what does it do?
I just used the center of the window as the starting point for the projectiles. You could just replace this with the position of your player or whatnot as needed, it will work the same. Though, if your player ends up changing position, that could pose an issue. So you'd have to store the starting point of the projectile. Or:
line[0].position += -unitVec(line[0].position - line[1].position) * VELOCITY * dt.asSeconds();
line[1].position += unitVec(line[1].position - line[0].position) * VELOCITY * dt.asSeconds();
This way, the projectile will just reuse it's current direction to calculate its movement. Don't forget the negative in front of the first "unitVec", line[0].position - line[1].position will be the opposite direction of the movement, so you have to negate the result to get the opposite of the opposite. Hehe.

Quote
I probably should just read up a lot more til I understand, but vectors, are they just positions for dots right, with x, y , z, etc and the normal is the product of two or more vectors, or does vectors always have a magnitude / normal include together with the position?
Sort of, yes. I like to think of them as: "a displacement from the origin". And oh, wow. My bad. I name the function "vecNormal" when it should have been named "unitVec" or something. (I'll edit that in)
So, the unit vector of a vector, is itself divided by its magnitude.

307
Personally, you're doing it the hard way.

Try vector math! Makes stuff like this much easier.

For example:
// constants
const sf::Vector2f CENTER = static_cast<sf::Vector2f>(window.getSize() / 2u);
constexpr float LENGTH = 35.f;
constexpr float VELOCITY = 122.f;

// the projectile
sf::VertexArray line(sf::Lines, 2);

// calculate projectile direction based off: mouse press location and center of window
sf::Vector2f mousePos = {static_cast<float>(event.mouseButton.x), static_cast<float>(event.mouseButton.y)};
sf::Vector2f projEndNorm = unitVec(mousePos - CENTER);
line[0].position = CENTER + projEndNorm;        // offset from the center slightly so: line[0].position - CENTER != {0, 0}
line[1].position = projEndNorm * LENGTH + CENTER;

// update
line[0].position += unitVec(line[0].position - CENTER) * VELOCITY * dt.asSeconds();
line[1].position += unitVec(line[1].position - CENTER) * VELOCITY * dt.asSeconds();

// the unitVec function:
sf::Vector2f unitVec(const sf::Vector2f& vec)
{
        if(vec.x != 0 && vec.y != 0)
                return vec / std::sqrt(vec.x * vec.x + vec.y * vec.y);    // vector / length = unit vector of the vector
        else
                return {0, 0};
}
 

Unit Vector Definition

Minimal and Naive Example if you need it

308
Forgive me if I'm oversimplifying the problem, but couldn't you just make the color value of the vertices in your VertexArray that are close to your player semi-transparent? I don't think you'd need a shader for this.

309
Personally, if a switch can be used, I use it, as I find it a bit easier to read.

In some cases, if the case values are not spaced out (ie: 1,2,3,4,5 vs 1,4,7,12), a compiler can optimize a switch to be a bit more performant (jump tables). But good compilers could also do the same with a series of if-else statements, so it's kinda up in the air.

Really just comes down to personal preference of readability.

310
SFML projects / Re:creation - a top down action rpg about undeads
« on: May 20, 2015, 08:59:41 pm »
I see the method Jabberwocky is talking about. The idea is that there isn't one vector for all Components, there are multiple vectors, one for each Component type.

I went with something very similar to what he is describing.

One system per component type, which contains a vector of all Components of that type (well in a container I called an "AssocMap" (I should rename it to something like "AssocVector"), which is essentially a combined vector/hash map so I can access Components via entity ID, but also have sequential memory storage. Prolly not a novel concept or even a best solution, but I liked the result).

My System Implementation

Then "entities" are simply an ID number, for which I use just use an unsigned int.

It's a little out of date, I have some changes I haven't pushed yet, but it should get my underlying concept across. :)


Anyway, as others have said, I'm absolutely loving the art and the art style!

311
If you want a Sprite that keeps the original texture, then yes, I would use a second Sprite.

312
All your drawing to the window is the bgSprite, why would you expect anything else?

You're not drawing the results of drawing to the RenderTexture's to the window, is what I mean.

313
General / Re: PONG Game Menu Events
« on: May 14, 2015, 09:44:15 pm »
case Game::Paused:
      ShowInGameMenu();
      break;
case Game::ShowingOptionMenu:
      ShowOptionMenu();
case Game::ShowingSplash:
      ShowSplashScreen();
      break;
 

You're missing a break statement after the call to ShowOptionMenu.

314
SFML projects / Re:creation - a top down action rpg about undeads
« on: May 14, 2015, 07:20:30 pm »
What about security? Everyone can see and edit scripts.
You recommend encode them to binary/resource files, or compile as libraries? What's your method?

There are plenty of Lua decompilers out there, and the output tends to be pretty straightforward.

Can you tell me the advantages of using scripts instead of just writing it in c++? I was just thinking how hard can it be to just translate the lua into c++ and then not have to use another language.

1. You don't have to recompile the whole game every time you make a change.

2. Lua is more flexible than C++ in some ways, which can make some tasks easier to accomplish in Lua.

3. Lua is a higher-level language than C++, generally, you can get more done in less time.

4. Makes it easier to include modding support.

5. Helps to keep your C++ code clean. Less implementation specific stuff clogging it up.

6. Almost requires a good design for your C++ code. Having messy C++ code can make it more difficult to bind it to Lua.

315
General / Re: Diamond Square
« on: May 11, 2015, 01:40:28 am »
I'm not sure there is even a 1D version of the Diamond Square... I mean, it's whole concept is based on a 2D grid iirc.
wikipedia.

Pages: 1 ... 19 20 [21] 22 23 ... 34