Hi, I’, trying to make a 2d Building game, but I ran into a problem. With all the terrain and houses, it makes the program slow down A LOT, I think the reason is the loop. I’ve made a loop that goes through a table, and redraws each of them, so if I have 300 squares on the screen, then it has to redraw them every frame. Or maybe its because they are physic bodies. Does anyone have any ideas? Could I use backingmode somehow?
@stevon8ter I thought of that, but I’m not sure that would be any better. Because every time the player walks, it would get laggier creating and removing the physic.bodies
Well if you give me a day or so to work something out… xD
nah i’ll try to work something out in an hour or 2… whenever i go to bed i’ll start working on it, but idk if i’ll manage to do it ;p
I’m relative noob at codea, but i already made some of this games in other languages, especially on my TI84+ calculator xD
But as far as that went, it was with a grid system… but smooth movement, but It should be possible to work something out
@Prynok I don’t know if this is something like you’re doing, but I’m moving a character around a grid area checking if it’s over a key. I don’t think it would slow down that much if I placed houses or other objects on the screen and checked to keep the character from going thru them. Maybe I’ll try adding squares and see what happens.
@Prynok@stevon8ter I don’t play games, so I had to look up terraria to see what you were talking about. I think the physics.objects are out. When I saw one of the guys digging away at a wall with a pick, the pick was overlapping the wall as he was swinging it, so I think distance calculations would work.
ok i worked a small example out, tho it’s rather messy and uncommented
I just don’t have alot of time now, but around 4am, when i stop skyping, i’ll try to write it out nicely and commented
also, you might wanna considere using a vec3, and using the z to store blockdata
-- test
-- Use this function to perform your initial setup
function setup()
print("Hello World!")
displayMode(FULLSCREEN)
char = vec2(75, 525)
Blocks = {}
for e = 1, 10 do
Blocks[e] = {}
for i = 1, 60 do
Blocks[e][i] = vec2(i*50 - 25, e*50 - 25)
end
end
Blocks[10][7].y = 9*50 - 25
Blocks[10][9].y = 9*50 - 25
Blocks[10][8].y = 9*50 - 25
jump = false
end
-- This function gets called once every frame
function draw()
print(char.x)
print(char,y)
background(113, 255, 0, 255)
for i, v in ipairs(Blocks) do
for e, k in ipairs(Blocks[i]) do
sprite("Platformer Art:Block Grass", Blocks[i][e].x, Blocks[i][e].y, 50, 50)
end
end
print(math.ceil((525-50)/50))
if char.y - 25 > Blocks[math.ceil((char.y-50)/50)][math.ceil((char.x+25)/50)].y + 25 and char.y - 25 > Blocks[math.ceil((char.y-50)/50)][math.floor((char.x+25)/50)].y + 25 then
char.y = char.y - 1
end
sprite("Platformer Art:Hill Short", char.x, char.y, 50, 50)
if CurrentTouch.state ~= ENDED then
if CurrentTouch.x < char.x then
char.x = char.x - 1
elseif CurrentTouch.x > char.x then
char.x = char.x + 1
end
end
end
function touched(touch)
end
@stevon8ter I don’t want a grid system at all. I’m trying to allow users to place blocks anywhere on the screen, not just a fixed point in space.
Also, your example is great, I understood the hole thing, the problem is its a lot slower than my physic.bodies method, Probably because the loop with physic.bodies is equal to the giant “if” statement.