yipee got to grips with sprites

this week to get further into corona I gave myself the challenge to display random roadsigns generated from a spritesheet.

code here: https://www.sugarsync.com/share/enrgehqv9gfrs

the key eureka moment was to pre-create a set of spritesets
based on the index of the frame in the spriteset:
[lua] self.SpriteSets = {}
oSheet = sprite.newSpriteSheet(self.spriteFile, self.spriteSize, self.spriteSize)
for i =1, self.maxSpriteFrames do
oSpriteSet = sprite.newSpriteSet(oSheet,i,1)
table.insert(self.SpriteSets, oSpriteSet)
end[/lua]

which meant that when I wanted a random object I just pulled it out from the table stored in my class

[lua] iSet = math.random(1, cRoadSigns.maxSpriteFrames)
oSprite = sprite.newSprite(self.SpriteSets[iSet])[/lua]

so now I have endless tumbling roadsigns from the UK. :slight_smile:

next challenge, for another week, add a random sound generator.
[import]uid: 74338 topic_id: 20391 reply_id: 320391[/import]

Nice work :slight_smile: [import]uid: 84637 topic_id: 20391 reply_id: 79856[/import]

thanks - anyone care to peer review my code. I come from a structured OO way of working in Java, Visual basic and delphi. Been programming that way for a few - many … too many years now and I wonder if its ok to use a similar style in lua. Is there eg a tradeoff for say performance when using OO?

The roadsign tumbler app above creates a new instance every time something tumbles off screen. I’m resetting obj references to nil, but I’m wondering whether I should be doing anything else as there is no explicit free function.

Well still got a lot to learn… must crack on [import]uid: 74338 topic_id: 20391 reply_id: 79908[/import]