PÄSSION 0.6.2rc1 is here!
It has been some time since I did not update this thread. In the meantime,
development has continued. You can blame the lack of forum updates on work, holidays, and then
this guy and
this other guy.
Last time Osuf suggested two improvements: stackable states and an observer pattern. Both are done now.
- Regarding stackable states, I've even made some documentation about them.
- I've implemented a little messaging system called Beholder (Observer was too boring). Quick sneak peek:
Code: Select all
MyActor = class('MyActor', passion.Actor)
function MyActor:initialize()
super.initialize(self)
self:observe('keypressed_up', 'goUp')
self:observe('keypressed_down', function(obj) obj.y = obj.y + 1 end)
end
function MyActor:goUp()
self.y = self.y - 1
end
function MyActor:destroy()
self:stopObserving('keypressed_up')
self:stopObserving('keypressed_down')
end
Notice that it is possible to specify either a function or a method name for the callback. The callbacks admit parameters (mousepressed_l will give you the x and y coords, for example)
'keypressed_up' and 'keypressed_down' are events triggered by PÄSSION, but it is possible to trigger them from code by invoking:
It is also possible to create custom messages - for example, on a multiplayer game, one could create an event called 'player_won', passing the winning player as a parameter:
Code: Select all
Player = class('Player') -- Player is a regular class (not an actor)
Player:implements(Beholder) -- This includes "observe" and "stopObserving" on regular classes. passion.Actor includes it by default.
function Player:initialize(name)
super.initialize(self)
self.name = name
self:observe('player_won', 'someoneWon')
end
function Player:someoneWon(someone)
if(someone==self) then
print(self.name .. ' : yahooo!')
else
print(self.name .. ': buaaaah!')
end
end
frank = Player:new('frank')
peter = Player:new('peter')
ann = Player:new('ann')
Beholder.trigger('player_won', ann) -- ann will smile, peter and frank will cry
In additon to these changes, I've:
- Removed the hasBody / hasImage stuff. There's a proper subclass now, called ActorWithBody, that handles actors with bodies. HasImage was too trivial, so I've just scrapped it.
- I've chanded all passion:methods to passion.methods, so it looks more like love now.
- I've added utility functions here and there. passion:dumpTable(t) will output the contents of a table on the console. There's also a function for drawing shapes (passion.graphics.drawShape) that it is used by ActorWithBody:drawShapes, a very useful debug function. And there are others, mostly on passion_util.lua.
- I've re-organized the code in modules: audio, fonts, graphics, gui, oop and timer. Hopefully this will make the library easier to understand on a first glance.
- By the way, timer functions are the other big addition. Check this out:
Code: Select all
MyActor = class('MyActor', passion.Actor)
function MyActor:initialize()
super.initialize(self)
self:after(3, function(obj) print('This will be printed 3 seconds after the object creation') end)
self:every(4, 'shout', 'wooho!') -- prints 'Periodic call - wooho!' every 4 seconds
self:every(5, 'shout', 'yeehoo!') -- prints 'Periodic call - yeehoo!' every 5 seconds
end
function MyActor:shout(phrase)
print('Periodic call - ' .. phrase)
end
The 'after' and 'every' functions allow you to invoke methods (by name) or functions, with optional parameters.
Finally, I've updated all the samples on this thread to the latest version of PÄSSION. I've replaced the old versions on their respective entries, but for comfort I'm also attaching them here (except the piano one, which is too big - you might find it
here).
What comes next?
- Well, I certainly want to include more gui elements.
- I'm also planning to make an 'interpolator', based on the timer implementation that I've got now. This will allow the creation of "fade in/fade out" effects (like the ones Jasoko and others alked about not long ago) easily, not only on images, but on every lua object (i.e. sounds). I'll be "inspiring myself" on jquery's animate function.
- I'll try to create a passion.audio.play method that handles the duplication the source automatically so we can hear the same sound more than once.
- I still have to delucidate a way to handle the new camera-like functions of love properly.
- And, documentation . I keep delaying this one, but sooner or later I will have to start writing tutorials about PÄSSION.
- I'm making a space game that uses all the new stuff. I've got a ship that shoots stuff, with different cannons. I'll publish it once I get it done to the "Asteroids" level.
Sorry for the long post. Comments / Questions are welcomed - and encouraged!