@@ -8,8 +8,9 @@ package leafy.objects;
88import Std ;
99
1010import sdl2 .SDL_Render .SDL_Texture ;
11- import sdl2 .SDL_Pixels .SDL_Color ;
1211import sdl2 .SDL_Render ;
12+ import sdl2 .SDL_Render .SDL_RendererFlip ;
13+ import sdl2 .SDL_Pixels .SDL_Color ;
1314import sdl2 .SDL_Rect ;
1415import sdl2 .SDL_Surface .SDL_Surface ;
1516import sdl2 .SDL_Image ;
@@ -18,7 +19,6 @@ import leafy.backend.sdl.LfWindow;
1819import leafy .utils .LfUtils .LfVector2D ;
1920import leafy .utils .LfUtils ;
2021
21-
2222/**
2323 * Type of the object
2424 */
@@ -37,12 +37,24 @@ enum CenterMode {
3737 CENTER_XY ;
3838}
3939
40+ /**
41+ * Scale mode of the object
42+ */
4043enum ScaleMode {
4144 NEAREST ;
4245 LINEAR ;
4346 BEST ;
4447}
4548
49+ /**
50+ * Flip mode of the object
51+ */
52+ enum FlipMode {
53+ NONE ;
54+ HORIZONTAL ;
55+ VERTICAL ;
56+ }
57+
4658/**
4759 * Base class for all objects
4860 *
@@ -183,6 +195,11 @@ class LfObject extends LfBase {
183195 */
184196 public var scaleMode : ScaleMode = null ;
185197
198+ /**
199+ * Flip mode of the object
200+ */
201+ public var flipMode : FlipMode = FlipMode .NONE ;
202+
186203 // //////////////////////////////
187204
188205 override public function update (elapsed : Float ): Void {
@@ -241,7 +258,7 @@ class LfObject extends LfBase {
241258 // }
242259
243260 SDL_Render . SDL_SetTextureAlphaMod (this .sdlTexturePtr , Std .int (this .alpha * 255 ));
244- SDL_Render . SDL_RenderCopyEx (LfWindow .currentRenderer , this .sdlTexturePtr , null , this .sdlRect , this .angle , null , SDL_FLIP_NONE );
261+ SDL_Render . SDL_RenderCopyEx (LfWindow .currentRenderer , this .sdlTexturePtr , null , this .sdlRect , this .angle , null , convertFlipModeToSDL ( this . flipMode ) );
245262 }
246263
247264 /**
@@ -373,6 +390,18 @@ class LfObject extends LfBase {
373390 this .scaleMode = scaleMode ;
374391 }
375392
393+ /**
394+ * Set the flip mode of the object texture
395+ * @param flipMode
396+ */
397+ public function setFlipMode (flipMode : FlipMode ): Void {
398+ if (this .sdlTexturePtr == null ) {
399+ LeafyDebug .log (" Failed to set flip mode for object: [" + this .name + " ] - Texture is null (" + SDL_Image . IMG_GetError ().toString () + " )" , ERROR );
400+ return ;
401+ }
402+ this .flipMode = flipMode ;
403+ }
404+
376405 /**
377406 * Convert a Leafy object scale mode to an SDL scale mode
378407 * @param scaleMode
@@ -391,6 +420,24 @@ class LfObject extends LfBase {
391420 }
392421 }
393422
423+ /**
424+ * Convert a Leafy object flip mode to an SDL flip mode
425+ * @param flipMode
426+ * @return SDL_Render.SDL_RendererFlip
427+ */
428+ private function convertFlipModeToSDL (flipMode : FlipMode ): SDL_RendererFlip {
429+ switch (flipMode ) {
430+ case FlipMode .NONE :
431+ return SDL_RendererFlip .SDL_FLIP_NONE ;
432+ case FlipMode .HORIZONTAL :
433+ return SDL_RendererFlip .SDL_FLIP_HORIZONTAL ;
434+ case FlipMode .VERTICAL :
435+ return SDL_RendererFlip .SDL_FLIP_VERTICAL ;
436+ default :
437+ return SDL_RendererFlip .SDL_FLIP_NONE ;
438+ }
439+ }
440+
394441 /**
395442 * Update the SDL rect of the object
396443 */
0 commit comments