Hello there, guys . I have an optimization problem in my project. I make a 2d table (maybe that can solve with 1d table), which contains position of platforms on the screen. There is a screenshot how it looks in game
Sprites in bottom are an animation, which slows down then platforms appear (platforms are static. I had an idea make that field in photoshop, but i decide made it in codea)
Here is my code :
Platforms class
Lvls = class()
function Lvls:init(x)
-- you can accept and set parameters here
self.platform = {}
for x = 1,size do
--size = 7
self.platform[x] = {}
for y = 1,size do
self.platform[x][y] = vec2(150+x*90,50+y*90)
if math.fmod(x,2) == 0 then
self.platform[x][y].y = self.platform[x][y].y - 45
end
end
end
end
function Lvls:construction()
for k,v in pairs(self.platform) do
for a,b in pairs(self.platform[k]) do
sprite("Documents:RhPlatform",b.x,b.y,512/2,512/2)
end
end
end
function Lvls:draw()
-- Codea does not automatically call this method
background(0,0,0)
self:construction()
hero:draw()
monsters:draw()
monsters1:draw()
monstersfr:draw()
end
function Lvls:touched(touch)
-- Codea does not automatically call this method
end
Hero’s Animation class (blue man in the bottom).
Similar to other three sprites
Hero = class()
function Hero:init(x)
-- you can accept and set parameters here
self.frames = {"Documents:RhHeroframe1",
"Documents:RhHeroframe2",
"Documents:RhHeroframe3"}
self.herox = WIDTH/2
self.heroy = 95
self.count = 1
self.stop = false
self.currentFrame = 1
self.herow = 512
end
function Hero:position()
end
function Hero:arrows()
if CurrentTouch.x > WIDTH/2 and touching == true then
self.herox = self.herox + 5
self.herow = 512
elseif CurrentTouch.x < WIDTH/2 and touching == true then
self.herox = self.herox - 5
self.herow = -512
end
if self.herox < 100 then
self.herox = 101
elseif self.herox > WIDTH-100 then
self.herox = WIDTH-100
end
self.position()
end
function Hero:draw()
-- Codea does not automatically call this method
-- background(0, 0, 0, 255)
if touching == true then
self.count = self.count + 1
if self.count > 7 then
self.count = 1
self.currentFrame = self.currentFrame + 1
if self.currentFrame > 3 then
self.currentFrame = 1
end
end
sprite(self.frames[self.currentFrame],self.herox,self.heroy,self.herow/4,512/4)
else
sprite("Documents:RhHeroframe2",self.herox,self.heroy,self.herow/4,512/4)
end
self:arrows()
end
function Hero:touched(touch)
-- Codea does not automatically call this method
end