Laser using Shape Painter and sprite as laser

I was checking out the Zombie Laser game example, and hope to implement something similar into the game I’m working on. In the example, the laser is generated from the player using raycasting and the Shape Painter to draw the line. However, in the Shape Painter object parameters, it seems you can only choose the color of the line, the color of its outline, and the opacity.

If you have a laser sprite you want to use (maybe a repeating image which will scale) but implement it similar to how it was done in Zombie Laser, how would you do this? I was hoping to use a multi-colored sprite as the laser object rather than being restricted to a fill color and outline color. Thanks in advance.

Awhile back I create an example of a growing tongue. The grow part might be helpful. I used a panel sprite so it repeated the texture instead of stretching it. I hope it helps.

1 Like

Sorry i 1st read your title then i pasted screenshots
AND AFTER that i actually did read your issue
My solution is only for getting shape painter when lmb is clicked

No problem. I was just wondering how you can use a repeating sprite image as the “laser” rather than just being limited to the fill color and outline color of the Shape Painter, while still having the effect of the Shape Painter drawing the straight line.

Are you familiar with the object masking extension? You can use a shape painter for the mask.

try me: this draws a line from the center to the cursor exposing a tiles sprite that’s the size of the scene.
I added a toggle that rotates the texture towards the cursor.

The code is simple, at start mask the target object. I used 4 objects, a tiled sprite and shape painter. I unchecked the shape painter’s “clear after each frame” and “draw the shapes relative” I added the text label and a toggle object

I would limit the drawing and clearing to only when necessary , the shape painter isn’t the most efficient way. That’s why I recommended the tongue approach. For limited things, it seems to be fine.

I don’t know if there is any difference to having a full screen tiled sprite to keeping it the size of your laser. You can rotate the tiled sprite to match the direction. You could also change any of the tiled sprite’s settings like tint or effects or move either the tiled object or the object’s tile offset.

Note: to rotate the texture it needs to be square and the line should start from the center. Otherwise, it won’t stay in alignment.


1 Like

Sorry for the late reply to this, as I simply forgot. I decided to put this mechanic of the game off for now while I take care of other things that need done before I implement it. When that time comes, I’ll definitely be referencing your information on the Object Masking extension. Thanks again!

1 Like