Variable sprite speed

Anything related to Hollywood Designer goes in here
Post Reply
User avatar
r-tea
Posts: 133
Joined: Tue Feb 16, 2016 11:48 pm
Location: Zdzieszowice, Poland
Contact:

Variable sprite speed

Post by r-tea »

Hi!
I did my first try with Sprites and drawing.
It's a randomly moved circle.
There are two things that surprised me.
1. sprite often changes its speed significantly. The speed is constantly set to 1.
2. sprite's paths are not straight lines
Twice: why?

Code: Select all

@VERSION 2,0

@DISPLAY {Width = 640, Height = 480}
@SAMPLE 10, "Bells.wave"

/*
** Make the sprites. We create two sprites from each form: One for the
** background and one that is displayed below the mouse pointer.
*/
Function p_CreateSprites()
        ; Circle
		SetFillStyle(#FILLCOLOR)
        CreateBrush(10, 12, 12)
        SelectBrush(10)
        Circle(0, 0, 6, #WHITE)
        EndSelect
        SetBrushTransparency(10, #BLACK)
        CreateSprite(1, #BRUSH, 10)
EndFunction



p_CreateSprites()

x1=0
y1=0
DisplaySprite(1, x1, y1)

Function p_MoveRnd()
	x=Rnd(634)
	y=Rnd(474)
	Circle(x,y,3,#RED)
	MoveSprite(1, x1, y1, x, y, {Speed=1})
	PlaySample(10)
	Circle(x,y,3,#BLACK)
	x1=x
	y1=y
EndFunction

EscapeQuit(True)
SetInterval(1, p_MoveRnd, 40)

;
; main loop!
;
Repeat
        WaitEvent
Forever
User avatar
airsoftsoftwair
Posts: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Variable sprite speed

Post by airsoftsoftwair »

Don't use MoveSprite(). To move a sprite to a new position just call DisplaySprite() with the new position. MoveSprite() is a very old function of very limited practical use. And yes, the name is misleading but it got its name somewhen in 2001 or so ;-)
User avatar
r-tea
Posts: 133
Joined: Tue Feb 16, 2016 11:48 pm
Location: Zdzieszowice, Poland
Contact:

Re: Variable sprite speed

Post by r-tea »

Ok, but DisplaySprite() just blanks the sprite on the old position, and display it instantly again in a new position, without displaying all the indirect positions. If MoveSprite() is not recomended then what alterative is there?
SamuraiCrow
Posts: 475
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

Re: Variable sprite speed

Post by SamuraiCrow »

Use the law of cosines to find the direction of the difference of the coordinates and then convert the vector back to rectangular coordinates using sine and cosine. Just watch out for horizontal and vertical cases because they can result in an invalid angle so just do them manually using sign comparisons.
I'm on registered MorphOS using FlowStudio.
User avatar
r-tea
Posts: 133
Joined: Tue Feb 16, 2016 11:48 pm
Location: Zdzieszowice, Poland
Contact:

Re: Variable sprite speed

Post by r-tea »

@SamuraiCrow
But it doesn't resolve the problem of speed.

EDIT:
Oh, you might have in mind DisplaySprite() to take evaluated coords. Am I right?
I was thinking you're refering to MoveSprite() at first.
SamuraiCrow
Posts: 475
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

Re: Variable sprite speed

Post by SamuraiCrow »

r-tea wrote: Mon Jun 25, 2018 5:39 pm @SamuraiCrow
But it doesn't resolve the problem of speed.

EDIT:
Oh, you might have in mind DisplaySprite() to take evaluated coords. Am I right?
I was thinking you're refering to MoveSprite() at first.
DisplaySprite() is what I'm referring to. The speed is 1 by default when using trigonometric unit vectors. If you want it to be a different speed, multiply the unit vectors by the speed while they are still in polar notation.
I'm on registered MorphOS using FlowStudio.
User avatar
airsoftsoftwair
Posts: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Variable sprite speed

Post by airsoftsoftwair »

By the way, if you non-perfect vsync'ed refresh by "variable speed", then you have to use a plugin like GL Galore or RebelSDL which uses hardware double buffering. Hollywood's default display driver is software-based and thus doesn't offer perfect vsyncing which can lead to a few glitches when moving sprites. If you need perfect vsync'ing, you need to use GL Galore or RebelSDL because those two offer hardware double buffering. Then the speed will be completely smooth.
User avatar
r-tea
Posts: 133
Joined: Tue Feb 16, 2016 11:48 pm
Location: Zdzieszowice, Poland
Contact:

Re: Variable sprite speed

Post by r-tea »

SamuraiCrow wrote: Mon Jun 25, 2018 10:39 pm DisplaySprite() is what I'm referring to. The speed is 1 by default when using trigonometric unit vectors. If you want it to be a different speed, multiply the unit vectors by the speed while they are still in polar notation.
As Hollywood's documentation stands DisplaySprite() doesn't have a speed argument.
SamuraiCrow
Posts: 475
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

Re: Variable sprite speed

Post by SamuraiCrow »

I am telling you how to do the math to make it yourself. It takes some basic trigonometry.
I'm on registered MorphOS using FlowStudio.
User avatar
Clyde
Posts: 348
Joined: Sun Feb 14, 2010 12:38 pm
Location: Dresden / Germany

Re: Variable sprite speed

Post by Clyde »

I would be interested in some kind of small tutorial or some explanations, if you still want to. Thanks!
Currently using: Hollywood 9 with Windows IDE and Hollywood 9 with Visual Studio Code and hw4vsc
Post Reply