Page 1 of 1
Adding graphics to a "buffer" drawing from table not working
Posted: Tue Jun 16, 2015 2:56 pm
by MattyAB
Hey Everyone,
I am writing a twist on Super Hexagon (check out my post about it here:
viewtopic.php?f=5&t=80361), and I am a bit stuck. So I've got the code for the table, as well as the table that *should* be drawing the blocks. I will attach a .love file so that you can take a look. So why is this mechanism not working? I only want it drawing the block if it's set to true in the worldData.spawn() call. Also, how would I be able to have it moving across the screen as well as making more at the same time? is there some way I can add it to some kind of buffer or something, and then it keeps the block drawn as long as it is on the screen. How would I go about doing this?
Attached will be a .love file. Here is the GitHub Repo:
https://github.com/tom7tomm/SuperDoger
Thanks!
Re: Adding graphics to a "buffer" drawing from table not wor
Posted: Tue Jun 16, 2015 11:00 pm
by Joe Black
for the first problem : drawing from table not working
when you insert the table in worldData here is the table you insert (with the example segment piece) :
what you want is that
Code: Select all
{segment=1, position=1, C1=true, ... , length=20}
here is the code
Code: Select all
table.insert(worldData, {segment=segment, position=position, C1=C1, C2=C2, C3=C3, C4=C4, C5=C5, C6=C6, length=length})
for the second point : have it moving across the screen as well as making more at the same time
There are many solution, you can use canvas : create a canvas with the image of the segment and draw it at the x you want.
But it's not what I would suggest. What I would do is add an element x in the table of a segment initialised at 100 and at each update x=x+dx*dt with dx the velocity and dt the parametre return by love.update(dt). and then you draw it at love.window.getWidth() - x
Re: Adding graphics to a "buffer" drawing from table not wor
Posted: Wed Jun 17, 2015 7:29 am
by MattyAB
I am fairly sure I have got what you said, but it's not drawing anything. Why not?
Attatched will be a .love
Sorry to be a n00b
Thanks
Re: Adding graphics to a "buffer" drawing from table not wor
Posted: Wed Jun 17, 2015 9:27 am
by vladgalay
I added your world.loadData( ) function after line 24 in menu.lua, and it draws something now. The result is in attachment
Re: Adding graphics to a "buffer" drawing from table not wor
Posted: Wed Jun 17, 2015 3:49 pm
by MattyAB
Thanks, didn't notice I wasn't calling that.
I have now added a bit more code to hopefully create the method of it moving across, but it does't like that I've put a variable in the worldData.spawn() call. Here is the code that it throws and attatched will be a .love.
Code: Select all
function world.loadData()
segment11x = love.graphics.getWidth()
worldData.spawn(1, 1, true, true, true, false, true, true, 20, segment11x) --an example segment piece
end
function worldData.spawn(segment, position, C1, C2, C3, C4, C5, C6, segmentx) --what segment number it is, position in the segment, column 1-6, length of that position in the segment, the X of that segment
table.insert(worldData, {segment = segment, position = position, C1 = C1, C2 = C2, C3 = C3, C4 = C4, C5 = C5, C6 = C6, segmentx = segmentx})
end
Re: Adding graphics to a "buffer" drawing from table not wor
Posted: Wed Jun 17, 2015 5:10 pm
by vladgalay
Well, i made segments move, but in a specific way. Here is a list of my changes to your code:
- First of all i changed line 19 of world.lua (which caused error) to:
Code: Select all
if v.segmentx < love.graphics.getWidth() and 0 < v.segmentx then
Then, to avoid other errors, i replaced v.length to v.segmentx (it displays weird, but i kinda like it), because v.length was no more in worldData
After running this game without errors, i decided to go further and to animate it. In order to do so, i added dt argument to love.update and world.update functions. I did so to connect movement with time
Then in world.update i added this cycle to make segments move:
Code: Select all
for i, v in ipairs(worldData) do
v.segmentx = v.segmentx - 100 * dt
end
And finally i changed line 50 of world.lua to this:
Code: Select all
worldData.spawn(1, 1, true, true, true, false, true, true, segment11x)
I removed the ninth argument (20) to make segment appear on the edge of the screen
The segments width display is weird, but i decided to keep it in that way
Re: Adding graphics to a "buffer" drawing from table not wor
Posted: Wed Jun 17, 2015 8:56 pm
by MattyAB
Thanks! This has really helped me in my development in the game.