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

Pages: 1 [2]
16
Graphics / Re: is it possible to rotate a line?
« on: January 17, 2020, 09:00:15 am »
Rotating is usually done like this:

x = center.x + radius * cos(angle);
y = center.y + radius * sin(angle);

// switch +- or sin/cos depending on your axes directions and where you want 0° to be


Or you can use a properly configured sf::Transform that you pass when drawing the vertices.

@Laurent, thanks so much this did it. I incremented the angle by += 0.1 for a slow effect for cos(angle) and sin(angle) and it's spinning. Just out of curiosity, how can I use sf::Transform properly to pass through vertices? I was having trouble with transform and lines.

17
Graphics / is it possible to rotate a line?
« on: January 16, 2020, 10:25:18 pm »
I'm having a tiny brain fart and sorry if it seems very simple to figure out, but i cant seem to rotate a line. I'm using 2 points using
Code: [Select]
sf::Vertex lines[] = {
        sf::Vertex(sf::Vector2f(pos)),
        sf::Vertex(sf::Vector2f(pos.x + ret.getRadius(), pos.y)) // <-- this one is the radius line
    };
w.draw(lines, 2, sf::Lines);
-or-
Code: [Select]
sf::Vertex lines[2];
    lines[0].position = sf::Vector2f(pos);
    lines[0].color = sf::Color::Yellow;
    lines[1].position = sf::Vector2f(pos.x + ret.getRadius(), pos.y); // <-- this one is the radius line
    lines[1].color = sf::Color::Yellow;
    w.draw(lines, 2, sf::Lines);

its for my stroke circle. I want to rotate just the radius line around the circle's center point around and around like a spinning radar and cant seem to use rotate or transform on these lines, or maybe I'm doing it wrong? I can rotate an image using trig but thought this may be possible as well

18
If you only scale your sprite, then you can simplify this and just divide mouse coordinates by the scale factor.

Oh man, thank you so much Laurent this worked perfectly! Why couldn't I figure that out damn my feeble brain, you are a genius! Now I don't need to spend hours doing mind numbing photoshop resizes phew!!! :D

19
I've been searching for days on google and reddit and other forums but I can't seem to figure it out. And if there is already a solution for this then I apologize for duplicates...

What I want is to test my mouse point on getPixel() for rgba values but that can only be done with sf::Image which I understand.

However, after I setScale with sprite I realize that the resize doesn't apply to the original image. Is there a way to resize the sf::Image somehow so that the scale updates as well?

For example, i have a star image that's width 50 and height 48 with a transparent background as star.png. I can set a sf::Texture and then sf::Sprite sprite(starImage) then setScale(2, 2) which doubles; but when I try to getPixel() for the image from sf::Image image = starImage.copyToImage() I get the original dimensions and not the doubled.

I feel like I'm missing something or is this not possible? I suppose I can just resize the original star png file and all the other png files ahead of time manually in photoshop to fit the window but is there an easier way? Thanks in advance.

20
General / Re: SFML, how to learn it
« on: October 12, 2019, 11:30:32 pm »
@albert_lazaro hey man, have you had any prior experience with game development? Jumping into a project like that can be frustrating because there might be concepts in there that you might not fully understand. What I did to get started with SFML was I ported javascript html5 canvas animations to SFML and from there I understood c++ more and more.

I started with tiny concepts such as collision detection, particle animations, physics for gravity/friction, as well as c++ knowledge like databases, memory management, and pointers/references. From practicing on those I could gradually piece them together and then be confident enough to jump into projects. But if you already have prior c++ knowledge/game dev then by all means just hope you have more time to spend on coding.

But I always say practice whenever you have the chance and always write it down or have a block diagram of what your vision is. Sometimes when I just code away without a guideline I'll paint myself into a corner so to speak and then dread that I'd have to start from scratch again. Anyway, Good luck!

21
General / Re: adding sf::Vector2f ?
« on: September 17, 2019, 05:51:48 pm »
@Nexus nice! I'll check these out cheers!

22
General / Re: adding sf::Vector2f ?
« on: September 17, 2019, 07:47:49 am »
Ok thank you. I suppose I don't really need to multiply vectors but thought I'd ask since I was wondering why addition and subtractions were there. I don't really have any use for vector multiplication, at least not yet.

23
General / Re: adding sf::Vector2f ?
« on: September 17, 2019, 04:43:02 am »
I apologize, that's what I meant to say overload operators not functions :D. By the way, after much experimentation I can't seem to find a multiplication for vectors.

For example:
Code: [Select]
float a = 5.f,
      b = 6.f,
      x = 8.f,
      y = 9.f;
sf::Vector2f apos(a, b);
sf::Vector2f bpos(x, y);
sf::Vector2f cpos;

cpos = apos + bpos; // 13 and 15
cpos = apos - bpos; // -3 and -3
// however
cpos = apos * bpos; // error no match for operator*
// But a scalar value works such as
cpos = apos * 4.f // output is 20 and 24

24
General / Re: adding sf::Vector2f ?
« on: September 16, 2019, 06:06:46 am »
Oh that's right overload functions. I completely forgot about that, ok thank you.

25
General / adding sf::Vector2f ?
« on: September 15, 2019, 05:47:04 am »
+Just a quick question,
 
is it possible to add multiple sf::Vector2f? For example I have a apos.x and apos.y in the form of sf::Vector2f apos.
If I have another sf::Vector2f bPos is there a way to .add() them like something equivalent in p5 js? Or do I just do apos.x + bpos.x  and then apos.y + bpos.y etc..? Thanks in advance!

26
Graphics / Re: "destination-over" equivalent
« on: May 31, 2019, 01:36:35 am »
Holy crap, I slept it over and spent all morning on this breaking it down step by step. I figured it out. SFML is so simple. You don't need destination-over because the way you draw it or call the function to draw will determine if its in front or behind.

So another thing was I didn't realize vectors had .insert() instead of push_back() and that completely changed everything. So doing a reverse iteration loop and insert instead of push_back solved my issue.

Now I have no flickering when removing objects and the trail effect it leaves behind is correctly placed behind the ball objects. Oh man, this was the most headache inducing problem I had to face yet. Now I can happily port javascript canvas rendering to c++ sfml to determine the performance!

27
Graphics / Re: "destination-over" equivalent
« on: May 30, 2019, 10:19:38 am »
Sure thing. What happens is when I iterate forward to draw my ball objects, later I want to remove the 1st element in that vector. The problem with removing the 1st element in the vector during an increment loop is that element at index 0 is gone, and so the vector shifts and then the next iteration there's a split second where nothing is drawn, hence that little flicker.

However when I do a reverse iteration loop, it checks backwards and so I can now remove the 1st element in that vector (0) ,and it wont affect my next draw so it's one way of preventing flickering But the problem is now the trail effect is placed in front the ball object.  Conversely when I do a forward loop the placement of the trail effect is correct (trail is behind the inital ball object) but flickering occurs when those balls are removed.

My problem is, is it possible to have the correct placement of the trails effect using the correct loop and not have flickering as well.

I can take pictures if you need more info. Hopefully it wasnt more confusing.

28
Graphics / "destination-over" equivalent
« on: May 30, 2019, 01:44:42 am »
Hello there,
I'm coming from javascript where if you're experiencing objects flickering when getting rid of objects in an array, you can do a reverse loop to prevent objects from flickering, however the rendering of the images are in front of the initial object (such as in a trail effect) and to remedy this you use something called ctx.globalCompositeOperation = "destination-over" where the trail effects will be drawn behind the initial object instead.

Is there a similar remedy in sfml c++? I can't seem to find any documentation or anything related through google searches for drawing objects behind something. I know you can literally window.draw() after another to show it in the foreground but when Im looping through an object's trail it doesnt seem to work.

What happens is when I use a normal incrementing for loop, the ball created will show a trailing effect behind the new ball (correctly) but during removal of each ball there is a 'flickering' for existing balls. This can be solved by doing a reverse loop decrement instead but then the rendering is changed where each new ball will be behind the older created ball.

I want the no flickering AND where the new object will be in front of the ball but a reverse loop doesnt seem to solve both these issues. An incrementing for loop will solve the draw placement but flickering occurs, but decrement for loop will solve the flickering but draw placement is wrong. And there doesn't seem to be a "destination-over" or "source-over" equivalent to solve this issue.

Is there a way to solve both the flickering and the new ball to be drawn in front of the older? Thx in advance!

Pages: 1 [2]
anything