[SDL] Sprite Origin positions

MrTAToad mrtatoad at mrtatoad.plus.com
Mon Sep 22 13:01:01 PDT 2014


My change did work fine with all 9 possible origin positions.

My rendering code is now thus :


Code:
       // Calculate final size
        switch (mode) {
            case    RESIZE      :   // Resize to a given size - calculate the scaling value
									scaleX = scaleX / sourceRect.w;
									scaleY = scaleY / sourceRect.h;
                                    break;

            case    SCALE       :   // Scale to indiviual values
                                    // Do nothing
                                    break;

			default				:   // Standard scaling
									scaleX = 1.0;
									scaleY = 1.0;
									break;
            };

		if (scaleX == 0.0 || scaleY == 0.0) return true;

        switch (GETXHANDLE()) {
			case    TOPLEFT		:   pointX = 0;              break;
			case    MIDDLE		:   pointX = sourceRect.w / 2;   break;
			case    BOTTOMRIGHT	:   pointX = sourceRect.w - 1;   break;
            };

        switch (GETYHANDLE()) {
			case    TOPLEFT		:   pointY = 0;              break;
			case    MIDDLE		:   pointY = sourceRect.h / 2;   break;
			case    BOTTOMRIGHT	:   pointY = sourceRect.h - 1;    break;
            };

		pointX *= scaleX;
		pointY *= scaleY;
		//centre.x = centre.y = 0;

		destRect.x = (int)(x - pointX);
		destRect.y = (int)(y - pointY);
		destRect.w = (int)(sourceRect.w*scaleX);
		destRect.h = (int)(sourceRect.h*scaleY);

		point.x = (int)pointX;
		point.y = (int)pointY;

		SDL_SetTextureAlphaMod(sprite->texture,blendModes[TEXTURE-TEXTURE].amount);
        SDL_SetTextureBlendMode(sprite->texture,blendModes[TEXTURE-TEXTURE].mode);
		SDL_SetTextureColorMod(sprite->texture, blendModes[TEXTURE - TEXTURE].r, 
								blendModes[TEXTURE - TEXTURE].g,
								blendModes[TEXTURE - TEXTURE].b);

        if (SDL_RenderCopyEx(m_mainRenderer,
								sprite->texture,&sourceRect,&destRect,angle,&point,SDL_FLIP_NONE)<0)
        {
			throw(CMP_SDL_ERROR);
        }






-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20140922/5b103a77/attachment-0002.htm>


More information about the SDL mailing list