Scaling Sprites

General help with the Ecere Cross Platform GUI toolkit: Window, common controls, events, etc.
Help with the 2D Graphics library: Surface, Display, Bitmap, Font and others.
Post Reply
mothdragon
Posts: 28
Joined: Mon Jan 18, 2010 11:56 pm

Scaling Sprites

Post by mothdragon »

I thought I remembered at one time having come across some kind of scaling function for Bitmap Objects, but I can't seem to find it now... Is there a scaling function (either up or down) that can be used when displaying a Bitmap, or a portion of the Bitmap(ie sprite)?

What I want to do is to take a sprite from my spritesheet and make it smaller at various points.
--==[[ Mothdragon ]]==--
- - - - - - - - - - - - - - - - -
Everything New is Old, Everything Old is New. Nothing exists, and it's all here.
mothdragon
Posts: 28
Joined: Mon Jan 18, 2010 11:56 pm

Re: Scaling Sprites

Post by mothdragon »

Oh I found it. Its the Stretch() method in the Surface Object. Guess I was looking in the wrong spot, I had been looking at the Bitmap Object... :oops:
--==[[ Mothdragon ]]==--
- - - - - - - - - - - - - - - - -
Everything New is Old, Everything Old is New. Nothing exists, and it's all here.
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: Scaling Sprites

Post by jerome »

Good morning Charlie :)

Yes, there is Surface::Stretch. It works just like Surface::Blit, except it takes 2 sets of coordinates.

Code: Select all

void Stretch(Bitmap src, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
Destination x, y
Source x, y
Destination w, h
Source w, h

So you tell the function which portion (a rectangle) of your source bitmap should be used to stretch over a rectangular area of your destination surface.

There is also Filter() which takes the exact same parameters as Stretch, but will do bilinear filtering so the result will generally look nicer (at a performance cost in a non-accelerated driver). Stretch() will pixelize.

Regards,

Jerome
Post Reply