Sprite Sheet Move/Animation

Hi all,

I have a doubt with the sprite sheets in corona.

When developing a game like endless runner that use a sprite sheet for the character to walk, run, jump, whatever… You basic call a frame to frame of the sprite sheet you want to do that animation as the background that moves in the backs, right?

But in my case i have: 

a fixed background image;

The character have to move from one position to another doing the animation in not a straight line.

Please, see this video to understand what i’m saying: (It’s only 0:13) 

https://www.youtube.com/watch?v=Wz9SFvMN3PA

Is a playground swing animated. 

I want to do something like this with my sprites. Is that possible? 

Yes, sprite animations and transitions work independently, so you can easily combine them. For example, you can use sprite animation to make the guy move his arms & legs, then use transitions to move/rotate the whole guy to simulate the swing.

You could even build a physics swing, which would make for a nicer animation (and be more fun :slight_smile:

Hey _memo, thanks for the answer.

Yes, how i do that, do you know any tutorial?

I want to set the sprite as a physics object so it can interact with another physics objects. His move is a bit like the swing i posted, is not straight line. Think as a target moving by swinging in the screen, you know?

What do i search for do such a thing? Transition?

Hi @Ziad.Ali,

Our physics-related guides and tutorials can be found here:

http://coronalabs.com/resources/tutorials/physics-box2d/

Take care,

Brent

For clarity – if you want to build a physics swing, search for physics not transitions. Transitions and physics are different. With transitions you are directly moving objects around with your code, while with physics you let the physics engine move objects for you.

@_memo, @Brent Thanks for helping.

BUT, i’m a little bit lost yet, sorry.

If i set the sprite to be a physics body, how do i set them to move in the screen doing the animation frames i want to and using fixed positions? Like in the image attached(I drew in a paper, sorry hahah :smiley: ). Think as a spider-man game (it’s not, but has the same concept).

xn9312.jpg

In the image you can see the (P1) as the initial point going to a fixed point 2: (P2). And not in a straight line like: ---->, you can see a curve. And All of his trajectory playing the frames: 1,2,3,4.

In a period of time i want the sprite, to leave (P2) and go the P3 playing those frames i mentioned in the image.

Using physics i can do that?

Yep, it’s possible. Here’s some example code that creates a rudimentary swing out of circles and rectangles, and pushes it. This shows how to create physics bodies and assemble them with joints. Put it in a main.lua and run it.

local physics = require("physics") -- create our "sprites" local swing = display.newRect(100, 100, 100, 5) local chain = display.newRect(100, 100, 5, 200) chain.anchorX, chain.anchorY = 0.5, 0 local guy = display.newRect(100, 300, 30, 30) -- create physics bodies for sprites physics.start() physics.addBody(swing, "static") physics.addBody(chain, {density = 0.5}) physics.addBody(guy, {density = 1}) -- assemble physics bodies with joints local swingChainJoint = physics.newJoint("pivot", swing, chain, swing.x, swing.y) local chainGuyJoint = physics.newJoint("weld", chain, guy, guy.x, guy.y) -- push the guy guy:applyLinearImpulse(10, 0)

Heey, thanks @_memo.

That’s a start, i’m playing with your code to understand physics. After that i will try to add the sprite sheets.

Yes, sprite animations and transitions work independently, so you can easily combine them. For example, you can use sprite animation to make the guy move his arms & legs, then use transitions to move/rotate the whole guy to simulate the swing.

You could even build a physics swing, which would make for a nicer animation (and be more fun :slight_smile:

Hey _memo, thanks for the answer.

Yes, how i do that, do you know any tutorial?

I want to set the sprite as a physics object so it can interact with another physics objects. His move is a bit like the swing i posted, is not straight line. Think as a target moving by swinging in the screen, you know?

What do i search for do such a thing? Transition?

Hi @Ziad.Ali,

Our physics-related guides and tutorials can be found here:

http://coronalabs.com/resources/tutorials/physics-box2d/

Take care,

Brent

For clarity – if you want to build a physics swing, search for physics not transitions. Transitions and physics are different. With transitions you are directly moving objects around with your code, while with physics you let the physics engine move objects for you.

@_memo, @Brent Thanks for helping.

BUT, i’m a little bit lost yet, sorry.

If i set the sprite to be a physics body, how do i set them to move in the screen doing the animation frames i want to and using fixed positions? Like in the image attached(I drew in a paper, sorry hahah :smiley: ). Think as a spider-man game (it’s not, but has the same concept).

xn9312.jpg

In the image you can see the (P1) as the initial point going to a fixed point 2: (P2). And not in a straight line like: ---->, you can see a curve. And All of his trajectory playing the frames: 1,2,3,4.

In a period of time i want the sprite, to leave (P2) and go the P3 playing those frames i mentioned in the image.

Using physics i can do that?

Yep, it’s possible. Here’s some example code that creates a rudimentary swing out of circles and rectangles, and pushes it. This shows how to create physics bodies and assemble them with joints. Put it in a main.lua and run it.

local physics = require("physics") -- create our "sprites" local swing = display.newRect(100, 100, 100, 5) local chain = display.newRect(100, 100, 5, 200) chain.anchorX, chain.anchorY = 0.5, 0 local guy = display.newRect(100, 300, 30, 30) -- create physics bodies for sprites physics.start() physics.addBody(swing, "static") physics.addBody(chain, {density = 0.5}) physics.addBody(guy, {density = 1}) -- assemble physics bodies with joints local swingChainJoint = physics.newJoint("pivot", swing, chain, swing.x, swing.y) local chainGuyJoint = physics.newJoint("weld", chain, guy, guy.x, guy.y) -- push the guy guy:applyLinearImpulse(10, 0)

Heey, thanks @_memo.

That’s a start, i’m playing with your code to understand physics. After that i will try to add the sprite sheets.