Showing different images when moving?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: Showing different images when moving?
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. 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).
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. 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).
Re: Showing different images when moving?
Hi bogs,
This is exactly what I was going for! Thanks
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
This is exactly what I was going for! Thanks
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
Re: Showing different images when moving?
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
Perhaps locking the screen & messages until the count > 5, and then unlocking everything would work. I leave it to you to explore the possibilities
Re: Showing different images when moving?
Just use lock screen and unlock screen, tested and works: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.
...
########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: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: Showing different images when moving?
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.
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.
-
- VIP Livecode Opensource Backer
- Posts: 7216
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Showing different images when moving?
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.For lock screen, I've only ever had goofy results with that in the past, so I rarely use it,
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
HyperActive Software | http://www.hyperactivesw.com
Re: Showing different images when moving?
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 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.
All that aside, as I said earlier, it may well be a good idea for qqchrono's project.
-
- VIP Livecode Opensource Backer
- Posts: 7216
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Showing different images when moving?
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:
Now change the handler to use lockscreen:
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.
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
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
Edit: added timing in milliseconds. Watch the message box.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Showing different images when moving?
I actually owe Jacque an apology, my faulty memory was thinking about lock moves, not lock screen
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.
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.
Re: Showing different images when moving?
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
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 332 times
Re: Showing different images when moving?
Slightly changed stack is attached.
Jim Lambert
Jim Lambert
- Attachments
-
- arrow.livecode.zip
- improved
- (4.31 KiB) Downloaded 330 times
Re: Showing different images when moving?
That is indeed a nice simple way to do it.
-
- VIP Livecode Opensource Backer
- Posts: 7216
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Showing different images when moving?
Very nice, and preferable to the other solutions.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Showing different images when moving?
... ... ... ...
Re: Showing different images when moving?
Thanks.
Here's a version that shows the same technique but using a group of animated GIFs.
In msg box:
(Too large to attach here.)
Jim Lambert
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"
Jim Lambert