Page 1 of 1

Flexibility in project

Posted: Sun Feb 06, 2011 8:17 am
by Echo51
Imagine Conway's game of life. mhhhm, good, now imagine that whenever something hits the border, everything on screen would be rescale by 0.5(as in zoom out), and it would continue running. But how would you do this?

You could ofcourse have an array, but then how would you go about implenting not only the switch to a different array, but also the dynamic recreation of one, since i imagine creating a 250x250 2d array on the run is kinda heavy.

Or you could do it arrayless, and just depend on reading the color of previous objects/pixels, but is this possible?


So all in all: what's the best way to manipulate a grid of above 100x100 tiles, if you wanna update it regularly, like, alot...

Re: Flexibility in project

Posted: Sun Feb 06, 2011 8:40 am
by BlackBulletIV
If I catch what you want to do correctly, you'll want to implement a camera. You can do this using love.graphics.translate, love.graphics.rotate, and for what you want to do, love.graphics.scale. But you'll also need to manage a transformation stack using love.graphics.push and love.graphics.pop. The basic formula is this:

Code: Select all

love.graphics.push() -- push the current transformation
love.graphics.rotate(-math.rad(degrees))
love.graphics.scale(1.0 / scaleX, 1.0 / scaleY)
love.graphics.translate(-posX, -posY)
-- do all drawing here
love.graphics.pop() -- return screen to normal state of transformation
Fortunately this has already been done. For example kikito has implemented a camera in his framework called PÄSSION, and I've also made one (based off his) in my framework Grace; although to use these you'll have to use the whole framework. vrld has implemented a (I believe) framework independent camera in his library HUMP.

Hope that helps.

Re: Flexibility in project

Posted: Sun Feb 06, 2011 9:37 am
by Echo51
Thanks for the quick response :) those functions are just what i need, but clearly require some testing to get to know how to make them function correctly.

Eitherway, i'll get back to making the scaling work correctly once i get a bit more done on the actual content. :)

Re: Flexibility in project

Posted: Sun Feb 06, 2011 9:45 am
by BlackBulletIV
No worries ;). The wiki is your friend, it's got a lot of information in it.

By the way those functions perform very well (even when calling the whole sequence every frame - which is what you'll have to do).

Re: Flexibility in project

Posted: Sun Feb 06, 2011 10:03 am
by Echo51
I hope so ;) Came to Love2D for the sole reason that Flash+AS3 got too inefficient and limited. Before even stepping it up to 1080p HD resolution! :D

Eitherway, i tested yestaday and just the love.exe demo screen seemed to utilize the GPU for drawing, so it can't be worse ;)

Re: Flexibility in project

Posted: Sun Feb 06, 2011 10:35 am
by BlackBulletIV
Really? My first programming environment was Flash with AS3. Yeah, Flash sure does have it's limitations.

As far as I know, Love uses OpenGL for hardware acceleration, I'm sure that would give it a boost.

Re: Flexibility in project

Posted: Sun Feb 06, 2011 11:50 am
by Taehl
Echo51 wrote:You could ofcourse have an array, but then how would you go about implenting not only the switch to a different array, but also the dynamic recreation of one, since i imagine creating a 250x250 2d array on the run is kinda heavy
Lua can make a 250x250 array in a hundredth of a second - it may be a scripting language, but it's /fast/.

But why make a new array each time? Why not just add new rows and columns to the existing array as you need them?

Re: Flexibility in project

Posted: Sun Feb 06, 2011 11:19 pm
by Jasoco
Creation of a 250x250 array is very fast and running through it every frame is pretty fast too. Thing is it's better to update large arrays a chunk at a time. Like in SimCity, in order to update the entire city, it would update it a chunk at a time from the top left to bottom right. Depends on what you want to do.

Re: Flexibility in project

Posted: Mon Feb 07, 2011 4:43 pm
by Anisij1981
Какой симпатичный ответ

Re: Flexibility in project

Posted: Mon Feb 07, 2011 6:28 pm
by Jasoco
Anisij1981 wrote:Какой симпатичный ответ
Yes. It is a nice answer.. I guess?