Animation in a Canvas (Real Studio network user group Mailinglist archive)

Back to the thread list
Previous thread: [ANN] REALbasic 4.0.2 Now Available
Next thread: Stickies...


Stickies...   -   Brandon McWhirter
  Animation in a Canvas   -   Pepe
   Re: Animation in a Canvas   -   Joseph J. Strout
    Re: Animation in a Canvas   -   Pepe
     Re: Animation in a Canvas   -   Kevin Windham
     Re: Animation in a Canvas   -   Joseph J. Strout
      Re: Animation in a Canvas   -   Pepe
      vCards (important for me)   -   Pepe

Animation in a Canvas
Date: 19.03.02 19:05 (Tue, 19 Mar 2002 19:05:38 +0100)
From: Pepe
Sorry, but I still don't get it:

I got some pictures in my project. Now I want to get an animation from
pic1 to picX. This is no problem with a SpriteSurface and a Timer.
Joe wrote that it would be a lot easier using a Canvas. Now I really
need to use a Canvas, and I tried to figure out how to do this. Even
though Joe gave me a little example, it doesn't work.
I can't believe it - it works with a SS, but it seems to me that I'm not
able to create a simple animation using a Canvas.
So, if anyone would help me...

Thank you,

Yours,
Pepe

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: Animation in a Canvas
Date: 19.03.02 19:09 (Tue, 19 Mar 2002 12:09:12 -0600)
From: Joseph J. Strout
At 7:05 PM +0100 3/19/02, Pepe wrote:

>Joe wrote that it would be a lot easier using a Canvas. Now I really
>need to use a Canvas, and I tried to figure out how to do this. Even
>though Joe gave me a little example, it doesn't work.

What doesn't work about it? Please post the actual code you're
using, and describe in detail what happens, or fails to happen that
you expected to happen. You'll get more help faster if you're
specific in your questions.

Best,
- Joe

Re: Animation in a Canvas
Date: 19.03.02 21:24 (Tue, 19 Mar 2002 21:24:07 +0100)
From: Pepe
> What doesn't work about it? Please post the actual code you're using,
> and describe in detail what happens, or fails to happen that you
> expected to happen. You'll get more help faster if you're specific in
> your questions.
>
> Best,
> - Joe

Ok, thanks for your suggestions, Joe.

My problem is this:
I learned how to use a SS for an animation, and I was very confused
because I didn't get it to "port" the code to a canvas. That means: I
thought if I could make an animation with a SS, I could easily do this
with a Canvas. Problem in detail: I don't know how to "load" pictures (I
put into my project) into the canvas.
If I load them as CICN-Resources (made with ResEdit), this code works
just fine (it's in a timer);

Dim rf as ResourceFork
Dim p as Picture
Dim i as integer

rf=GetFolderItem("Resources").OpenResourceFork
p=rf.getcicn(i)
rf.close
canvas1.graphics.drawpicture p,0,0
i=i+1

But this is just for testing. Now I want to do the same animation with
the pictures available in my project already (no ResEdit-file, but
single PICTs). But I don't know how, because I don't know how to tell
the Canvas where the pictures are. Using a SS, I would do this in the
OpenEvent:

dim pics(10) as picture
dim picsprite as sprite
dim PicFrame as integer
Pics(0) = picture1
Pics(1) = picture2
.
.

PicSprite = me.NewSprite(Pics(0), 0, 0)
PicSprite.image = Pics(PicFrame)
me.Update

A timer would do the rest.

As you can see, I assume that I know what I've to put into the timer,
but I don't know how to "load(?)" the pictures into a Canvas.

I'm so sorry, but I can't give you more details, as I don't know where
the problem exactly is. I searched my harddisk, the internet, RS-FTP
sites and the RB-CD for examples and didn't find a single one.

Hope you can help me.

Thanks,
Regards,
Pepe

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: Animation in a Canvas
Date: 19.03.02 21:58 (Tue, 19 Mar 2002 14:58:52 -0600)
From: Kevin Windham
If I understand your problem correctly then the answer is pretty
straightforward.

Since the picture has been dragged into RealBasic, you can refer to it
by name. So this code...

> Dim rf as ResourceFork
> Dim p as Picture
> Dim i as integer
>
> rf=GetFolderItem("Resources").OpenResourceFork
> p=rf.getcicn(i)
> rf.close
> canvas1.graphics.drawpicture p,0,0
> i=i+1

would become

Dim i as integer

canvas1.graphics.drawpicture MyDraggedInPicture,0,0
i=i+1

where MyDraggedInPicture is the name of the picture as shown in the
project window.

Hope that helps,
Kevin

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: Animation in a Canvas
Date: 20.03.02 00:28 (Tue, 19 Mar 2002 17:28:47 -0600)
From: Joseph J. Strout
At 9:24 PM +0100 3/19/02, Pepe wrote:

>I learned how to use a SS for an animation, and I was very confused
>because I didn't get it to "port" the code to a canvas. That means:
>I thought if I could make an animation with a SS, I could easily do
>this with a Canvas. Problem in detail: I don't know how to "load"
>pictures (I put into my project) into the canvas.

That's because a canvas doesn't have any place to store pictures.
But your window does, if you declare such a place.

>If I load them as CICN-Resources (made with ResEdit), this code
>works just fine (it's in a timer);
>
> Dim rf as ResourceFork
> Dim p as Picture
> Dim i as integer
>
> rf=GetFolderItem("Resources").OpenResourceFork
> p=rf.getcicn(i)
> rf.close
> canvas1.graphics.drawpicture p,0,0
> i=i+1

Hmm, I don't understand how this code would work. You've declared
"i" as a local variable. So it's going to have a value of 0 every
time the timer fires, and you'll be drawing cicn 0 every time.

>But this is just for testing. Now I want to do the same animation
>with the pictures available in my project already (no ResEdit-file,
>but single PICTs). But I don't know how, because I don't know how to
>tell the Canvas where the pictures are. Using a SS, I would do this
>in the OpenEvent:
>
> dim pics(10) as picture
> dim picsprite as sprite
> dim PicFrame as integer
> Pics(0) = picture1
> Pics(1) = picture2

Good, do this very same thing, but don't declare pics(10) as a local
variable. Make it a Property of the window instead (use the New
Property) command.

Then add another property, mFrame as Integer. And in your timer, do:

mFrame = (mFrame + 1) mod 10
canvas1.graphics.DrawPicture mPics(mFrame), 0,0

Cheers,
- Joe

P.S. If you don't know how to create and access properties, I highly
recommend going through the tutorial -- it doesn't take very long and
you'll learn a lot.

Re: Animation in a Canvas
Date: 20.03.02 11:37 (Wed, 20 Mar 2002 11:37:32 +0100)
From: Pepe
>>
>> Dim rf as ResourceFork
>> Dim p as Picture
>> Dim i as integer

> Hmm, I don't understand how this code would work. You've declared "i"
> as a local variable. So it's going to have a value of 0 every time the
> timer fires, and you'll be drawing cicn 0 every time.

Sorry, I just didn't care about that when I wrote the code into my
e-mail client. Of course I declared it as a property.

> mFrame = (mFrame + 1) mod 10
> canvas1.graphics.DrawPicture mPics(mFrame), 0,0
>
> Cheers,
> - Joe
>
> P.S. If you don't know how to create and access properties, I highly
> recommend going through the tutorial -- it doesn't take very long and
> you'll learn a lot.

Thanks, now it works, Joe!

Yes, I know how to create properties, I just didn't know how to get
around this canvas problem...

Greetings,
Pepe

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>