Showing different images when moving?

Creating Games? Developing something for fun?

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

bogs
Posts: 1611
Joined: Sat Feb 25, 2017 10:45 pm

Re: Showing different images when moving?

Post by bogs » Wed Nov 01, 2017 10:56 pm

I finally freed up some time and wrote this demo to show you one way to do this. I don't think this is the only way, or even a very good way, but it does work as I understand what your looking to do.

There is no error checking in it, all the code is in the card, it only moves left/right/stop, and it was only tested briefly (less than 5 mins). Hopefully it helps you out somewhat.
button_mover_Post.livecode.zip
(7.86 KiB) Downloaded 20 times
What Jacque wrote is pure 'gold of the pen', but I did not include it in the demo (it would be faster and easier, not to mention smoother though).
ImageImage

qqchrono
Posts: 13
Joined: Tue Oct 24, 2017 3:27 am

Re: Showing different images when moving?

Post by qqchrono » Fri Nov 03, 2017 4:02 am

Hi bogs,

This is exactly what I was going for! Thanks :D
I'll definitely get back to improving this game when i am given the time to.
This would really help me out greatly.
Once again, thanks to everyone who replied!



Cheers,
Chrono

bogs
Posts: 1611
Joined: Sat Feb 25, 2017 10:45 pm

Re: Showing different images when moving?

Post by bogs » Fri Nov 03, 2017 4:43 am

My pleasure, but I hope you find a better way of handing the start of the move sequence, as it sets, there is a slight delay in getting started that would become very irritating I am sure :)

Perhaps locking the screen & messages until the count > 5, and then unlocking everything would work. I leave it to you to explore the possibilities :D
ImageImage

MaxV
Posts: 1467
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Showing different images when moving?

Post by MaxV » Fri Nov 03, 2017 10:37 am

qqchrono wrote:
Thu Oct 26, 2017 3:19 am
...
As of now what happens is both the Idle animation and Directional sprites flicker back and forth when any of the arrow keys are held down to move. Any help on how I would be able to keep the idle animation hidden while any arrow keys are pressed and make Idle animation visible and directional sprites hidden when the arrow key is released would be greatly appreciated.
...
Just use lock screen and unlock screen, tested and works:

########CODE to copy and paste#######
local lastLocation

on arrowKey x
lock screen
put the loc of graphic "charIdle" into lastLocation

if x = "right" then
// if you pressed the right arrow key, move the mouse right +1
set the visible of image "charRight" to "true"
set the visible of graphic "charIdle" to "false"
set the right of graphic "charIdle" to the right of graphic "charIdle" + 4
set the loc of image "charRight" to lastLocation
end if
if x = "left" then
// if you pressed the left arrow key, move the mouse left -1
set the visible of image "charLeft" to "true"
set the visible of graphic "charIdle" to "false"
set the left of graphic "charIdle" to the left of graphic "charIdle" - 4
set the loc of image "charLeft" to lastLocation
end if
if x = "up" then
set the visible of image "charUp" to "true"
set the visible of graphic "charIdle" to "false"
set the top of graphic "charIdle" to the top of graphic "charIdle" - 4
set the loc of image "charUp" to lastLocation
end if
if x = "down" then
set the visible of image "charDown" to "true"
set the visible of graphic "charIdle" to "false"
set the bottom of graphic "charIdle" to the bottom of graphic "charIdle" + 4
set the loc of image "charDown" to lastLocation
end if
unlock screen
end arrowKey

on rawKeyUp
set the visible of graphic "charIdle" to "true"
set the visible of image "charRight" to "false"
set the visible of image "charUp" to "false"
set the visible of image "charLeft" to "false"
set the visible of image "charDown" to "false"
end rawKeyUp
#####END OF CODE generated by http://tinyurl.com/j8xf3xq with livecode 9.0.0-dp-6#####
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

bogs
Posts: 1611
Joined: Sat Feb 25, 2017 10:45 pm

Re: Showing different images when moving?

Post by bogs » Fri Nov 03, 2017 2:32 pm

Heya Max :)

That is pretty close to the code he started with here, the problem wound up being that if you held down the arrow key long enough, you'd get a 'flicker' of the idle image in there at times. I still saw that flicker of idle while running your example, although greatly reduced, and it was getting rid of that 'flicker' that produced what I posted using a count till empty loop instead of the raw key states.

Like I said at posting it, it is not the ideal way, only a workable one.

Also, he is currently running the icon of a button, per the beginning of the discussion, not just graphics and images (small enough difference, I know). For lock screen, I've only ever had goofy results with that in the past, so I rarely use it, however I also am using archaic versions of Lc, so it may well be a good idea for qqchrono's project, and probably if you were moving a lot of objects maybe lockMessages too.
ImageImage

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4257
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Showing different images when moving?

Post by jacque » Fri Nov 03, 2017 9:52 pm

For lock screen, I've only ever had goofy results with that in the past, so I rarely use it,
You should. :) Locking the screen speeds up redraws by a large magnitude. It's recommended in all sorts of situations. You do have to watch out for nested locks, they work in doubles. But even if you don't lock/unlock in pairs, the engine will unlock automatically at the next idle period.

The only issue I've had recently with locking the screen is if a nested lock pair uses a visual effect inside a pair that doesn't. There's a bug in there somewhere.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bogs
Posts: 1611
Joined: Sat Feb 25, 2017 10:45 pm

Re: Showing different images when moving?

Post by bogs » Sat Nov 04, 2017 12:53 am

Heh, Jacque if you saw what I saw when I was testing out lock screen, well, lets just say I wasn't sure I was even using it correctly, since I saw no difference at all. I do know it is recommended, and have read that plenty of times in plenty of places, and I am sure it must work for probably everyone else :P but I didn't see the magic.

All that aside, as I said earlier, it may well be a good idea for qqchrono's project.
ImageImage

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4257
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Showing different images when moving?

Post by jacque » Sat Nov 04, 2017 5:25 am

Try this as a lockscreen test. This isn't the best way to alter text in a field but it is a good demonstration of the value of lockscreen.

Create a field and put a couple hundred lines of text in it. Make a button with this script:

Code: Select all

on mouseUp
  put the milliseconds into t
  repeat with x = 1 to the number of lines in fld 1
    set the textstyle of word 1 of line x of fld 1 to "bold"
    set the textstyle of word -1 of line x of fld 1 to "italic"
  end repeat
  put the milliseconds - t
end mouseUp
Now change the handler to use lockscreen:

Code: Select all

on mouseUp
  put the milliseconds into t
  lock screen
  repeat with x = 1 to the number of lines in fld 1
    set the textstyle of word 1 of line x of fld 1 to "bold"
    set the textstyle of word -1 of line x of fld 1 to "italic"
  end repeat
  unlock screen
  put the milliseconds - t
end mouseUp
The more text in the field, the more dramatic the difference. The same thing applies when changing the location of more than one object on screen if you want the changes to appear simultaneously. There are many other situations where lockscreen is faster or, sometimes, the only way to accomplish something -- particular animation effects, for example.

Edit: added timing in milliseconds. Watch the message box.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bogs
Posts: 1611
Joined: Sat Feb 25, 2017 10:45 pm

Re: Showing different images when moving?

Post by bogs » Sat Nov 04, 2017 4:32 pm

I actually owe Jacque an apology, my faulty memory was thinking about lock moves, not lock screen :oops:

Using the same example I used there, I did get a 1 ms faster response on moving the 5 bubbles with lock screen compared to without it.
ImageImage

jiml
Posts: 145
Joined: Sat Dec 09, 2006 1:27 am
Location: Los Angeles

Re: Showing different images when moving?

Post by jiml » Sun Nov 05, 2017 12:20 am

Here's a stack showing yet another way to animate a game character. It does not involve showing or hiding images or swapping icons. Nor does it benefit from lock screen.

This is an old technique from the early days of game development. But it still works!

Jim Lambert
Attachments
arrow.livecode.zip
Animating a character
(4.78 KiB) Downloaded 18 times

jiml
Posts: 145
Joined: Sat Dec 09, 2006 1:27 am
Location: Los Angeles

Re: Showing different images when moving?

Post by jiml » Sun Nov 05, 2017 12:57 am

Slightly changed stack is attached.

Jim Lambert
Attachments
arrow.livecode.zip
improved
(4.31 KiB) Downloaded 23 times

bogs
Posts: 1611
Joined: Sat Feb 25, 2017 10:45 pm

Re: Showing different images when moving?

Post by bogs » Sun Nov 05, 2017 11:20 am

That is indeed a nice simple way to do it.
ImageImage

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4257
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Showing different images when moving?

Post by jacque » Sun Nov 05, 2017 8:27 pm

Very nice, and preferable to the other solutions.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bogs
Posts: 1611
Joined: Sat Feb 25, 2017 10:45 pm

Re: Showing different images when moving?

Post by bogs » Sun Nov 05, 2017 9:00 pm

:shock: ... :o ... :? ... :| ... :(

:wink:
ImageImage

jiml
Posts: 145
Joined: Sat Dec 09, 2006 1:27 am
Location: Los Angeles

Re: Showing different images when moving?

Post by jiml » Sun Nov 05, 2017 9:40 pm

Thanks.

Here's a version that shows the same technique but using a group of animated GIFs.

In msg box:

Code: Select all

go url "http://netrin.on-rev.com/animateimage/roach.livecode"
(Too large to attach here.)

Jim Lambert

Post Reply

Return to “Creating Games”