Sprite-related question!
Displaying 1-6 of 6 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
ErayMan

I'm experimenting on sprites and I think they're pretty cool so far.
But I have two things that I would like to do but can't find any details in the docs.

For each sprites, there is a variable that is described as:
sprite.thinkproc - The function for Verge to call every time a sprite gets updated.

That's cool. The problem is:
I have multiple birds that I render using Sprites, and I want to move them around with the thinkproc function.
I set all the birds the same value:"moveBird"

In that function, is there a way to know which sprite is being rendered? The same way that the "event" variables contain the zone actually being triggered, is there a way to know that with the "sprite" variables?

Also, it would be cool to have a read/write variable "sprite.param" or something, to keep track of valuable information regarding a specific sprite, like which direction the bird is going, it's speed, etc.

The only way for now is to carry a set of global variables everywhere, matching the number of sprites, which is tiring. Sometimes I use the sprite.lucent variable for that, but I don't have a lot of room before it begins to show on-screen.

Any help on those two things would be appreciated! :)
Thanks
Eric

Posted on 2011-01-04 22:19:22

Kildorf

Hey, Eray.

Sadly I have bad news: I don't think there's any way to figure out which sprite has called the thinkproc. Someone can correct me on this one if I'm wrong.

That said, both of these are fantastic ideas and would both be steps towards improving the usefulness of sprites. We'll get them added, and hopefully a new release will be seeing the light of day in the not-too-distant future. We have some big changes to the engine coming, but these seem important enough that if those big changes are going to take too long, I'll try to get something put together prior to their release with these in there for you.

Thanks! It's always nice to hear feature requests from people actually using the engine. Seriously, much appreciated. :)

Posted on 2011-01-05 05:56:01

Overkill

Originally by Kildorf:

Sadly I have bad news: I don't think there's any way to figure out which sprite has called the thinkproc. Someone can correct me on this one if I'm wrong.


Use event.sprite and you can figure out what sprite triggered their sprite.thinkproc[] event.

As far as passing arguments instead of globals everywhere, that'd be nice, although I can't see it being possible in VC. In Lua, you can could create a local scope to keep other code from modifying the sprite variables, like this:

do
    local birds = {}
    function moveBird()
         if not birds[event.sprite] then
              -- First time using this sprite.
              -- Create new birds table entry.
              -- ...
         else
              -- Bird's entry exists, update it.
              -- ...
         end
    end
end

local spr = v3.GetSprite()
v3.sprite.image[spr] = birdFrame[1]
v3.sprite.thinkproc[spr] = moveBird


Really sprite.thinkproc[] should probably be using function values instead of names of global functions. That'll probably change later. But as you can see, you can create a private table for your sprite management, and then use event.sprite to index it, which should work for now.

EDIT:

Also, in Lua, making the engine keep track of extra arguments to functions is completely unnecessary, since you can create anonymous functions with upvalues, and basically use them to call higher-arg functions:

function f(a, b, c)
    return a + b + c
end

local g = function(a)
    return function()
        return f(a, 1, 1)
    end
end
local h = g(2)
print(h())

-- More complex example
function methodPointer(self, meth)
    return function(...)
        return self[meth](self, ...)
    end
end

Monster = {}
function Monster.new(name)
    local t = { name = name }
    for k, v in pairs(Monster) do
        t[k] = v
    end
    return t
end

function Monster:roar()
    print('The ' .. self.name .. ' roars!')
    self:roar()
end

monster = { Monster.new('Slime'), Monster.new('Bat') }

local f = methodPointer(monster[1], 'roar')
local g = methodPointer(monster[2], 'roar')
f()
g()


So I don't think we really need parameter-passing in the engine, only the ability to call anonymous zero-args functions. Perhaps some of the event data could be passed to the event callback, instead of held globally though.

Posted on 2011-01-05 08:14:38 (last edited on 2011-01-05 08:33:17)

ErayMan

Thank you Kildorf and Overkill! :)
event.sprite works perfectly.

Kildorf: you say big changes are coming. That's awesome :)
What kind of changes is it? I'm using the good ol' VC scripting. Is it exclusively for LUA? Will there be compatibility issues?
I'm always excited to see new features (the addition of "structs" and being able to render using CPU instead of GPU were nothing short of life changing :)) and I can't wait to see what's in store. You guys are geniuses.

Overkill: I haven't been able to try LUA so far. It looks very interesting! My game is getting pretty big in VC (~10k lines of code... it reminds me that I should probably update my gruedorf entry), remaking it in LUA while learning it would take me a hundred years haha.
(I'm also very fond of VC, I almost grew with it :P)
I'll have to try LUA on my next project!

Eric

Posted on 2011-01-05 13:49:46

Kildorf

Eray, if your game is getting that big, there's one big question I have:

Why aren't you posting in Gruedorf anymore?

:D

Posted on 2011-01-06 19:28:50

ErayMan

Soon, soon, I shall...!

Posted on 2011-01-12 16:30:56


Displaying 1-6 of 6 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.