Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Strange pixelart compression  (Read 1115 times)

0 Members and 1 Guest are viewing this topic.

grzesiek11

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Strange pixelart compression
« on: July 17, 2018, 05:00:22 pm »
Hi. I made a project that show a template checkers board-like world. But I excepted something other than this:

Cause I've got THAT in resources:

Maybe it happened because of scaling? Code here:
https://pastebin.com/dhPqLLd2

Sorry for my grammar, I'm from Poland.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10821
    • View Profile
    • development blog
    • Email
Re: Strange pixelart compression
« Reply #1 on: July 17, 2018, 09:36:14 pm »
Well you're not properly understanding what your if condition does. x % 2 == 0 checks for dividable by two, so it skips every other place creating your checkerboard look.

What was your intention?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Strange pixelart compression
« Reply #2 on: July 18, 2018, 02:08:35 am »
You really shouldn't be loading textures every frame of your main loop, especially once per tile for so many tiles!

When you set the first texture for the rectangle shape, it determines the size of the texture rectangle based on the size of the texture. Unfortunately, you have no loaded texture at the time of assigned the texture to the rectangle shape so the rectangle shape's size is zero. This texture rectangle is never updated...
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

grzesiek11

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Strange pixelart compression
« Reply #3 on: July 18, 2018, 10:57:40 am »
Quote
[...]What was your intention?
Warning! Bad graphics editing here!


Quote
You really shouldn't be loading textures every frame of your main loop, especially once per tile for so many tiles!
I figured that out, but I don't know how to change this. And, it isn't my biggest problem for now.

Quote
When you set the first texture for the rectangle shape, it determines the size of the texture rectangle based on the size of the texture. Unfortunately, you have no loaded texture at the time of assigned the texture to the rectangle shape so the rectangle shape's size is zero. This texture rectangle is never updated...
Thanks. I will try it.

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Strange pixelart compression
« Reply #4 on: July 18, 2018, 03:44:19 pm »
It will be your next problem though as loading from a file can significantly slow down your frame.

Load both textures before the loop and then set the sprite to the texture you want to use before drawing it. This is the option closest to your current design and allows the two image files to be left as they are.

A better option, though, is to place both the textures into one image file and load it as one texture (before the main loop). Then, for each tile, just set the texture rectangle to cover the part you want to use. This can also significantly increase performance even over the previous version.

Better still, use a tile map object, which will be a single vertex array that draws all tiles in one go. This will also require the tiles to be in one image.
A simple example of this is available in SFML's vertex array tutorial:
https://www.sfml-dev.org/tutorials/2.5/graphics-vertex-array.php#example-tile-map

If you need more flexibility, you may want to create your own vertex array or use something like Selba Ward's Tile Map, which does it all for you ;)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*