GLBasic forum

Codesnippets => 2D-snippets => Topic started by: Albert on 2008-Mar-22

Title: Mirroring a Sprite
Post by: Albert on 2008-Mar-22
Hi!
I have a number of sprites, loaded by LOADANIM
how can I draw a mirrored sprite?
I tried STRETCHANIM with -1, 1 but it seems that stretch values less than 0 -> no sprite visible :(

Please, I need very fast ansver! Or I have to draw all the mirrored sprites :)
Title: Mirroring a Sprite
Post by: Kitty Hello on 2008-Mar-22
try scale = -1 in Rotozoomanim.
No, Flips upside down. It's not possible. Try creating the image again with tiles flipped.
Title: Mirroring a Sprite
Post by: Albert on 2008-Mar-23
Bad news.
Ok. meanwhile i created the mirrored tiles.
Title: Re: Mirroring a Sprite
Post by: MEGAMANFAN on 2009-Oct-03
try to
mirror
image it on paint or gimp or photoshop,etc.etc.etc!
Title: Re: Mirroring a Sprite
Post by: Hemlos on 2009-Oct-03
Polyvectors are great for manipulating texture coordinates.

To understand these functions, just use them exactly as if they were "DRAWSPRITE" commands.
These 3 function will mirror, vertical, horizontal, and both.

Code (How to use Mirror functions) Select

ID=0
LOADSPRITE "image.png",ID
SpriteMirrorH(ID,x,y)



Code (Mirror Horizontal:) Select

FUNCTION SpriteMirrorH: num, x, y
LOCAL sW,sH,color=RGB(255,255,255)
GETSPRITESIZE num, sW,sH
STARTPOLY num , FALSE
POLYVECTOR x,y,sW,0, color
POLYVECTOR x,y+sH,sW,sH, color
POLYVECTOR x+sW,y+sH,0,sH, color
POLYVECTOR x+sW,y,0,0, color
ENDPOLY
ENDFUNCTION



Code (Mirror Vertical:) Select

FUNCTION SpriteMirrorV: num, x, y
LOCAL sW,sH,color=RGB(255,255,255)
GETSPRITESIZE num, sW,sH
STARTPOLY num , FALSE
POLYVECTOR x,y,0,sH, color
POLYVECTOR x,y+sH,0,0, color
POLYVECTOR x+sW,y+sH,sW,0, color
POLYVECTOR x+sW,y,sW,sH, color
ENDPOLY
ENDFUNCTION



Code (Mirror Vertical AND Horizontal:) Select

FUNCTION SpriteMirrorVH: num, x, y
LOCAL sW,sH,color=RGB(255,255,255)
GETSPRITESIZE num, sW,sH
STARTPOLY num , FALSE
POLYVECTOR x,y,sW,sH, color
POLYVECTOR x,y+sH,sW,0, color
POLYVECTOR x+sW,y+sH,0,0, color
POLYVECTOR x+sW,y,0,sH, color
ENDPOLY
ENDFUNCTION

Title: Re: Mirroring a Sprite
Post by: Albert on 2010-Dec-20
Hi again!

The question is similar: There is any built-in function to draw an anim mirrored (2 years passed, maybe a new function arised :) )? Or Hemlos's code is the preferred one?
Title: Re: Mirroring a Sprite
Post by: Kitty Hello on 2010-Dec-20
rotozoomanim with negative scaling?
Title: Re: Mirroring a Sprite
Post by: Albert on 2010-Dec-20
:) Same what you suggested two years ago. Ok trying now...
Nope. It's only a 180 degree rotation (because this mirrors not about a vertical line but the centerpoint of the image)  :whistle:

EDIT:
Stretchanim with negative value seems to work.
Code (glbasic) Select

DRAWANIM Bitmap%, anim%, x%, y% //draws normal anim frame
STRETCHANIM Bitmap%, anim%, x%+width%, y%, -width%, height% //draws mirrored anim frame
Title: Re: Mirroring a Sprite
Post by: I love my Brick on 2012-Apr-12
Im currently coding a sprite designer for GLBasic with all the trimmings and found a solution to the above question.

Zoomsprite num,x,y,-1,1 // will flip the sprite horizontally.
Title: Re: Mirroring a Sprite
Post by: Albert on 2012-Apr-12
Nice!
I'm using StretchSprite and StretchAnim
Title: Re: Mirroring a Sprite
Post by: I love my Brick on 2012-Apr-13
Ive started a routine to help (with anims) within the sprite designer.  Save options: save single, save anim, save reverse anim. I`m also implementing a start and finish marker so you can fine tune a anim list and also animate it.

If anyone has any ideas of what they need when designing sprites let me know. But only if Albert is fine with me asking this here.

For now I have coded the following: plot, line, circle/eiipse, box, fill, stencil (various wacky vector shapes that can be shrunk/enlarged upon the grid) flip, rotate, cut n paste, undo, clear, wrap scroll, copy/paste sprite, modify colours, animate(in progress), test screen(paste sprites on screen to see how they look - also in progress), 32x32,64x64 & 128x128 size options

It looks like DPaint in appearence and all drawing options are zoomed to fill the grid.  Draw a line and you see an enlarged pixel line move around the grid etc.
Title: Re: Mirroring a Sprite
Post by: fuzzy70 on 2012-Apr-13
Sounds good & am looking forward to seeing it  =D.

By "modify colours" to you mean a palette type system or basic image processing features like brighten/darken, invert, outline etc. If it is not the latter then that would be a nice feature & save at trip to GIMP/Photoshop for little tweaks. Also the ability to use a sprite as a brush or fill pattern would be great but am getting carried away now  :D

Lee
Title: Re: Mirroring a Sprite
Post by: erico on 2012-Apr-13
Light table to hand draw animation and possibly some sort of stencil to make it easier to colorize them.
It does look like a great Idea you should open a thread about it.

About stretchanim and zoomsprite to achieve flipped sprites:
I understand drawsprite is quite fast and that zoomsprite and rotosprite maybe a little slower on systems like caanoo.
I wonder if using stretch or zoom to a perfect negative number would yield same speed as drawsprite.

I might be able to check this on caanoo. I don´t think there would be a problem on higher systems though.
Title: Re: Mirroring a Sprite
Post by: I love my Brick on 2012-Apr-13
Quote from: fuzzy70 on 2012-Apr-13
Sounds good & am looking forward to seeing it  =D.

By "modify colours" to you mean a palette type system or basic image processing features like brighten/darken, invert, outline etc. If it is not the latter then that would be a nice feature & save at trip to GIMP/Photoshop for little tweaks. Also the ability to use a sprite as a brush or fill pattern would be great but am getting carried away now  :D

Lee
[/quote

The palette is currently 48 colours strong in 3 strips ( I dont agree with having 100s of colours on screen. A fixed number allows you plan the palette - just like in the old days :) ) that have a r,g,b ref next to them.  The ref marker is surrounded by < & > buttons to reduce, increase the colours values.

The cut/paste option uses a sprite and allows it to become the brush. In this mode such options as flip, rotate, scroll etc now effect the brush and not the grid.

Your ideas to improve the fill command have been noted :) perhaps in a future version. A patterned fill could be made by using data and array commands with preset designs(a method I used early on to generate a stipple fill). A brush fill is a simple case of storing it as an data statement. I will be tinkering with this :)

I think for now a bitmap save displaying all sprites is the cheapest option with regards to GIMP etc.

Thanks for the ideas. :good:
Title: Re: Mirroring a Sprite
Post by: I love my Brick on 2012-Apr-13
Quote from: erico on 2012-Apr-13
Light table to hand draw animation and possibly some sort of stencil to make it easier to colorize them.
It does look like a great Idea you should open a thread about it.

About stretchanim and zoomsprite to achieve flipped sprites:
I understand drawsprite is quite fast and that zoomsprite and rotosprite maybe a little slower on systems like caanoo.
I wonder if using stretch or zoom to a perfect negative number would yield same speed as drawsprite.

I might be able to check this on caanoo. I don´t think there would be a problem on higher systems though.
The animation code currently displays each frame at natural size and large grid size. So you can click through them step by step if needed and make the odd change to the sprite. 

I wont hog this thread anymore (sorry) and will soon start my own. I`ll attach a demo of the code when I reach 90% complete - currently 70%.  When I started this project, I made a pen and paper list of things to do. When I tick one off I keep returning to that portion of code with new ideas.  Ive now decided to abort such habits, get through the list and complete the project.

See you all soon :)
Title: Re: Mirroring a Sprite
Post by: fuzzy70 on 2012-Apr-13
I am definitely looking forward to this :-). A wrapping scroll function is something I miss and saves a lot of messing about sometimes. Would be great to have it integrated into the IDE as well :P

Lee

Sent from my GT-I5700 using Tapatalk 2