Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Using a mask and the new sprite skew commands to make a shadow — Gideros Forum

Using a mask and the new sprite skew commands to make a shadow

SinisterSoftSinisterSoft Maintainer
edited October 2016 in Code snippets
I sometimes create a mask of a sprite to have pixel perfect collision detection and to allow a sprite to flash a particular colour if hit by a bullet - like old arcade games used to flash a sprite white.

This mask can now also be used to make a nice shadow effect by using new sprite 'skew' commands available in the next version of Gideros (2016.10 ?)...
	p.shadow=Bitmap.new(c.mask)
	p.shadow:setAnchorPosition(0.5,0.5)
	p.shadow:setSkewX(-40)
	p.shadow:setX(30)
	p.shadow:setScaleY(1.4)
	p.shadow:setY(-14)
	p.shadow:setColorTransform(0,0,0)
	p.shadow:setAlpha(0.5)
The code first makes the anchor point to the middle of the sprite (like the main sprite). It then sets the x skew so that it leans to the right, the x is adjusted so that shadow and the feet line up. I increase the Y scale as shadows are usually quite tall and adjust the Y so the shadow and feet line up again. My mask is white, but shadows are usually black - so I adjust the colour transform (multipliers) to get rid of any colour. Shadows are also usually transparent so the alpha is adjusted to make this happen.

Likes: antix, n1cke

Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
https://deluxepixel.com
+1 -1 (+2 / -0 )Share on Facebook

Comments

  • antixantix Member
    edited October 2016
    That's pretty cool. I think I'm still on 2016.6 :D

    You're using the pixel class for your radar at the top left right? That's a very handy class the Pixel class. You can even use it for a laser beam which just shows how flexible it really is.

    Likes: SinisterSoft

    +1 -1 (+1 / -0 )Share on Facebook
  • SinisterSoftSinisterSoft Maintainer
    edited October 2016
    No, I'm using the path2d for the lines - using the same shape for the pitch but with the coordinate array changed by a multiplier. I use a particles sprite for all of the players on the radar - so they get drawn at once. I may make it so the particles have an alpha decay - then add 22 particles per frame with the players current positions - so they 'sweep' around with a decay trail.

    I was going to use a different viewport and just redraw everything there - but the pitch lines and players were actually too small when it scaled. They look better thicker than real life.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • n1cken1cke Maintainer
    > how flexible it really is
    @antix: [spoiler] in upcoming release Pixel will become most flexible and useful class in Gideros ;)
    +1 -1 (+4 / -0 )Share on Facebook
  • So much for not building up expectations. :D

    Likes: SinisterSoft

    My Gideros games: www.totebo.com
    +1 -1 (+1 / -0 )Share on Facebook
  • antixantix Member
    edited October 2016
    @SinisterSoft, I meant using pixels for the actual radar dots. Particles though eh? Might have to look at those :)

    Since the radar will never change is a path more efficient than just plopping a bitmap there instead?
  • It would be, but it's currently a proto with hardly any sprites - also I know that path2d looks great on any native resolution. :)

    Likes: antix

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.