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

Pages: [1] 2 3 ... 16
1
General / Re: How can I make a background repeat infinitely?
« on: January 18, 2023, 11:16:13 pm »
One idea is, instead of having one background rectangle, you have multiple side-by-side rectangles that extend beyond the bounds of the window/view. Each of these rectangles has your background texture. This assumes your background texture is seamless so that you don't notice the multiple rectangles, but it sounds like you already have that covered.

Then as your character and view move to the right, for example, you can check if the bounds of the view are close to the edge of the furthest right background rectangle. When this happens, you can create another new rectangle even further to the right. You can also delete the furthest left rectangle once it is no longer within the view. When your character moves left you can create a new rectangle to the left as needed, and delete the furthest right rectangle. This gives the illusion of an infinite background when really you're just creating and deleting background rectangles as needed.

2
SFML projects / Re: American Football
« on: August 08, 2022, 03:41:07 am »
I've continued to add more features and polish to my American Football game over time since my last post here. Too many changes to list them all here, but most notably I decided to create a demo if anyone wants to give the game a try for free :)! The demo is fully featured other than limiting the "career" mode to 2 in-game weeks. It can be found on the game's itch.io page.

3
Graphics / Re: Erase only one rectangleShape
« on: July 22, 2022, 08:19:24 pm »
for (auto& door: doors)
{
   FloatRect playerBounds = player.getGlobalBounds();
   FloatRect doorBounds = door.getGlobalBounds();
 
   for ( auto it = doors.begin(); it != doors.end();)
   {            
      if(doorBounds.intersects(playerBounds)) {
 

You are looping through every door (outer for loop), and for each of those doors you are looping through every door again (inner for loop). If the current door from the outer loop intersects the players bounds then you are deleting every door in the inner loop. You likely don't need these nested for loops.

One thing that might be helpful is to look up how to use a debugger. A debugger would allow you to step through one line of code at a time while your program is running to get a better understanding of what's happening. You can usually spot this type of problem pretty quickly with a debugger.

4
Graphics / Re: check which glyph is at a position
« on: July 07, 2022, 10:01:03 pm »
sf::Text provides a few member functions, like getGlobalBounds() and findCharacterPos(), that you can use in combination with some math to get pretty close to what you describe.

5
How are you determining your inputs are being repeated? Did you put a print statement in your InputHandler class? Or is there something in CheckBtn() or animPlayer() happening more than once?

Also, is there a reason that this line
input.InputHandler(event, window);
isn't inside of the while loop above it? Looks like it probably should be.

6
Graphics / Re: VertexArray accepts coordinates one beyond?
« on: June 07, 2022, 09:57:40 pm »
The 'top' variable is indeed empty space above your letters and the value is dependent on which letters/characters you are using in your Text object. The value of top will be small if you have tall characters in your text, and vice versa.

Going off of memory here, but I believe a Text object's height represents the height of the characters that are currently being used, not the height of the tallest possible character within your font (hopefully someone corrects me if I have this backwards). So, height + top would give you the height of the tallest possible character.

It's useful to know the size of the tallest possible character so that you can prevent your characters, which are aligned at their baseline, from visibly bouncing up and down as new characters with different heights are added or removed from your text. Or at least you can choose how you want to use the combination of 'height' and 'top' to do your positioning when dealing with characters of different heights.

7
Graphics / Re: Trouble moving two sprites in the same window
« on: May 11, 2022, 10:28:02 pm »
I would avoid trying to use threads for this. Most games you create, especially simpler ones like Space Invaders, don't need multiple threads for things to visually appear to be happening at the same time. In fact you should almost never need to use multiple threads at all. If anything, having multiple threads will greatly complicate your code and they are prone to causing issues that are really hard to debug.

At a high level, most games work by having an infinite loop, where each time through you clear the screen, draw everything, and then display it to the player. (See the tutorials if you aren't familiar with the basics). Remember that the player won't see objects move at the very moment the code tells the object to move. The player only sees things move once the window has been displayed. So for 2 objects to move "at the same time", all you need to do is move both of them between your calls to the display function.

8
General / Re: event.text.unicode returning wrong code
« on: March 22, 2022, 09:48:42 pm »
The event type you want is sf::Event::TextEntered not sf::Event::KeyPressed

9
Are you trying to load all of these textures into memory at the same time? If so, why not only load the textures that are actively being used? Then once you are done with those, you can free that memory before loading in the next set.

As Kojack mentioned, png image files use compression. They might only be 30 - 200 KB on disk, but they will be much larger when loaded in memory and uncompressed behind the scenes.

10
General / Re: Little problem
« on: July 20, 2021, 11:43:00 pm »
I didn't read through your code very carefully, but the problem is probably here
ball.move(x_position(t,vx), y_position(t,vy));
t += 0.000007;
 
The move function adjusts the sprites position relative to its previous position. So if your ball sprite is at the position (500, 300) and you call ball.move(1,1) then your sprite will now be at position (501, 301).

Though, think about what x_position() and y_position() will return each time through the game loop. Each time through the loop you keep incrementing the variable t such that it keeps getting bigger and bigger. Thus the numbers returned by those functions will keep getting bigger and bigger, and so you will be moving the ball by bigger and bigger amounts. That's acceleration.

You might want to take a step back and ask yourself what the variable t is supposed to be for. This article on timesteps might be helpful for you.

11
Graphics / Re: Load Texture from another file doesnt work ?
« on: February 05, 2021, 08:41:55 pm »
This is what is commonly referred to as the white square problem. The Sprites and Textures tutorial on the SFML website has a section about it: https://www.sfml-dev.org/tutorials/2.5/graphics-sprite.php#the-white-square-problem.

In short, the problem is that you're creating a local texture variable.  The sprite doesn't copy the texture data into itself. It simply holds a pointer to the texture. Therefore the texture needs to exist for as long as the sprite is using it. In your case, once the createChar() function ends the texture will go out of scope and be destroyed, leaving your sprite pointing at invalid memory.

12
Graphics / Re: Window acting extremely glitchy on Ubuntu
« on: February 05, 2021, 03:43:42 pm »
Check out the first drawing tutorial at https://www.sfml-dev.org/tutorials/2.5/graphics-draw.php , specifically scroll down to the first box with red text. See if your problem goes away if you move your clear window and draw text code to be inside of the main while loop.

13
If you search around the forums you'll find that this question comes up fairly regularly (Like this one and this one).

In short, text is aligned at the baseline, not the top. Different letters have different sizes, thus the offsets can change depending on which letters you are using. The space at the top matches the height of the tallest character of the font

14
SFML projects / Re: American Football
« on: November 09, 2020, 04:36:03 am »
Hello everyone

Poking in for another update after a long delay. The game is still a little rough around the edges, but otherwise it's starting to feel more and more like a real game! In fact, it's at a point to where I want to open it up for others to play.  I recently put up an "early access" build on itch.io if anyone is interested in checking it out. Though, I did put a price on it. I'm testing the waters on itch.io to see if this is something anyone would be willing to pay for  ;D.  Hopefully the price isn't too steep. Sorry in advance if this type of self-promotion isn't appropriate here.


Since my last post I've implemented a lot of miscellaneous things. A few of the highlights include:
  • Major improvements to player recruiting. A large part of American Football at the college/university level involves the coaches recruiting players to come to their respective school and play for their team. I've implemented a bit of a mini-game where you can research these prospective recruits and save the ones you want to go after. You can then try to convince them to come to you school by calling them and picking a topic to talk about. If you picked a topic that is important to that recruit then you may receive bonus points towards their interest in your school. If you have the most points for a given recruit at the end of the season then they may choose to join your team next season.

    (click to show/hide)

    In the above screenshot you can also see that the window shows a picture of the recruit. As part of this update I implemented a way to procedurally generate pictures for all recruits (and all other players too for that matter). I'm pretty happy with the way the pictures have turned out. I plan to implement more variety in the faces over time.

  • I always envisioned this game to be a management sim where you call plays as the coach and watch the players act them out. However, I've been experimenting with direct player control like a more traditional football game. You now have the option of picking what control style you want to use. You can choose to control the players like a traditional football game, choose to only call the plays, or choose to do nothing and only spectate. The gif below shows me directly controlling the players on the left team.

    (click to show/hide)


15
Graphics / Re: Scrolling tilemap issue: black bars
« on: November 04, 2020, 03:39:28 pm »
Quote
Is this possibly some floating point/pixel alingment issue?

It could be. Similar problems comes up fairly often on these forums, so if you search around you might find other threads of people talking about why this happens and some possible solutions. Here's one example.

Pages: [1] 2 3 ... 16
anything