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

Pages: 1 2 3 [4] 5 6 ... 27
46
General / Re: How to implement character control with the mouse
« on: September 13, 2017, 07:50:23 pm »
Can you tell me how correctly or incorrectly I implemented it?

Does your implementation work like you expect? Then you did it correctly :).

There is one thing which might not work like you expect: Your character will move faster when farther away from the cursor, because you take the distance vector and not the direction in your calculation. So I would recommend the following for your movement vector:
if ( Mouse::isButtonPressed(Mouse::Right) )
{  
    Vector2f totalMovement;
    totalMovement.x = Mouse::getPosition(window).x - hero_sprite.getPosition().x;
    totalMovement.y = Mouse::getPosition(window).y - hero_sprite.getPosition().y;
    // Create a unit vector, to move at constant speed
    totalMovement /= std::sqrt(std::pow(totalMovement.x, 2) + std::pow(totalMovement.y, 2))
    hero_sprite.move(totalMovement * (1.f/1000.f)); //1/1000 should then be choosen bigger like 5
}

This will make your character move at the same speed independent from the distance to the mouse


AlexAUT

47
General / Re: Win32 console
« on: September 13, 2017, 07:02:02 am »
Please do a quick google search before you make a new thread. There are already 50 threads about that topic and there is also a section in the FAQ about that:

https://www.sfml-dev.org/faq.php#tr-win-console


AlexAUT

48
General / Re: How to implement character control with the mouse
« on: September 08, 2017, 08:40:51 pm »
Basically you need to calculate a movement vector for your character based on the mouse position. So you need two things:
  • Angle from the character to the cursor, which is also the rotation of the character/sprite
  • The distance, so you can implement a "deadzone", i will explain later why this is needed

You get the angle by using simple geometry, as described here
Getting the distance is also not very difficult

With these two values we can move the character by calculating a movement vector. This can be easily derived from the angle

  sf::Vector2f movement = sf::Vector2f(cos(angle), sin(angle)) * movementSpeed;
where angle is a float (in radiant) from (1) and movementSpeed is a float which you can set.

Now you have everything you need to move your character
   yourCharacter.move(movement );
You need to take the frametime into account to get a nice and smooth result, as described here

Also there is another small problem, the character will start spinning around your cursor once it has reached it. Because it will move a bit to far "over" the cursor and in the next frame it will "bounce" back. To avoid this you need a deadzone, which should look like this (modify the part above with the deadzone):
  const float DEAD_ZONE = some_amount_based_on_movementSpeed
  if(distance > DEAD_ZONE)
  {
       yourCharacter.move(movement);
  }
 
Where distance is described in (2)


I hope this gives you a basic idea how to tackle this problem.

AlexAUT

49
General / Re: TGUI & SFML - "pressed" event
« on: July 30, 2017, 10:11:31 pm »
TGUI has his own forum (https://forum.tgui.eu/) and the creator Texus is very usally very active there.

Also the code you provided does not show the actual callback of the button.


AlexAUT

50
Window / Re: two keyboard keys pressed at the same time?
« on: July 23, 2017, 09:45:34 pm »
well...using event for it can be tough but I think it can be done...I'll try to experiment on it

You would need to store the state of each key (e.g. std::array<bool, sf::Keyboard::KeyCount>). On the KeyPressed Event you set it to true for the key which fired the event, and in the KeyReleased you will reset the bool to false. This does also decouple your input checking from the input handling.

However events will be a tiny bit delayed because they have to go throught the OS/SFML event queue. So for a game you should use the sf::Input::isKeyPressed function for keys which sate changes rapidly. (or for all keys and change it to a hybrid system if the polling of many keys is a problem)
 


AlexAUT

51
Graphics / Re: Color filling algorithm for pseudo-concave shape
« on: July 23, 2017, 09:22:32 pm »
I would duplicate the corner points of the polygon and move them along their angle bisector. Then you get the polygon as in the attachement. The green line is the amount you move the duplicated points.
Now if you want to have it in the normal status, give every point the same color. If you want the "glow" effect, give the border points a brighter color.

sf::ConvecShape (sf::Shape) does only support one fill color therefore you will need to use sf::VetexArray, which is the way to go anyways if you want to draw several thousand polygons.



PS. I'm not sure if this is possible with a simple vertex/fragment shader, but with a geometry shader this would also be possible to achieve.


AlexAUT

52
General / Re: Android, how to know if GL context is lost?
« on: February 17, 2017, 04:43:02 pm »
The Android code isn't published, but at the time the lowMemory and onSaveState weren't handled by SFML, so I implemented them myself and recompiled SFML


Edit:
Just had a quick look, and they still aren't implemented (https://github.com/SFML/SFML/blob/master/src/SFML/Main/MainAndroid.cpp#L451-L462).


AlexAUT

53
General / Re: Android, how to know if GL context is lost?
« on: February 16, 2017, 02:48:18 pm »
It has been quite some time i did the port of Kroniax on android. But the LostFocus/GainedFocus worked, but you also have to watch for MouseEnter/Leave, they were strangly mapped (Lockscreen iirc).

I never had the issue with only clearing the GPU objects, in my case the RAM did also get cleaned up (savestate). But maybe things have changed because we now have plenty of RAM (at the time of the port 1-2gb were top-notch :D)


AlexAUT

54
SFML projects / Re: QuadStrike - simple arcade on SFML
« on: February 16, 2017, 12:07:02 am »
Nice idea and a good starting point, keep up the work!

A few notes:
-You should avoid the shift key for things like firing, because fast clicks will trigger a windows popup.
-I cannot get back to the menu when both players are alive?
-You should always include screenshots in your presentation thread, so users somewhat knows what to expect (and for the linux/mac users :D)


AlexAUT

55
Feature requests / Re: Android Studio example project
« on: September 22, 2016, 11:07:28 am »
Yeah it's kinda strange how SFML loads the usercode. I don't think it's necessary, you could simply copy the content of the SFMLActivity.cpp to the MainAndroid.cpp (the onCreate function). Then SFML would not need to load all the dll itself, also the META data (lib_name) could then be removed. But we cannot link the part of SFML with the ANativeActivity functions dynamically because they need to be in the NDKModule loaded by the NativeActivity. And to make it work statically we would need a sfml_dummy function (see at the end of this post)

Is the VisualStudio for Android port really a thing? Last time i tried it, it was horrible (not talking about the tegra plugin)

Just out of interest: How does building normal native activities work? IIRC they also require WHOLE_STATIC_LIB, don't they?

If you talk about the native_app_glue, they link it statically and call the "app_dummy" function to prevent the stripping. See here


AlexAUT

56
Feature requests / Android Studio example project
« on: September 21, 2016, 07:32:17 pm »
Hello,

as the title says, it would be time for an example project for AndroidStudio (using Gradle) for SFML. I managed to port the android-sfml example to Android Studio 2.2 with Gradle Experimental 0.8.0/2.14.2. It would be nice if you could test it, and give some feedback.

https://github.com/AlexAUT/SFML-AndroidStudio-Template there is a HowTo at the Github Site.

There are currently two problems which requires a fix by Google:
  • Because sfml-activity loads the user's code it's required that the whole sfml-main is available in the shared library file. With normal linkage basically everything from sfml-main gets thrown away by the linker, because no user code does reference any sfml-main's code. In ANT we have WHOLE_STATIC_LIB for this case, in Gradle there is no way to do this yet (see github). So I had to copy some implementation specific files to the userproject (SFMLHack folder). As soon as google supports the -Wl,--whole-archive linker option in the Gradle plugin I could remove these files.
  • Also there is currently no way to link the -d libraries when using a debug build, so the template will always link the release lib files.

If you have any questions about the build system, feel free to ask  :D

AlexAUT

57
General / Re: Understanding memory usage of my application
« on: November 14, 2015, 01:11:58 pm »
When you have an AMD card i can recommend CodeXL, when you have an NVIDIA card I can recommend NVIDIA Nsight.

Both tools allow you to pause the program and have a look at every texture/buffer/shader/etc. on the GPU, and the memory usage.


AlexAUT

58
Window / Re: pEvent->mouseWheelScroll.delta .. not put back worth
« on: November 14, 2015, 01:07:16 pm »
You should have a look again at the EventHandling tutorial. You did the most common misstake, you should only use the event in the event loop and not outside, so put the "if(event.type == sf::Event::MouseWheel...)" into the pollEvent loop and you code will work like expected.


AlexAUT

59
General / Re: When a support for a core context ?
« on: October 28, 2015, 07:54:40 am »
No SFML won't create a core context by default, as Laurent posted, please read the answers...
Quote
By default, SFML creates 3.2+ contexts using the compatibility profile


Just have a look at sf::ContextSettings and you will get all your answers. There you can set the major and minor version of the context, and with the attribute member you can set the Debug, Core or the Compability flag...

Quote
Excepting in debug mode ...
?

Quote
but when I create an opengl 3.3+ context with SFML the .exe crash.
A really useful statement, have you tried to debug it? I guess you want to create a 3.3+ compability context but your driver doesn't support it?



AlexAUT

60
SFML projects / Re: In Soviet Russia
« on: October 25, 2015, 08:45:04 pm »
Got too excited after seeing the screenshots, didn't even notice the paragraph at the bottom  ;D


AlexAUT

Pages: 1 2 3 [4] 5 6 ... 27