Adding graphics to a "buffer" drawing from table not working

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
MattyAB
Citizen
Posts: 57
Joined: Wed Mar 25, 2015 8:37 pm

Adding graphics to a "buffer" drawing from table not working

Post 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!
Attachments
game.love
(80.13 KiB) Downloaded 107 times
Check out my blog - The place to find out about the latest tech news! http://thegeekcircle.blogspot.co.uk/
Joe Black
Prole
Posts: 39
Joined: Wed Jan 21, 2015 1:57 pm

Re: Adding graphics to a "buffer" drawing from table not wor

Post 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) :

Code: Select all

{1=1, 2=1, 3=true,..., 9=20}
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
Attachments
game.love
(80.13 KiB) Downloaded 90 times
User avatar
MattyAB
Citizen
Posts: 57
Joined: Wed Mar 25, 2015 8:37 pm

Re: Adding graphics to a "buffer" drawing from table not wor

Post 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
Attachments
game.love
(80.16 KiB) Downloaded 88 times
Check out my blog - The place to find out about the latest tech news! http://thegeekcircle.blogspot.co.uk/
User avatar
vladgalay
Citizen
Posts: 60
Joined: Sun Jan 29, 2012 4:54 pm
Location: The Motherland

Re: Adding graphics to a "buffer" drawing from table not wor

Post by vladgalay »

I added your world.loadData( ) function after line 24 in menu.lua, and it draws something now. The result is in attachment :nyu:
Attachments
game_c1.love
(94.57 KiB) Downloaded 93 times
User avatar
MattyAB
Citizen
Posts: 57
Joined: Wed Mar 25, 2015 8:37 pm

Re: Adding graphics to a "buffer" drawing from table not wor

Post 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
Attachments
game.love
(81.71 KiB) Downloaded 74 times
Check out my blog - The place to find out about the latest tech news! http://thegeekcircle.blogspot.co.uk/
User avatar
vladgalay
Citizen
Posts: 60
Joined: Sun Jan 29, 2012 4:54 pm
Location: The Motherland

Re: Adding graphics to a "buffer" drawing from table not wor

Post 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 :nyu:

    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 :crazy:
Attachments
game (1)_c1.love
(96.66 KiB) Downloaded 77 times
User avatar
MattyAB
Citizen
Posts: 57
Joined: Wed Mar 25, 2015 8:37 pm

Re: Adding graphics to a "buffer" drawing from table not wor

Post by MattyAB »

Thanks! This has really helped me in my development in the game.
Check out my blog - The place to find out about the latest tech news! http://thegeekcircle.blogspot.co.uk/
Post Reply

Who is online

Users browsing this forum: No registered users and 50 guests