Create Shield Around Ship

Honestly i dont know (and have tried but still confused) how to make a shield around a ship. I'm not asking about collision filter but how can I create that shield (transparent one) that would be used around the ship. So if i move to the left/right, the shield would move following the ship object as well.

Can you guys give me some codes example? because if i use (let's say) shield.jpg, then most likely it will not look transparent and also im not sure how can I create the shield to automatically move following the ship movement?

These are just some ideas off the top of my head.

If you don't want the shield to be part of the same "group" as the ship then set an enterframe listener to call a function which states:

shield.x = ship.x
shield.y = ship.y

you can change the opacity of an object by stating:

shield.aplha = x, (where x is the opactiy value. 0 = transparent, 1 = opaque)

additionally, you could give the shield a strength of say 10 initially and on each collision with a bullet/laser, deduct one from shield strength, and set shield.alpha = shield.alpha - 0.1

by doing so, the shield would become fainter the more damaged it was, until it vanishes entirely.

Hope that helps?

Dan

spider has it right.
I'd recommend that the shield is created at the same time as the ship, and part of the same group.
Set the image alpha to 0 initially.
Move the group instead of the ship.

When you want the shield visible, change the alpha of the shield image to a value higher than 0
And doing the 'subtract 0.1' thing is a funky way to show it losing power, although using SetFillColor would probably also be a good indicator. I imagine the eye would struggle to tell apart alpha of 0.6 from 0.5, but if the shading starts to go from electric blue to dull red, it will be very obvious.

ok thanks, i got the idea now. I will try to implement it and if i find any difficulty, i will edit this post.

hey guys, if i want to move a group instead of an object (so shield + ship move together), how do i do that?

also, when the shield is gone (opacity 0), then how do i make it doesn't have physics any longer?

edit: I changed shield.alpha = 0 but why it still look no different?

nvm, my mistake. I know what to do now, thanks guys

First you'll need to wrap your head around the concept of groups, try searching for a few tuorials initially.

Once you know what you want to acheive it's really easy.

local shipGroup = display.newGroup()

shipGroup:insert(ship)
shipGroup:insert(shield)

(now your ship and shield objects are part of shipGroup)

--whatever code to change the x and y of shipGroup on screen and move the whole group.

**A word of caution - physics collisions will only work correctly between objects in the same group, not across groups **

Brad, without wishing to be in any way rude, I think you need to start from the beginning and get to grips with how corona works, try doing some of the tutorials on the techority website, or have a look at the sample projects to get some ideas on how to do things.

to remove the physics from the sheild the easiest thing to do is simply delete the shield, (as at that point it is no longer visible)

You'd also need to remove it from memory, stop displaying it and set it to "nil."

In Omniblaster (http://bit.ly/omniblaster) I use 6 semi-transparent shields (one is very thin, showing you can only take one hit etc.) and I stack them on top of my ship and have everything in the same display group. Then I just move the display group as necessary.

views:1808 update:2012/2/7 8:40:54
corona forums © 2003-2011