# How do I create a beam of light

Get help using Construct 2

### » Fri Apr 14, 2017 4:25 pm

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.
B
32
S
12
G
2
Posts: 142
Reputation: 3,557

### » Fri Apr 14, 2017 6:54 pm

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.
B
21
S
10
G
5
Posts: 33
Reputation: 4,224

### » Fri Apr 14, 2017 9:06 pm

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
B
21
S
10
G
5
Posts: 33
Reputation: 4,224

### » Sat Apr 15, 2017 4:32 am

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.
B
17
S
6
G
2
Posts: 41
Reputation: 2,257

### » Mon Apr 17, 2017 7:36 pm

I still didnt get it.
Here is the image that i will be using as lazer..
B
32
S
12
G
2
Posts: 142
Reputation: 3,557

### » Tue Apr 18, 2017 4:11 am

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.
B
17
S
6
G
2
Posts: 41
Reputation: 2,257

### » Tue Apr 18, 2017 4:45 am

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.
Mistakes were made.
B
60
S
30
G
132
Posts: 1,931
Reputation: 74,339

### » Tue Apr 18, 2017 2:55 pm

@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.
Scirra Employee
B
10
S
5
G
2
Posts: 132
Reputation: 2,356

### » Tue Apr 18, 2017 7:02 pm

DiegoM wrote:@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...
B
32
S
12
G
2
Posts: 142
Reputation: 3,557

### » Tue Apr 18, 2017 7:16 pm

I can put together an example later today if you don't mind waiting.
Mistakes were made.
B
60
S
30
G
132
Posts: 1,931
Reputation: 74,339

Next

Return to How do I....?

### Who is online

Users browsing this forum: No registered users and 2 guests