Git Product home page Git Product logo

examples's Introduction

Examples

Every now and then I sit down and try out some features of some library, C++ itself or with SFML. Instead of letting those code fragments go to waste somewhere on my disk or get lost in the depth of the SFML forum, I decided to put them openly and centralized here on GitHub for everyone to see, share and learn from them.

Keep in mind that the code is provided as-is and isn't necessarily suited for your final product, as not a lot of thought was put into performance or code design.

zlib

zlib is a small and useful library which allows the compression and decompression of data. By applying some settings it's possible to let zlib decompress a gzip file, which this examples demonstrates by loading a file into memory and output the decompressed data to standard output.

SFML

One of the most common questions you'll run into on the SFML forum is how to center a sf::Text object inside a shape, or more commonly, a button. Because sf::Text aligns itself to the baseline instead of the visual top/bottom, it tends to be more confusing that working with shapes and sprites. In order to get it working properly, you have to take into account the LocalBounds as is shown in the given example.

Center Text

This was originally created as a test for this thread (or was it this one?), but since I kind of liked the result I adjusted a few things and uploaded it.

Fading Dots

Out of nowhere came suddenly all those requests (starting with this one) for subjective blending and I think, I could help a few people with my example on how to achieve what they wanted.

Flashlight 1 Flashlight 2

Although I can't find the original SFML thread about this, I found the StackOverflow question which was IIRC created before the forum thread. This effect can definitely give a nice ambiance, but it probably could need some retouching. Since the picture do not tell much: Starting off with one color the example automatically iterates through the whole RGB color spectrum in a smooth way.

Hue Shift

I had once read a tutorial in connection with SFML on how to create some nice 'laser' effect. Unfortunately I don't remember which blog/site this was on, because he was using some texture moving which made everything look even better. While doing a search to possible find that tutorial again, I found another similar piece of code on the forum, adapted it for SFML 2 and made a nicer class out of it.

Lightning

The other day in #learnprogramming on freenode someone was trying to implement a way to mix two audio files without actually playing them back. I wondered how something like that would work with SFML and thus went ahead an wrote a small example. A quick Google search on audio sample mixing brought me to this site and lead me to the current implementation.

I'm not sure if there ever existed a forum post or if the whole conversation happened on IRC, but someone wanted to make a 'scrolling' road and since I really liked that idea, I went ahead and implemented an example. The code here is particularly not that nice, so keep that in mind when adapting it.

Road

One of the age old questions by game development beginners is along the lines of "How do I rotate my player to face X?". This short example answers that question, by rotating a triangle (sf::CircleShape with three points) to wherever the mouse pointer is on the window.

Rotating Triangle

This example answers the same question as the 'Rotating Triangle' one, but it uses a sf::VertexArray in combination with a sf::Transformable. It's a good foundation to see how one could start to implement an entity class deriving from sf::Transformable and sf::Drawable.

Rotating Vertices

Every month there's at least one question on simple collision detection testing the last 'bigger' one with in this forum thread, which lead to this example. I've even implemented some very simple physics, which will fail in most situations, but you can at least move around and jump.

AABB

Even though SFML has a tutorial and an example on sound recording, I wanted to have my own small demonstration of said feature with recording device selection and mono/stereo options.

License

All examples are under the zlib/png license and thus free to use. See the LICENSE file for more details.

examples's People

Contributors

expl0it3r avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.