How do I create a beam of light

0 favourites
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • I am doing a ship game, and i need to create a beam of light simila what truxton had

    I have the bean animation but i need that if it find a object.. it can lock on and rescale to it as i move.

  • Keep in mind, I'm a C2 noob

    You'll need to use this expression, that's all: distance(x1, y1, x2, y2) Calculate distance between two points

    hypothetical: We want a beam to hit player. I would set the origin of the beam to x=0 and y= 1/2 of the height

    Sprite Names:

    beam

    player

    Set the width of beam with an 'every tick' event:

    beam set angle towards position player.x, player.y

    beam width = distance(beam.x, beam.y, player.x, player.y)

    WARNING: This will distort the image of the sprite if its fancy lighting like in the picture you show. That should work, don't have the time to test myself though, sorry.

  • Just thought of something else, if what I posted helps you and you want to show the the beam travel you could make a global set the global as the distance and then create an event

    (event) beam width is < distance (action) beam width + 1

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It looks like that beam is split up into separate sprites. If you look carefully, you can see repeated sections, some mirrored.

    I reckon a simple way would be to have a bunch of beam segment sprites that get called in randomly and placed along a path. As long as the sprites all have the same start and end point there shouldn't be any visible seams. Hell, you could even animate them if you had the time to spend on it.

  • I still didnt get it.

    Here is the image that i will be using as lazer..

  • How do you plan to extend/shorten its length? looks like that gif is one single lazer with a clear start and finish, which means that if you keep it that way, you'll be stretching it out and it will looks weird.

    What I think would be best is to have a modular lazer beam that can be short or as long as it needs to be and the system adds in the segments to match the length. That would require breaking up them beam into parts, and each segment would need to start and finish in the same spot in the sprite sheet so the beam looks continuous as it animates.

    Someone else might have a better idea than me though.

  • I would simply use a really long sprite, and clip it to whatever length I need it to be (with a blending mask) at run time, and put an "explosion" over it at the destination to cover up the cut end.

  • igalencar

    Congratulations for attempting to clone Truxton

    I second oosyrag's suggestion, sounds straight forward and will look nice with a special animation to cover up the cutting point.

    The laser animation would need to be long enough to cover up the longest possible distance between the player ship and a target, that would be the length of one of the diagonals of the screen rectangle.

  • igalencar

    Congratulations for attempting to clone Truxton

    I second oosyrag's suggestion, sounds straight forward and will look nice with a special animation to cover up the cutting point.

    The laser animation would need to be long enough to cover up the longest possible distance between the player ship and a target, that would be the length of one of the diagonals of the screen rectangle.

    Thanks for the help but i still quite did not understand what he thought.. maybe is my english.. im fom Brazil...

  • I can put together an example later today if you don't mind waiting.

  • I can put together an example later today if you don't mind waiting.

    Thank you sooo mutch...

  • https://www.dropbox.com/s/mtuitc8dsr6i0 ... .capx?dl=0

    Rough draft.

    You can improve it by making a more solid core on the explosion sprite to hide the cut. You can also do a gradient on the masking sprite so that cut off edge is softened.

    Also I used mouse distance from the end of the laser to set the width of the mask, you probably want a different method depending on your application.

  • Thanks a bunch

  • oosyrag an example capx will be great to see

  • oosyrag an example capx will be great to see

    ............

    dropbox.com/s/mtuitc8dsr6i03r/laseranimation.capx

    Rough draft.

    You can improve it by making a more solid core on the explosion sprite to hide the cut. You can also do a gradient on the masking sprite so that cut off edge is softened.

    Also I used mouse distance from the end of the laser to set the width of the mask, you probably want a different method depending on your application.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)