Animation: A Moment of Panic

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Animation: A Moment of Panic

Post by richmond62 » Sat May 21, 2022 8:48 pm

I got "all hot and sweaty" today when I came across something called sprite masking, which has to
do with the way sprite images pass each other:

https://www.reddit.com/r/Unity3D/commen ... on_top_of/

When I realised that LiveCode is so fantastic that there is no need to even consider that:
-
Sfight.jpg
-
https://www.dropbox.com/s/a7skk4wyujf8j ... e.zip?dl=0
-
Use the 'A', 'D', 'J' and 'L' keys to move the 2 monsters. 8)
Last edited by richmond62 on Sun May 22, 2022 7:18 pm, edited 1 time in total.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Animation: A Moment of Panic

Post by richmond62 » Sun May 22, 2022 8:13 am

This is certainly a worthwhile port-of-call (especially if you cannot draw anything semi-decent like me):

https://craftpix.net/categorys/sprites/
-
Free-Minotaur-Tiny-Style-Sprites-720x480.jpeg

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Animation: A Moment of Panic

Post by richmond62 » Sun May 22, 2022 8:21 am

The reason I panicked was threefold:

1. I had never heard of sprite masks before.
-
SShot 2022-05-22 at 10.15.03.png
-
2. I had forgotten I was not programming for the BBC Micro. :roll:

3. I had forgotten about LAYERS in LiveCode.

Code: Select all

on rawKeyDown RD
   switch RD
      case 97
         set the layer of grc "mRIGHT" to top
         put item 1 of the loc of grc "mRIGHT" into RLR
         put item 2 of the loc of grc "mRIGHT" into RUD
         subtract 20 from RLR
         move grc "mRIGHT" to RLR,RUD
         add 1 to fld "RR"
         if fld "RR" > 17 then
            put 0 into fld "RR"
         end if
         put fld "RR" into RX
         set the backGroundPattern of grc "mRIGHT" to the ID of img ("Minotaur_01_Walking_" & RX & ".png")
         break
      case 100
         set the layer of grc "mRIGHT" to top
         put item 1 of the loc of grc "mRIGHT" into RLR
         put item 2 of the loc of grc "mRIGHT" into RUD
         add 20 to RLR
         move grc "mRIGHT" to RLR,RUD
         add 1 to fld "RR"
         if fld "RR" > 17 then
            put 0 into fld "RR"
         end if
         put fld "RR" into RX
         set the backGroundPattern of grc "mRIGHT" to the ID of img ("Minotaur_01_Walking_" & RX & ".png")
         break
      case 106
         set the layer of grc "mLEFT" to top
         put item 1 of the loc of grc "mLEFT" into LLR
         put item 2 of the loc of grc "mLEFT" into LUD
         subtract 20 from LLR
         move grc "mLEFT" to LLR,LUD
         add 1 to fld "LL"
         if fld "LL" > 17 then
            put 0 into fld "LL"
         end if
         put fld "LL" into LX
         set the backGroundPattern of grc "mLEFT" to the ID of img ("Minotaur_03_Walking_" & LX & ".png")
         break
      case 108
         set the layer of grc "mLEFT" to top
         put item 1 of the loc of grc "mLEFT" into LLR
         put item 2 of the loc of grc "mLEFT" into LUD
         add 20 to LLR
         move grc "mLEFT" to LLR,LUD
         add 1 to fld "LL"
         if fld "LL" > 17 then
            put 0 into fld "LL"
         end if
         put fld "LL" into LX
         set the backGroundPattern of grc "mLEFT" to the ID of img ("Minotaur_03_Walking_" & LX & ".png")
         break
   end switch
end rawKeyDown
-
SShot 2022-05-22 at 10.19.02.png
-
I really ought to get out more: but the chains cramp my style. :shock:

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Animation: A Moment of Panic

Post by richmond62 » Sun May 22, 2022 12:17 pm

Oo-er:

https://docs.unity3d.com/Manual/class-SpriteMask.html

All very complicated indeed when, in LiveCode all one needs are a bunch of PNG or GIF images.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Animation: A Moment of Panic

Post by richmond62 » Sun May 22, 2022 12:25 pm

UNITY:
-
SpriteMask3.png
SpriteMask3.png (27.38 KiB) Viewed 3902 times
-
LiveCode:
-
Screen Shot 2022-05-22 at 2.24.04 PM.jpg

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Animation: A Moment of Panic

Post by Klaus » Sun May 22, 2022 1:02 pm

Richmond,

some time ago you admitted that I had finally been able to convince you to use "mouseup" instead of "mousedown".
Maybe I can also convince you to use "set the loc of xy to x,y"*** instead of "move xyz to x,y", what you ALWAYS use? 8)

That will make everything much more "snappier"!
Try it here in your "Sprite Fight" example.

***Of course only where you do not need an animation-like "move".

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Animation: A Moment of Panic

Post by richmond62 » Sun May 22, 2022 1:20 pm

This thread IS about animation, and that tends to involve movement.

In my stack, the RESET button uses . . set the loc. 8)

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Animation: A Moment of Panic

Post by Klaus » Sun May 22, 2022 1:30 pm

You know what I mean!

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Animation: A Moment of Panic

Post by richmond62 » Sun May 22, 2022 7:07 pm

Bloody Hell, mandatory attendance at an enormous piss-up for one my ex-pupils because she has finished high school (sit on your arse and you'll fall out the top oneday), no obvious method of escape.

Back with a vengeance (that means you, Klaus), and a thumping headache tomorrow . . . 8)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Animation: A Moment of Panic

Post by richmond62 » Sun May 22, 2022 7:26 pm

Wait a moment . . . why not just rack
the moveSpeed up well high?

Mind you, if the flaming DJ could turn the volume down
to about 20% round these parts . . .

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Animation: A Moment of Panic

Post by richmond62 » Mon May 23, 2022 9:15 am

SF2.jpg
-
The ONLY significant difference between this stack and the previous one is that it employs
on rawkeyUp instead of rawKeyDown.

https://www.dropbox.com/s/ch9nnqcerx9n7 ... e.zip?dl=0

What that does entail is that each movement is discrete, while in the first stack, by keeping one of
the control keys down the move signal was sent repeatedly.

Generally, when teaching children how to make goofy games I suggest they use rawKeyUp rather than rawKeyDown
just so there is not the 'horrible' problem of backGroundPattern animation happening in graphic rectangles AFTER movement of those graphic rectangles has taken place.
Last edited by richmond62 on Mon May 23, 2022 9:26 am, edited 2 times in total.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Animation: A Moment of Panic

Post by richmond62 » Mon May 23, 2022 9:23 am

Klaus, I understand your criticism of using move rather than set to be because,
using move in a rawKeyDown script means that, on keeping a key down,
movement proceeds in jerks, while, by using set that will not happen.

HOWEVER, and it is a 'HOWEVER' that has to be considered:

This stack was NOT conceived of as a way of reproducing Tom-&-Jerry like smooth animation, it was
conceived of as:

1. An illustration how, by using

set the layer of something to top

one did not have to get 'all hot and sweaty' about sprite masking in LiveCode.

2. How this might be implemented in a side-scrolling game.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Animation: A Moment of Panic

Post by richmond62 » Mon May 23, 2022 1:28 pm

FLIP.png
Attachments
FLIP SPRITE.livecode.zip
Stack.
(41.62 KiB) Downloaded 74 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Animation: A Moment of Panic

Post by richmond62 » Mon May 23, 2022 2:00 pm

Twist.png
Attachments
TWIST and SHOUT.livecode.zip
Stack.
(43.53 KiB) Downloaded 71 times

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Animation: A Moment of Panic

Post by FourthWorld » Mon May 23, 2022 6:20 pm

Historical tidbit: sprite masking was implemented as a built-in engine feature for SuperCard 2.0 circa 1995 under the feature name of "filmstrips".
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”