Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+2)

You've got some good answers already but here's another style of moving canvases around.

If you'd like to have things visibly move from one location to another, like a smooth slide across the screen, I sometimes use the Ease module for that. You can find ease.deck in the examples folder that comes along with Decker. You'll need to transfer the ease module from that example deck into your project.

An example of creating this kind of animation with the Ease module might look like this:

on click do
 time:60
 each i in range time
  mycanvas.pos: ease.lerp[i/time-1  startref.pos  endref.pos]
  sleep[]
 end
end

To explain what's going on here:

The "time: 60" creates a temporary variable called time which is used to set how many frames the animation should take. Decker runs at 60 frames per second so this example goes pretty fast. Feel free to change the number to whatever you want.

The "each" loop will run repeatedly, for as many loops as the number in our "time" variable.

The mycanvas.pos: part starts just like the other examples in the thread, by setting the position of the image (canvas) you want to move... 

But in this example I'm calling on the ease module to help do the math for a specific style of movement. There's a bunch of different functions representing different kinds of movement in the module. Smooth, elastic, bouncy, etc. You can see all the included possibilities if you open up ease.deck. I chose lerp for this because it's smooth and simple but you can replace lerp with any of the other options.

The startref.pos and endref.pos inside of the brackets are our start and end positions. I wrote it as if they were referencing other widgets like Internet Janitor mentioned or they could be replaced with pairs of coordinates.

sleep[] pauses for a frame on each step of movement while the "each" loop is running. This is needed to make the animation take the amount of time we set earlier.

Then the two ends close off the "each" loop and the original "on click do" event handler.

I hope this makes some sense. It may not be what you're looking for right now, I just wanted to mention it.