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

Author Topic: extra images appearing at 0,0 coordinate of window  (Read 2106 times)

0 Members and 1 Guest are viewing this topic.

lorence30

  • Full Member
  • ***
  • Posts: 124
    • View Profile
    • Email
extra images appearing at 0,0 coordinate of window
« on: May 10, 2015, 11:51:57 am »
http://pastebin.com/4QwmkZX6

can someone test my program?
here is the code: http://pastebin.com/4QwmkZX6
and download the images below and put the folder in the working directory.

if you notice,
if you play it slowly the game is fine,
but when you try to play it like spamming the key and mouse left button you will notice theres sometimes extra images appearing at 0,0 coordinate of window

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: extra images appearing at 0,0 coordinate of window
« Reply #1 on: May 10, 2015, 02:09:10 pm »
My poor memory, full of leaks  ;D, when you use "new" you have to use "delete" to free the memory.
The program is doing exactly what you made it to do, so to simply answer your question:
Extra images appear on top of the screen because in code its made that way.

Some issues: Use STL library for memory management if you are new to c++.
on sf::RenderWindow use function w.setFramerateLimit(60); because i had too many frames.
You also never clear screen at beginning of while loop, therefore you have so many images on screen w.clear();
All of this things can be found in the "TUTORIAL" of SFML, if you read through it, you will know all of this, i suggest you do that.

About the random sprites at 0,0 position. I did not examine the code, i just gave it a look. I suspect you do it in this order: Make warrior, draw warrior, set warrior position. (Thus the warrior will be drawn at 0,0 position first time, that is the default value, next frame he will be drawn at pos you wanted to)

TL;DR Read tutorial, everything you asked in few posts can be found there, also use STL library :)
« Last Edit: May 10, 2015, 02:14:56 pm by BaneTrapper »
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: extra images appearing at 0,0 coordinate of window
« Reply #2 on: May 10, 2015, 02:49:14 pm »
Don't use naked new's. Use smart pointers (std::unique_ptr) and make_unique.

lorence30

  • Full Member
  • ***
  • Posts: 124
    • View Profile
    • Email
Re: extra images appearing at 0,0 coordinate of window
« Reply #3 on: May 10, 2015, 03:26:10 pm »
@BaneTrapper
sorry late reply.

Quote
My poor memory, full of leaks  ;D, when you use "new" you have to use "delete" to free the memory.
i forgot XD

Quote
You also never clear screen at beginning of while loop, therefore you have so many images on screen w.clear();
i didnt clear the screen for purpose, because im just testing to see if they are spawning in the right way.
Quote
All of this things can be found in the "TUTORIAL" of SFML, if you read through it, you will know all of this, i suggest you do that.
im using the 2 books, "SFML Game Development" and "SFML Essentials"


Quote
About the random sprites at 0,0 position. I did not examine the code, i just gave it a look. I suspect you do it in this order: Make warrior, draw warrior, set warrior position. (Thus the warrior will be drawn at 0,0 position first time, that is the default value, next frame he will be drawn at pos you wanted to)

Its not, Make warrior -> setwarrior position -> draw warrior, thats how i do it.
when i spawn them slowly i dont get any character appearing at 0,0 position.
can you try play it?



Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: extra images appearing at 0,0 coordinate of window
« Reply #4 on: May 10, 2015, 03:31:51 pm »
Quote
i didnt clear the screen for purpose
As explained in the tutorial, you must clear the screen each frame - read the big red box (nay, read all of the tutorial(s)).

lorence30

  • Full Member
  • ***
  • Posts: 124
    • View Profile
    • Email
Re: extra images appearing at 0,0 coordinate of window
« Reply #5 on: May 10, 2015, 04:03:51 pm »
[qoute]As explained in the tutorial, you must clear the screen each frame - read the big red box (nay, read all of the tutorial(s)).[/qoute]
okay okay thanks