Flipped Sprites?
Monkey Forums/Monkey Programming/Flipped Sprites?| 
 | ||
| I recall a while back that DrawImageRect does not support sprite flipping by setting x or y scale to -1. Is this still the case or is there a way to do it now? Is it possible to do with matrix transforms and if so how? | 
| 
 | ||
| Works fine here... And according to the Monkey docs:  The image is drawn using the current color, alpha, blend mode and matrix, and is clipped to the current scissor rectangle.  Import mojo
Class MyApp Extends App
	Field items:Image
	
	Method OnCreate()
		items = LoadImage("items.png", 1, Image.MidHandle)
		SetUpdateRate 60
	End
	
	Method OnUpdate()
	End
	
	Method OnRender()
		Cls 128,0,255
		DrawImage items, 10, 10
		Scale -1,1
		DrawImageRect items, 200, 100, 0, 0, 200, 200
		Scale 1,1
	End
End
Function Main()
	New MyApp
End
 | 
| 
 | ||
| I see, when I tested it I was putting the scale into the drawimagerect call. Thanks! | 
| 
 | ||
| I actually prefer to use GrabImage: Import mojo
Class MyApp Extends App
	Field items:Image
	Field axe:Image
	Method OnCreate()
		items = LoadImage("items.png", 1, Image.MidHandle)
		axe = items.GrabImage(0, 0, 200, 200)
		SetUpdateRate 60
	End
	
	Method OnUpdate()
	End
	
	Method OnRender()
		Cls 128,0,255
		DrawImage axe, 200, 100, 0, -1, 1
	End
End
Function Main()
	New MyApp
End | 
| 
 | ||
| Unfortunately, when I attempt to draw it flipped, no sprite is drawn. Notice that for testing purposes both cases for facing are set to -1 to enforce the flipped draw. Function DrawStripTile:Void(strip:Image, num:Int, x:Int, y:Int, facing:Int) If facing = 1 Scale -1, 1 DrawImageRect(strip, x, y, num*TILESIZE, 0, TILESIZE, TILESIZE, 0, 1, 1) Else Scale -1,1 DrawImageRect(strip, x, y, num*TILESIZE, 0, TILESIZE, TILESIZE, 0, 1, 1) endif End Function | 
| 
 | ||
| What is the functional difference between the grabimage method and the drawimagerect method? At this point it wouldn't cause me much trouble to switch and setting up a table of different named images would make things like animation easier later. | 
| 
 | ||
| I see what I was doing wrong.  The scale in the drawimagerect was overwriting the Scale command. | 
| 
 | ||
|  What is the functional difference between the grabimage method and the drawimagerect method?   Not much from what I can see, apart from that you actually store the image into another variable which does make it a lot easier to use. | 
| 
 | ||
| I mostly use GrabImage when I want to set the handle to Image.MidHandle. If the handle will be at the top left, DrawImageRect is just as easy. | 
| 
 | ||
| i thought first that GrabImage copy imagebuffer, but it create a simple reference to image... Interesting, when i discard image, it happen nothing to this reference... that is fine! | 
| 
 | ||
| So revill's method creates an index into the sprite sheet and doesn't experience slowdown from sprite flipping? |