Hi,
the Ball doesn't bounce. I think it is because the GetRect function returns bullshit numbers. I added the program.
misterchi
Fart-Annoyed: Dowallcollision doesn't work properly
Fart-Annoyed: Dowallcollision doesn't work properly
- Attachments
-
- FartAnnoyed.zip
- (756.3 KiB) Downloaded 177 times
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Fart-Annoyed: Dowallcollision doesn't work properly
Take a look at these constructors, the second and third are incorrect.
Code: Select all
RectF::RectF(float left, float right, float top, float bottom)
:
left(left),
right(right),
top(top),
bottom(bottom)
{
}
RectF::RectF(Vec2 & topleft, Vec2 & bottomright) {
RectF(topleft.x, bottomright.x, topleft.y, bottomright.y);
}
RectF::RectF(Vec2 & topleft, float height, float width) {
RectF(topleft, topleft + Vec2(width, height));
}
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Fart-Annoyed: Dowallcollision doesn't work properly
Spoiler:
I find this to be more easily readable
Spoiler:
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: Fart-Annoyed: Dowallcollision doesn't work properly
Hi albinopapa,
now I changed the constructors and it works fine. Thanks! But I don't understand why the constructors without ":" don't work. Thanks for your feedback about my codingstyle, too. It helps a lot.
misterchi
now I changed the constructors and it works fine. Thanks! But I don't understand why the constructors without ":" don't work. Thanks for your feedback about my codingstyle, too. It helps a lot.
misterchi
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Fart-Annoyed: Dowallcollision doesn't work properly
There are two parts to a constructor, the initializer list and the function body. The initializer list portion is everything between the : and the {} and is responsible for initializing class/struct members. The function body portion is treated like any other function and is used for initializing members that are more complicated to initialize like arrays for instance.
Putting RectF(5, 5, 10, 10) inside the function body would be similar to writing:
int{5};
instead of
int a = int{5}
You are making a temp RectF, but because of scoping rules, it is destroyed at the closing brace '}' because you never assigned it to anything, like. Initialization through calling a constructor in the initializer list is built in to the standard, so it's understood that when calling a constructor in the initializer list you are telling the compiler to use a different constructor to initialize this object.
Hopefully, that explanation was helpful.
Putting RectF(5, 5, 10, 10) inside the function body would be similar to writing:
int{5};
instead of
int a = int{5}
You are making a temp RectF, but because of scoping rules, it is destroyed at the closing brace '}' because you never assigned it to anything, like
Code: Select all
*this = RectF(5, 5, 10, 10);
Hopefully, that explanation was helpful.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com