Author Topic: Mirroring a Sprite  (Read 8473 times)

Offline Albert

  • Dr. Type
  • ****
  • Posts: 257
    • View Profile
    • Blog
Mirroring a Sprite
« 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 :)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10695
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Mirroring a Sprite
« Reply #1 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.

Offline Albert

  • Dr. Type
  • ****
  • Posts: 257
    • View Profile
    • Blog
Mirroring a Sprite
« Reply #2 on: 2008-Mar-23 »
Bad news.
Ok. meanwhile i created the mirrored tiles.

Offline MEGAMANFAN

  • Mc. Print
  • *
  • Posts: 14
  • cik
    • View Profile
Re: Mirroring a Sprite
« Reply #3 on: 2009-Oct-03 »
try tomirrorimage it on paint or gimp or photoshop,etc.etc.etc!
think of a number x 2+22 divide 2-1st number = my grade in math!!!

(11)

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
Re: Mirroring a Sprite
« Reply #4 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: Text [Select]
ID=0
LOADSPRITE "image.png",ID
SpriteMirrorH(ID,x,y)
 


Code: Text [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: Text [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: Text [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
 
« Last Edit: 2009-Oct-04 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Albert

  • Dr. Type
  • ****
  • Posts: 257
    • View Profile
    • Blog
Re: Mirroring a Sprite
« Reply #5 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?

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10695
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Mirroring a Sprite
« Reply #6 on: 2010-Dec-20 »
rotozoomanim with negative scaling?

Offline Albert

  • Dr. Type
  • ****
  • Posts: 257
    • View Profile
    • Blog
Re: Mirroring a Sprite
« Reply #7 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
 
« Last Edit: 2010-Dec-20 by Albert »

Offline I love my Brick

  • Mr. Drawsprite
  • **
  • Posts: 61
    • View Profile
Re: Mirroring a Sprite
« Reply #8 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.
I like things and do stuff.

Offline Albert

  • Dr. Type
  • ****
  • Posts: 257
    • View Profile
    • Blog
Re: Mirroring a Sprite
« Reply #9 on: 2012-Apr-12 »
Nice!
I'm using StretchSprite and StretchAnim

Offline I love my Brick

  • Mr. Drawsprite
  • **
  • Posts: 61
    • View Profile
Re: Mirroring a Sprite
« Reply #10 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.
I like things and do stuff.

Offline fuzzy70

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 828
  • Look left, Look right, LOOK OUT!!
    • View Profile
Re: Mirroring a Sprite
« Reply #11 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
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4181
    • View Profile
    • Portfolio
Re: Mirroring a Sprite
« Reply #12 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.

Offline I love my Brick

  • Mr. Drawsprite
  • **
  • Posts: 61
    • View Profile
Re: Mirroring a Sprite
« Reply #13 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:
I like things and do stuff.

Offline I love my Brick

  • Mr. Drawsprite
  • **
  • Posts: 61
    • View Profile
Re: Mirroring a Sprite
« Reply #14 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 :)
I like things and do stuff.