how do you cope with having rotation and scaling but not general transformation
By using glRotatef and glScalef. Maybe change it to glMultMatrix if/when we implement general transformations.
how do you cope with having rotation and scaling but not general transformation
Code: Select all
obj = {}
function obj:new(o, ...)
o = o or {}
setmetatable(o, self)
if not rawget(self, '__index') then self.__index = self end
o.__parent = self
if o.__init then o:__init(...) end
return o
end
Hehe, go for it . You existing character-walking-demo could totally be tutorialized.aes wrote:There's a reason I really want to demo the basics in a way that isn't really necessary in löve projects: I've a friend i'd like to show these things.
Nice. I've done my "classes" manually so far. Maybe it's a good idea to use something like this instead.Merkoth wrote:There are a gazillion implementations of OOP in lua. Here's just one example: m http://class.luaforge.net/
This, unfortunately, is part of the problem. Another part is that there's really no known way so far of getting it quite right. To see why, let's dissect my suggested version:Merkoth wrote:There are a gazillion implementations of OOP in lua.
Code: Select all
obj = {} -- the ur-instance. needed, obviously
function obj:new(o, ...) -- note that the default ctor also takes varargs.
o = o or {} -- so far, so good.
setmetatable(o, self)
if not rawget(self,'__index') then
self.__index = self -- the reason for this nugget is to permit sub-
end -- classes to override __index.
o.__parent = self -- non-std, to know inheritance in new __index:en
if o.__init then
o:__init(...) -- a (possible) initializer that does not need to
end -- bother with metatable and this stuff.
return o
end
Code: Select all
function rect:__index(k)
if k == 'xa' then do return self.x end
-- ...
elseif k == 'y1' then do return self.y + self.h end
elseif k == 'area' then do return self.w * self.h end
end
-- ok, it's not in the table itself (or we wouldn't be called)
-- and it's not any of the named extra properties,
-- so let's ask super.
return self.__parent[k]
end
Code: Select all
function charas:__init()
self:reloadAnim()
end
Code: Select all
function obj:isinstance(kls)
if kls == obj then return true end
local k = self
while k ~= obj do
if k == kls then return true end
k = k.__parent
end
return false
end
Yeah, I'll get there. Eventually.rude wrote:Hehe, go for it . You existing character-walking-demo could totally be tutorialized.
Code: Select all
love.filesystem.require"util.lua"
love.filesystem.require"charas.lua"
function load()
love.graphics.setBackgroundColor(224,224,255)
playa = charas:new{imagename="d00d.png",pos=v2:new{x=200,y=200}, }
Code: Select all
keys = {
[ love.key_up ] = playa.sequences.walk_n,
[ love.key_down ] = playa.sequences.walk_s,
[ love.key_left ] = playa.sequences.walk_w,
[ love.key_right ] = playa.sequences.walk_e,
}
end
function update(dt)
playa.seq = playa.sequences.stop_s
for k,v in pairs(keys) do
if love.keyboard.isDown(k) then playa.seq, x = v, true end
end
playa:update(dt)
end
function draw()
playa:draw()
end
Code: Select all
local sequences = obj:new{
walk_n = { 0, 1, 2, 1, move=v2:new{x= 0, y=-2} }, ...
stop_n = { 1, move=v2:new{x=0,y=0} }, ...
}
charas = obj:new{
sequences = sequences,
cellsize = v2:new{ x=24, y= 32, }, cellcenter = v2:new{ x= 0, y=-15, },
pos = v2:new{}, delay = 0.075, time = 0, frame = 1, seq = sequences.stop_s,
}
Code: Select all
joe=charas:new{imagename="joe.png"}
Code: Select all
function charas:reloadAnim()
self.image = lg.newImage(self.imagename)
self.anim = lg.newAnimation(
self.image, self.cellsize.x, self.cellsize.y, 0, 0)
self.anim:setCenter(self.cellcenter.x, self.cellcenter.y)
end
function charas:__init()
self:reloadAnim()
end
Code: Select all
function charas:update(dt)
if self.delay > 0 then
self.time = self.time + dt
while self.time > self.delay do
self.frame = (self.frame+1) % #self.seq
self.pos = self.pos + self.seq.move
self.time = self.time - self.delay
end
end
end
Code: Select all
function charas:draw(pos)
local pos = pos or v2
pos = pos + self.pos
self.anim:seek(self.seq[self.frame+1] or 1)
lg.draw(self.anim, pos.x, pos.y)
end
Code: Select all
dancing = charas.sequences:new{
moonwalk_e = { 9,10,11,10, move=v2:new{x=3, y= 0} }, ...
}
playa = charas:new{
imagename="d00d.png",pos=v2:new{x=200,y=200},
sequences = dancing,
}
And here you go. I don't know if you can consider it a full-blown test suite, but it does give some info about performance. I'd löve to port it to AGen, but I can't be bothered to boot Windows,sorry.ivan wrote:I looked the other demos and the demopack but I couldn't find anything that tests performance.
How about a test suite demo? If somebody writes up a test suite, I'll make a parallel one in AGen.
It could be interesting to compare the two engines, especially in terms of rendering.
Love would probably be faster at rendering dynamic shapes - changing primitives or primitives generated per frame.
Well ... I don't think LÖVE would be faster at anything. You use a native container for sprites and graphics, so all you do in Lua is scene.add_child(), right? If you want to change a primitive, do you need to remove a child and re-add it? Remember that LÖVE has to iterate manually in Lua: foreach k,v in ipairs(enemies) ... end. 8-)ivan wrote:Love would probably be faster at rendering dynamic shapes - changing primitives or primitives generated per frame.
Code: Select all
ic = input.context:new{
keydown = {
[love.key_space] = {
function(menu)
world_master = m
menu:enter()
end,
m1,
-- more data here
},
},
}
Code: Select all
function do_it_but_like_with_the_thing(key) the_thing:do_it() end
Code: Select all
m1.items = {
{'Submenu', m2.enter, m2},
{'Other submenu', m3.enter, m3},
{"Don't do anything"},
{'Exit menu', m1.leave, m1},
}
Users browsing this forum: No registered users and 2 guests