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

Author Topic: Objects using wrong textures  (Read 1434 times)

0 Members and 2 Guests are viewing this topic.

Laggy44

  • Newbie
  • *
  • Posts: 2
    • View Profile
Objects using wrong textures
« on: April 07, 2014, 12:28:03 am »
So I'm learning SFML, and in my game I've created a platform object, with its own sprite and texture. The texture is simply a grey square.
In my main() function, I call window.setMouseVisible(false) and create a new sprite to use as a custom cursor. The cursor texture is a black circle with a dot in it.
Now when I create some platforms in my code, then run the program, all of the platforms use the cursor texture, scaled up to the size of their original texture. It seems for some reason, the platform objects are taking the texture of the cursor. I've tried removing the cursor texture, but then the platforms have no textures, they're just white squares.
Any reason for this? It sounds like the platform textures are going out of scope, but unless I've forgotten all of my programming lessons, I don't think that's the case. And even if they were, why would they be taking the cursor's texture?

math1992

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
    • Email
Re: Objects using wrong textures
« Reply #1 on: April 07, 2014, 01:21:42 am »
It would help if you send a minimal code causing the problem, otherwise we can't help.

Laggy44

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Objects using wrong textures
« Reply #2 on: April 07, 2014, 03:38:57 am »
This is the code for creating the custom mouse (in the main() function):
http://pastebin.com/6bVRMXiQ

This is the Wall class:
http://pastebin.com/NQDVPLHM

And this is in my main function where I create each wall:
http://pastebin.com/LdGrXZ85

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Objects using wrong textures
« Reply #3 on: April 07, 2014, 08:45:39 am »
You need to create a minimal example that reproduces the problem, either by removing every irrelevant part of your code, but lets you still compile it or by using an empty project and adding in the relevant pieces.

Keep in mind that getTexture() of the Wall class currently creates a copy of the texture, which is heavy operation. If you add a Wall constructor that takes the position as parameter, then you could use emplace_back(x, y) on the vector to create a new wall object.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/