Playing an image sequence in reverse

View: New views
9 Messages — Rating Filter:   Alert me  

Playing an image sequence in reverse

by jfcwilson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,
 
I'm trying to run a JPEG image sequence in reverse order, but am running into problems:
 
Code:
 
cubic { "dummy1024.png", "dummy.png","dummy.png", "dummy.png", "dummy.png", "dummy.png" }
 
local anim = patch {face=1, x = 0, y = 0, image = "patches/anim_100.jpg" }
local animpos = 100
 
hotspotmap "hotspotmap.png"
 
hotspot {
onmousedown = function()
pipmak.schedule(
0.04,
function()
animpos = math.mod(animpos - 1, 101)
anim:setimage ("patches/anim_" .. animpos .. ".jpg")
return 0.04
end
)
end
}
 
This playes it backward, but once it gets to frame "anim_0.jpg", it goes on to output continusly "Cannot find file "anim_-1.jpg" Cannot find file  "anim_-2.jpg", and so on.
How do I make it loop?
 
Thanks,
    James


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Pipmak-Users mailing list
Pipmak-Users@...
news://news.gmane.org/gmane.games.devel.pipmak.user
https://lists.sourceforge.net/lists/listinfo/pipmak-users

Re: Playing an image sequence in reverse

by Urs Holzer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi

> I'm trying to run a JPEG image sequence in reverse order, but am
> running into problems:
>
> Code:
> [...]
> animpos = math.mod(animpos - 1, 101)
> [...]

I guess this line is the problem. According to the Lua 5.0 reference,
math.mod just uses the mod operator from ANSI C. If I remember
correctly, ANSI C does define the result of it on a negative number as
implementation specific, so, depending on the plattform the software
runs on, math.mod(-1, 101) could be -1 or 100.

By replacing the above line with
if animpos < 0 then animpos = 100 end
should give what you want.

However, because of laziness, I have not tested it!

Greetings
Urs



------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Pipmak-Users mailing list
Pipmak-Users@...
news://news.gmane.org/gmane.games.devel.pipmak.user
https://lists.sourceforge.net/lists/listinfo/pipmak-users

Re: Playing an image sequence in reverse

by jfcwilson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks!
However, I still got the same output when I used this, Pipmak tried to find "an_anim_-1" and so on.
 
Here's my new code:
 
CODE*****************************************************************
 
cubic { "dummy1024.png", "dummy.png","dummy.png", "dummy.png", "dummy.png", "dummy.png"  }

local an_linkingBook = patch {face=1, x = 0, y = 0, image = "an_linkingBook/an_linkingBook_0.jpg" }
local animpos = 100

hotspotmap "hotspotmap.png"

hotspot {
  onmousedown = function()
    if animpos == 0 then
      animpos = 100
    else
      pipmak.schedule(
   0.04,
   function()
           animpos = math.mod(animpos - 1, 100)
    an_linkingBook:setimage ("an_linkingBook/an_linkingBook_"  .. animpos .. ".jpg")
                                return 0.04
                        end
                )
      end
  end
}
CODE*****************************************************************
 
Does anyone see the problem? I sure can't.
 
Thanks,
  James
--- On Sun, 9/27/09, Urs Holzer <urs@...> wrote:

From: Urs Holzer <urs@...>
Subject: Re: Playing an image sequence in reverse
To: pipmak-users@...
Date: Sunday, September 27, 2009, 5:59 AM

Hi

> I'm trying to run a JPEG image sequence in reverse order, but am
> running into problems:
>
> Code:
> [...]
> animpos = math.mod(animpos - 1, 101)
> [...]

I guess this line is the problem. According to the Lua 5.0 reference,
math.mod just uses the mod operator from ANSI C. If I remember
correctly, ANSI C does define the result of it on a negative number as
implementation specific, so, depending on the plattform the software
runs on, math.mod(-1, 101) could be -1 or 100.

By replacing the above line with
if animpos < 0 then animpos = 100 end
should give what you want.

However, because of laziness, I have not tested it!

Greetings
Urs



------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Pipmak-Users mailing list
Pipmak-Users@...
news://news.gmane.org/gmane.games.devel.pipmak.user
https://lists.sourceforge.net/lists/listinfo/pipmak-users


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Pipmak-Users mailing list
Pipmak-Users@...
news://news.gmane.org/gmane.games.devel.pipmak.user
https://lists.sourceforge.net/lists/listinfo/pipmak-users

Re: Playing an image sequence in reverse

by Urs Holzer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

James Wilson wrote:
> However, I still got the same output when I used this, Pipmak tried to
> find "an_anim_-1" and so on.


pipmak.schedule runs the function you give it as an argument after the given
time. So, what is run again and again is only the function() below, not the
whole code of onmousedown of the hotspot. So the if..then I gave you in my
previous post has to be placed in the function() below:

> pipmak.schedule(
> 0.04,
> function()
> animpos = math.mod(animpos - 1, 100)
> an_linkingBook:setimage ("an_linkingBook/an_linkingBook_"  .. animpos ..
> ".jpg") return 0.04
> end
> )

Just change this to

pipmak.schedule(
0.04,
function()
  if animpos < 0 then animpos = 100 end
  an_linkingBook:setimage ("an_linkingBook/an_linkingBook_"  ..    
  animpos ..".jpg")
  return 0.04
end
)

or similar. Now it loops automatically. I hope this is what you want. Then
you also don't need the if..then..else in the onmousedown function.

Greetings
Urs


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Pipmak-Users mailing list
Pipmak-Users@...
news://news.gmane.org/gmane.games.devel.pipmak.user
https://lists.sourceforge.net/lists/listinfo/pipmak-users

Re: Playing an image sequence in reverse

by jfcwilson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks, I think this last little problem is my fault:
I click on the hotspot and nothing happens. I think it's because I closed "hotspot" incorrectly. What do you think? Sorry to drag this out.
 
CODE************************
 
hotspot {
  onmousedown = function()
    pipmak.schedule(
    0.04,
     function()
      if animpos < 0 then animpos = 100 end
       an_linkingBook:setimage ("an_linkingBook/an_linkingBook_"  ..  animpos ..".jpg")
       return 0.04
       end
      )
  end
}
END CODE********************
 
Thanks,
  James
--- On Wed, 9/30/09, Urs Holzer <urs@...> wrote:

From: Urs Holzer <urs@...>
Subject: Re: Playing an image sequence in reverse
To: pipmak-users@...
Date: Wednesday, September 30, 2009, 9:33 AM

James Wilson wrote:
> However, I still got the same output when I used this, Pipmak tried to
> find "an_anim_-1" and so on.


pipmak.schedule runs the function you give it as an argument after the given
time. So, what is run again and again is only the function() below, not the
whole code of onmousedown of the hotspot. So the if..then I gave you in my
previous post has to be placed in the function() below:

> pipmak.schedule(
> 0.04,
> function()
> animpos = math.mod(animpos - 1, 100)
> an_linkingBook:setimage ("an_linkingBook/an_linkingBook_"  .. animpos ..
> ".jpg") return 0.04
> end
> )

Just change this to

pipmak.schedule(
0.04,
function()
  if animpos < 0 then animpos = 100 end
  an_linkingBook:setimage ("an_linkingBook/an_linkingBook_"  ..   
  animpos ..".jpg")
  return 0.04
end
)

or similar. Now it loops automatically. I hope this is what you want. Then
you also don't need the if..then..else in the onmousedown function.

Greetings
Urs


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Pipmak-Users mailing list
Pipmak-Users@...
news://news.gmane.org/gmane.games.devel.pipmak.user
https://lists.sourceforge.net/lists/listinfo/pipmak-users


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Pipmak-Users mailing list
Pipmak-Users@...
news://news.gmane.org/gmane.games.devel.pipmak.user
https://lists.sourceforge.net/lists/listinfo/pipmak-users

Re: Playing an image sequence in reverse

by Urs Holzer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

James Wilson wrote:
> Thanks, I think this last little problem is my fault:
> I click on the hotspot and nothing happens. I think it's because I closed
> "hotspot" incorrectly. What do you think? Sorry to drag this out.

Sorry, this is my fault. The line
if animpos < 0 then animpos = 100 end
only makes sure that animpos gets back to 100 once it reaches -1. I forgot
to insert a line that actually decreases animpos by 1. So this should work
now:

hotspot {
  onmousedown = function()
  pipmak.schedule(
    0.04,
    function()
      animpos = animpos - 1
      if animpos < 0 then animpos = 100 end
      an_linkingBook:setimage ("an_linkingBook/an_linkingBook_"  ..  animpos
..".jpg")
      return 0.04
    end
  )
end
}



------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Pipmak-Users mailing list
Pipmak-Users@...
news://news.gmane.org/gmane.games.devel.pipmak.user
https://lists.sourceforge.net/lists/listinfo/pipmak-users

Re: Playing an image sequence in reverse

by jfcwilson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks! That worked perfectly. Thanks also for being patient with me.
 
Thanks again,
   James

--- On Thu, 10/1/09, Urs Holzer <urs@...> wrote:

From: Urs Holzer <urs@...>
Subject: Re: Playing an image sequence in reverse
To: pipmak-users@...
Date: Thursday, October 1, 2009, 6:47 AM

James Wilson wrote:
> Thanks, I think this last little problem is my fault:
> I click on the hotspot and nothing happens. I think it's because I closed
> "hotspot" incorrectly. What do you think? Sorry to drag this out.

Sorry, this is my fault. The line
if animpos < 0 then animpos = 100 end
only makes sure that animpos gets back to 100 once it reaches -1. I forgot
to insert a line that actually decreases animpos by 1. So this should work
now:

hotspot {
  onmousedown = function()
  pipmak.schedule(
    0.04,
    function()
      animpos = animpos - 1
      if animpos < 0 then animpos = 100 end
      an_linkingBook:setimage ("an_linkingBook/an_linkingBook_"  ..  animpos
..".jpg")
      return 0.04
    end
  )
end
}



------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Pipmak-Users mailing list
Pipmak-Users@...
news://news.gmane.org/gmane.games.devel.pipmak.user
https://lists.sourceforge.net/lists/listinfo/pipmak-users

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Pipmak-Users mailing list
Pipmak-Users@...
news://news.gmane.org/gmane.games.devel.pipmak.user
https://lists.sourceforge.net/lists/listinfo/pipmak-users

Re: Playing an image sequence in reverse

by Urs Holzer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

James Wilson wrote:
> Thanks! That worked perfectly. Thanks also for being patient with me.

Good.

By the way, if you activate the animation like that, then you have to
make sure that it is not activated twice. Try clicking multiple times at
the image to see what happens. If my guess is correct, the sequence will
run twice as fast (if your computer can keep up with the pace) after you
click on it the second time.
In other words: You have to make sure that the animation can not be
activated again while it is already running.

However, if I remember correctly, the animation in linking books in Myst
starts immediately after opening the book. In other words, the animation
is activated automatically and not by the user. If the same is true for
your linking books, you don't have the problem I described above.

And anyway, don't hesitate to ask more questions. We are happy to answer
them.

Greetings
Urs



------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Pipmak-Users mailing list
Pipmak-Users@...
news://news.gmane.org/gmane.games.devel.pipmak.user
https://lists.sourceforge.net/lists/listinfo/pipmak-users

Parent Message unknown Re: Playing an image sequence in reverse

by jfcwilson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yes, this was only a test for general animation. The actual applied use is to make it loop, even when the ending and beginning do not match. E.g., I'd start the animation going forward, then backwards, and so on. Handy for things you don't have much control over when animating. So I just slapped together a test project, using renders form another project I'm involved in, Ages of Ilathid.
 
Thanks again,
  James

--- On Fri, 10/2/09, Urs Holzer <urs@...> wrote:

From: Urs Holzer <urs@...>
Subject: Re: Playing an image sequence in reverse
To: pipmak-users@...
Date: Friday, October 2, 2009, 1:58 PM

James Wilson wrote:
> Thanks! That worked perfectly. Thanks also for being patient with me.

Good.

By the way, if you activate the animation like that, then you have to
make sure that it is not activated twice. Try clicking multiple times at
the image to see what happens. If my guess is correct, the sequence will
run twice as fast (if your computer can keep up with the pace) after you
click on it the second time.
In other words: You have to make sure that the animation can not be
activated again while it is already running.

However, if I remember correctly, the animation in linking books in Myst
starts immediately after opening the book. In other words, the animation
is activated automatically and not by the user. If the same is true for
your linking books, you don't have the problem I described above.

And anyway, don't hesitate to ask more questions. We are happy to answer
them.

Greetings
Urs



------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Pipmak-Users mailing list
Pipmak-Users@...
news://news.gmane.org/gmane.games.devel.pipmak.user
https://lists.sourceforge.net/lists/listinfo/pipmak-users


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Pipmak-Users mailing list
Pipmak-Users@...
news://news.gmane.org/gmane.games.devel.pipmak.user
https://lists.sourceforge.net/lists/listinfo/pipmak-users