Flexibility in project

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Echo51
Prole
Posts: 4
Joined: Sun Feb 06, 2011 7:45 am

Flexibility in project

Post 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...
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Flexibility in project

Post 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.
Echo51
Prole
Posts: 4
Joined: Sun Feb 06, 2011 7:45 am

Re: Flexibility in project

Post 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. :)
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Flexibility in project

Post 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).
Echo51
Prole
Posts: 4
Joined: Sun Feb 06, 2011 7:45 am

Re: Flexibility in project

Post 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 ;)
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Flexibility in project

Post 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.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Flexibility in project

Post 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?
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Flexibility in project

Post 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.
User avatar
Anisij1981
Prole
Posts: 1
Joined: Mon Feb 07, 2011 4:09 pm
Location: Russia
Contact:

Re: Flexibility in project

Post by Anisij1981 »

Какой симпатичный ответ
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Flexibility in project

Post by Jasoco »

Anisij1981 wrote:Какой симпатичный ответ
Yes. It is a nice answer.. I guess?
Post Reply

Who is online

Users browsing this forum: No registered users and 217 guests