mPaddleRect;
mPaddleRect.x = 0;
mPaddleRect.y = 0;
mPaddleRect.w = 100;
mPaddleRect.h = 16;
mpPadRect = &mPaddleRect;
}
void CGraphics::Draw(SDL_Surface* screen, SDL_Surface* bitmap, SDL_Rect *pMySourceRect,
int destX, int destY)
{
// Part of the screen we want to draw the sprite to
SDL_Rect dest;
dest.x = destX;
dest.y = destY;
dest.w = pMySourceRect->w;
dest.h = pMySourceRect->h;
SDL_BlitSurface(bitmap, &pMySourceRect, screen, &dest);
}
K i give up SDL question
I'm getting this error when compiling:
.\Graphics.cpp(32) : error C2664: 'SDL_UpperBlit' : cannot convert parameter 2 from 'SDL_Rect **' to 'SDL_Rect *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
It has to do with BlitSurface function(which is a #define for UpperBlit(i guess)).One of the Rect's i plan on using is at the top.
Graphics.cpp
pMySourceRect is already a pointer. You don't need to have an & in front of it when you pass it to SDL_BlitSurface().
Oh man, that just sent my C++ universe off its axis. [totally] Thanks
One other thing if you come back in here: if there is a page for it, do you know of a good reference that you personal use as far as naming conventions?
One other thing if you come back in here: if there is a page for it, do you know of a good reference that you personal use as far as naming conventions?
Quote:Original post by deEnumerator
Oh man, that just sent my C++ universe off its axis. [totally]
I think the problem is not from that but just a misunderstanding of how SDL_BlitSurface works. The function is declared as: int SDL_BlitSurface (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect); You have down the SDL_Surface*'s I'll assume, so for the SDL_Rects, they take in a pointer to some rectagle. The reason a pointer to a SDL_Rect has to be sent in is because if the specified rectangle lies outside of the screen, SDL will update that rect with the portion that was drawn, to which afterwards, you can check to see if the original rect you sent in was the same that was blitted.
So when you have something like this:
SDL_Rect src, dest; You know those are not pointers, so to get them to work with that function, you have to pass the address of those variables into the function, &src, &dest.
If you had something like this:
SDL_Rect *src = new SDL_Rect; SDL_Rect *dest = new SDL_Rect; You know you have pointers, so to get them to work with that function, you just have to pass in src, dest.
I think the problem was that in all of the tutorials/references to SDL out on the net, they always use &var when passing to that function, so you instinctively did the same thing. Well that's if I'm wrong about all of this. Either way, now you know. Here's a reference on pointers in C++ if you need to refresh your memory.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement