Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Change animation sprite after event touch.
Started by luca.pasqu.pasqual Dec 18 2018 02:47 AM

3 replies to this topic
sprite animation spritesheet event touch jumo
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

luca.pasqu.pasqual

[GLOBAL: userInfoPane.html]
luca.pasqu.pasqual
  • Observer

  • 2 posts
  • Corona SDK

Hi guys, my name is Luca and I'm new. I have a question to ask you. how can you change the animation of a sprite following an event?! .... I have a spritesheet of 13 frames in which the first 8 are an animation while from 9 to 13 is another animation. I wrote the code so that the first animation starts immediately but I would like to implement the code so that until the position of my object does not return the starting one, the second animation is performed. I have an object that walks and with the pressure of a button it jumps. I would like to make sure that when I click the button the animation of the jump is performed and when I retouch the ground, I resume the animation of the walk .... can someone help me?



[TOPIC: post.html]
#2

carloshritzmann

[GLOBAL: userInfoPane.html]
carloshritzmann
  • Observer

  • 9 posts
  • Corona SDK

Well, i know it's a stupid idea but i don't see how to solve your problem using the standard display API from corona.

 

Why? Well, bc when you have the sprite, you must set the desired sequence before playing. But, if you want an offset as the beggining of the choosen sequence, the sequence will not play if you call setFrame() method. So there is no way to put an offset, as you can't edit the sequence parameters given to your sprite.

 

So, here is the answer:

Why not store a invisible clone object as a backup to the paused sequence?

 

Example:

You have a player sprite that has 2 sequences:     run     and    jump.

 

When you start the game, you create 2 player sprites, and keep 1 of them invisible (alpha = 0). When you need to jump, pause the run animation, set the player invisible, make the clone visible and make it jump. When it lands on the ground, just do the opposite.

 

It's a easy solution, the problem is the cost of memory for keeping 2 player sprites instead of only 1.



[TOPIC: post.html]
#3

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,463 posts
  • Corona SDK

Hopefully I understood your question: https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/12/walk_jump.zip

 

If not, please try re-posting without making a wall of text.  Use proper formatting, capitalization, spelling, paragraph breaks, bullet lists, ... and in general try to make the question legible and easily understood.

 

My rule of thumb: "The OP should spend more time and effort asking a question than the answering party should spend answering the question."

 


Edited by roaminggamer, 22 December 2018 - 05:46 PM.


[TOPIC: post.html]
#4

carloshritzmann

[GLOBAL: userInfoPane.html]
carloshritzmann
  • Observer

  • 9 posts
  • Corona SDK

Well, i know it's a stupid idea but i don't see how to solve your problem using the standard display API from corona.

 

Why? Well, bc when you have the sprite, you must set the desired sequence before playing. But, if you want an offset as the beggining of the choosen sequence, the sequence will not play if you call setFrame() method. So there is no way to put an offset, as you can't edit the sequence parameters given to your sprite.

 

So, here is the answer:

Why not store a invisible clone object as a backup to the paused sequence?

 

Example:

You have a player sprite that has 2 sequences:     run     and    jump.

 

When you start the game, you create 2 player sprites, and keep 1 of them invisible (alpha = 0). When you need to jump, pause the run animation, set the player invisible, make the clone visible and make it jump. When it lands on the ground, just do the opposite.

 

It's a easy solution, the problem is the cost of memory for keeping 2 player sprites instead of only 1.

Yeah, my bad, i interpreted wrong his question.. apologies. This solves something entirely different.

 

 

It's actually pretty easy to solve your problem. 2 commands:   sprite:setSequence("sequence name") and then sprite:play(), that's it. Call it when you press the button to jump, and when your character land on the groud, just like the roaminggamer example.




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: sprite, animation, spritesheet, event, touch, jumo