Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to have a pattern of objects move across the screen?

edited June 2014 in Questions Posts: 178

Hello, I recently bought Codea and I am getting a hang of it pretty quickly. However, I can't seem to figure out how to get a pattern of objects like the tunnels in Flappy Bird to move across the screen, delete themselves when they move out of the screen, and respawn at the top of the screen to start the process over again. I have heard about the table feature in Codea, but I don't know enough about it to store sprites and adjust their position on the screen.

If anyone could provide a simple example that would be awesome!

Also this is off topic, but if anyone knows how to implement a swipe function to transition across a main screen to another screen with preserving the same background image and only moving the text and buttons, I would love to know more about this. It seems a lot more complicated to do the swipe gesture on Codea than on XCode.

Comments

  • dave1707dave1707 Mod
    Posts: 7,911

    @YoloSwag Something like this. Tables make things easy, so I suggest that you read up on them.


    displayMode(FULLSCREEN) function setup() reset() end function reset() tab={} for z=1,15 do table.insert(tab,vec2(WIDTH,z*50)) end end function draw() background(40, 40, 50) for a,b in pairs(tab) do sprite("Cargo Bot:Crate Yellow 2",b.x,b.y) b.x=b.x-1 if b.x<0 then reset() end end end
  • dave1707dave1707 Mod
    Posts: 7,911

    @YoloSwag Here's another example.


    displayMode(FULLSCREEN) function setup() reset() end function reset() tab={} tab[1]=vec2(-100,100) tab[2]=vec2(-100,150) tab[3]=vec2(-100,200) tab[4]=vec2(-50,100) tab[5]=vec2(-150,100) end function draw() background(40, 40, 50) for a,b in pairs(tab) do sprite("Cargo Bot:Crate Yellow 2",b.x,b.y) b.x=b.x+2 if b.x>WIDTH+100 then reset() end end end
  • edited June 2014 Posts: 178

    Thank you so much dave1707! And I will make sure I read up more on tables.

Sign In or Register to comment.