Yeah I've got it bouncing off the top bottom and left walls perfectly but on the right wall it goes in a little too deep and I cant figure out a way to stop it from doing that
Okay, you remember in my movement tutorial parts 1 and 2 where I discuss the bouncing with the sprite? We had to take the sprite width into account when we tested the right side (GraphicsDevice.Viewport.Width - player.Width).
You basically do the same thing, but you use a spriteFont object and call the MeasureString method with a string passed to it. It will give you a Vector2. Then, you need to add it to the position and test to see if its bigger than the viewport.width and viewport.height
Thank you for the tutorials but I'm having a bit of trouble on the spriteFont one I'm trying to make the letters move around like the movement tutorial but on the right side of the screen it goes in a little too deep and I cant figure out why.
nvm I've fixed it ty:)
hauntedsoul21 2 years ago
Ok that works but now the right side is a little too "in" if you know what i mean like
wall ----> | end of the screen---- |
sorry if that doesnt explain alot lol
hauntedsoul21 2 years ago
so
if (position.X >= GraphicsDevice.Viewport.Width - spriteFont.MeasureString) ?
if I do it like that it gives me an error saying
Operator '-' cannot be applied to operands of type 'int' and 'method group'
hauntedsoul21 2 years ago
MeasureString needs a string parameter, and it returns a Vector2. So it needs to be something like this:
spriteFont.MeasureString("This is a string I want to measure").X
Also, I would recommend doing it this way:
if (position.X + spriteFont.MeasureString("This is a string I want to measure").X >= GraphicsDevice.Viewport.Width)
To do the same thing on the Y axis, use spriteFont.MeasureString("This is a string I want to measure").Y instead.
Whiplashx86 2 years ago
yeah it works fine just the right wall lets the text go in to deep
hauntedsoul21 2 years ago
You dont use line spacing, you use the measure string method I mentioned a few comments down.
Whiplashx86 2 years ago
Well here's how I have it now.
if(position.X >= GraphicsDevice.Viewport.Width - spriteFont.LineSpacing)
hauntedsoul21 2 years ago
Does it work?
Whiplashx86 2 years ago
Yeah I've got it bouncing off the top bottom and left walls perfectly but on the right wall it goes in a little too deep and I cant figure out a way to stop it from doing that
hauntedsoul21 2 years ago
Okay, you remember in my movement tutorial parts 1 and 2 where I discuss the bouncing with the sprite? We had to take the sprite width into account when we tested the right side (GraphicsDevice.Viewport.Width - player.Width).
You basically do the same thing, but you use a spriteFont object and call the MeasureString method with a string passed to it. It will give you a Vector2. Then, you need to add it to the position and test to see if its bigger than the viewport.width and viewport.height
Whiplashx86 2 years ago
Thank you for the tutorials but I'm having a bit of trouble on the spriteFont one I'm trying to make the letters move around like the movement tutorial but on the right side of the screen it goes in a little too deep and I cant figure out why.
hauntedsoul21 2 years ago
You want the text to bounce like in the movement tutorial?
Whiplashx86 2 years ago
soda dude he makes great tutorials if youu don't like it then find a different tutorial
xbourne117x 2 years ago
Well I cant change my voice, so I should just stop talking?
Whiplashx86 2 years ago
helpful, but TBH your voice grates on my nerves 4/5 stars
sodafountan 2 years ago