Collision/Animation Troubles

Hi Everyone!

I’m looking to create a game where things will change appearance when they collide with something. For example, when a plant ‘collides’ with water it will grow and change colour from green to blue, etc.

I’m really stuck on this, I was thinking sprites would probably need to be called but I wasn’t sure how I would get the game to recognize which one to use at different times, ‘if’ statements might work but I have no idea how I would go about that.

Anyway, any and all help is appreciated :slight_smile:
[import]uid: 90223 topic_id: 15855 reply_id: 315855[/import]

Sprite! Yes!

You’d set the current frame of the sprite to, maybe, +1 ? I don’t know quite how you’re doing it.

Then if current frame is == 10 (supposing sprite is 10 frames long) set it back to one.

Does that help? I’m not sure how new you are to Corona, or this area of Corona, so if need be I can try to provide something I little more solid for you.

Let me know :slight_smile:

Peach [import]uid: 52491 topic_id: 15855 reply_id: 58706[/import]

Hey,

I found myself with a little spare time this evening so threw something together for you;
http://techority.com/example01.zip

Enjoy :slight_smile:

Peach [import]uid: 52491 topic_id: 15855 reply_id: 58714[/import]

Hi Peach!

Thanks for sending me those files, they really helped me understand how I could use sprites to add animation!

However, the sprite would only make it look different right?
Sorry I didn’t say before but I think in order for my game to recognize a win, the ‘hero’ would need to have different properties to when it started otherwise you could complete it without doing anything.

For example, with sprites its color would appear to be the same, at least to the system, and if you can only win by changing the color it would never accept it and the game would go on forever, unless of course there was some way for it to measure which frame of the sprite it was on and act accordingly?

Sorry to waste your time like that, is there anything else you can suggest? [import]uid: 90223 topic_id: 15855 reply_id: 58724[/import]

So you win by changing the color of the sprite?

As in you have a box on the screen that must be blue for the hero to pass.

It starts as green, the hero does something to it to change the color. Green, change to red, change to blue.

And you need to know when it becomes blue - is that correct?

You can easily check which frame the sprite is on and act accordingly!

Say the 3rd frame was blue,

[lua]if greenMan.currentFrame == 3 then
– do something
end[/lua]

Does that help or am I still not understanding your exact needs?

Peach :slight_smile: [import]uid: 52491 topic_id: 15855 reply_id: 58829[/import]

Exactly, in order to win the hero must be a certain color (stage of the sprite) and say touching the flag.

Therefore the ability to know what stage of the sprite he is on is a massive help, thank you so much for that little piece of code!

If I could ask you for another thing, is there a way to only play the sprite when it hits certain objects? It wouldn’t be much to play if the sprites activated if you just hit the wall!

Thanks again :slight_smile:

EDIT:

P.S -

Here’s the code I’m currently using:

function greenredChange:collision (event) if event.phase == "began" then if greenredChange.currentFrame == 1 then greenredChange:prepare("greenredChange") greenredChange:play("greenredChange") else greenredChange.currentFrame = greenredChange.currentFrame end end end [import]uid: 90223 topic_id: 15855 reply_id: 58910[/import]

Yes, you can do that using collision detection.

I have a tutorial on it (Corona For Newbies Part 4) that you can find on http://techority.com

Peach :slight_smile: [import]uid: 52491 topic_id: 15855 reply_id: 59039[/import]

Thanks Peach that tutorial was really helpful and I think I have the collision detection done now, thanks for all your help :slight_smile: [import]uid: 90223 topic_id: 15855 reply_id: 59865[/import]