Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Help with code for transition.to with moving boards.
Started by matthewhanc Jan 11 2020 03:27 AM

- - - - -
2 replies to this topic
code lua
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

matthewhanc

[GLOBAL: userInfoPane.html]
matthewhanc
  • Observer

  • 2 posts
  • Corona SDK

Hi all,

 

I'm currently working on a game 'Magnet Monsters' please see link to tweet to see the demo of the game so far.

 

https://twitter.com/playhousegamer/status/1215953580131266560

 

There are 2 boards moving across the screen at the same time using transition.to. When you move between the boards they stop and start again when you land. The transition.to starts again so if you're very close to the edge it still uses up the 1000 to only go a short distance which doesn't make for great gameplay!

 

Is there a way to always make the boards move at the same speed even after they've stopped and started again? I was thinking of using the system time but am not sure how to do this. All help appreciated. Transition.to code below.

   function moveTopBlock()
			topblock.transition = transition.to(topblock,{time = 1000,x = _CW-topblock.width/2, onComplete = trans2})
		end
    
    trans2 = function ()
      topblock.transition = transition.to(topblock,{time = 1000,x = 0+topblock.width/2, onComplete = moveTopBlock})
      end

I've also attached the .mov but not sure if that uploads so have included link.

 

Many thanks

 

Matt



[TOPIC: post.html]
#2

ldurniat

[GLOBAL: userInfoPane.html]
ldurniat
  • Contributor

  • 403 posts
  • Corona SDK

Hi @matthewhanc,

 

Try

function moveTopBlock()
  local total_time = 1000
  local total_distance = _CW - topblock.width
  local const_velocity = total_distance/total_time
  local new_distance = total_distance + topblock.width/2 - topblock.x
  local new_time = new_distance/const_velocity 

  topblock.transition = transition.to(topblock,{time = new_time,x = _CW-topblock.width/2, onComplete = trans2}) 
end
    
trans2 = function ()
      topblock.transition = transition.to(topblock,{time = 1000,x = 0+topblock.width/2, onComplete = moveTopBlock})
end

Can you use transition.pause and transition.resume?

 

 

Have a nice day:)

ldurniat



[TOPIC: post.html]
#3

matthewhanc

[GLOBAL: userInfoPane.html]
matthewhanc
  • Observer

  • 2 posts
  • Corona SDK

Hi @idurniat,

 

Thank you so much for your help! The code works very well, as soon as I read it I thought 'why didn't I think of that!' I've posted a new tweet for the Saturday Game Dev. Please see link below, the game flows so much better now.

 

https://twitter.com/playhousegamer/status/1216134679662821377

 

I no doubt will be back on the forum as I am now noodling adding in new monsters as you progress through the levels. I'll see what my brain can process first!

 

Many thanks

 

Matt




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: code, lua