MovieClip: Difference between revisions

From GiderosMobile
No edit summary
mNo edit summary
 
(34 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
'''Supported platforms:''' android, ios, mac, pc<br/>
<!-- GIDEROSOBJ:MovieClip -->
{{PLATFORMS_ALL}}
'''Available since:''' Gideros 2011.6<br/>
'''Available since:''' Gideros 2011.6<br/>
'''Inherits from:''' [[Sprite]]<br/>
=== Description ===
=== Description ===
<br />
The MovieClip class inherits from the following classes: [[Sprite]] > [[EventDispatcher]].
The `MovieClip` class inherits from the following classes: `Sprite` > `EventDispatcher`.<br />
 
<br />
The MovieClip class is used to create static timedlined animations. The timeline parameters are given as an array.
The `MovieClip` class is used create static timedlined animations. The timeline parameters are given as an array. <br />
 
Each array element specifies one timeline element and consists of the starting frame, ending frame, sprite and <br />
Each array element specifies one timeline element and consists of: '''the starting frame''' (frame numbers start from 1)''', the ending frame, a sprite and an optional tweening parameters'''.
optional tweening parameters. Frame numbers start from 1.<br />
<br />
When a `MovieClip` object finishes it playing (by reaching its final frame or a frame with stop action), <br />
it dispatches an `Event.COMPLETE` event.<br />
<br />
The following properties can be tweened:<br />
<br />
<ul>
<li>`x`</li>
<li>`y`</li>
<li>`rotation`</li>
<li>`scale`</li>
<li>`scaleX`</li>
<li>`scaleY`</li>
<li>`alpha`</li>
</ul>
<br />


Additionally `MovieClip` uses set function to tween properties, so if you override provided object's set function by adding new parameters it can accept, then you can tween those new parameters too.
When a MovieClip object finishes playing (by reaching its final frame or a frame with stop action), it dispatches an [[Event.COMPLETE]] event.


The following properties can be tweened (those that can be set through [[Sprite:set]]):
*''x''
*''y''
*''z''
*''rotation''
*''rotationX''
*''rotationY''
*''scale''
*''scaleX''
*''scaleY''
*''scaleZ''
*''anchorX''
*''anchorY''
*''anchorZ''
*''alpha''
*''redMultiplier''
*''greenMultiplier''
*''blueMultiplier''
*''skewX''
*''skewY''
Additionally MovieClip uses a function to tween properties. If you override the default tween function then you can tween this parameter too. The following easing functions can be used:
* ''"inBack"''
* ''"outBack"''
* ''"inOutBack"''
* ''"inBounce"''
* ''"outBounce"''
* ''"inOutBounce"''
* ''"inCircular"''
* ''"outCircular"''
* ''"inOutCircular"'
* ''"inCubic"''
* ''"outCubic"''
* ''"inOutCubic"''
* ''"inElastic"''
* ''"outElastic"''
* ''"inOutElastic"''
* ''"inExponential"''
* ''"outExponential"''
* ''"inOutExponential"''
* ''"linear"''
* ''"inQuadratic"''
* ''"outQuadratic"''
* ''"inOutQuadratic"''
* ''"inQuartic"''
* ''"outQuartic"''
* ''"inOutQuartic"''
* ''"inQuintic"''
* ''"outQuintic"''
* ''"inOutQuintic"''
* ''"inSine"''
* ''"outSine"''
* ''"inOutSine"''


<br />
The following easing functions can be used:<br />
<br />
* `"inBack"`<br />
* `"outBack"`<br />
* `"inOutBack"`<br />
* `"inBounce"`<br />
* `"outBounce"`<br />
* `"inOutBounce"`<br />
* `"inCircular"`<br />
* `"outCircular"`<br />
* `"inOutCircular"`<br />
* `"inCubic"`<br />
* `"outCubic"`<br />
* `"inOutCubic"`<br />
* `"inElastic"`<br />
* `"outElastic"`<br />
* `"inOutElastic"`<br />
* `"inExponential"`<br />
* `"outExponential"`<br />
* `"inOutExponential"`<br />
* `"linear"`<br />
* `"inQuadratic"`<br />
* `"outQuadratic"`<br />
* `"inOutQuadratic"`<br />
* `"inQuartic"`<br />
* `"outQuartic"`<br />
* `"inOutQuartic"`<br />
* `"inQuintic"`<br />
* `"outQuintic"`<br />
* `"inOutQuintic"`<br />
* `"inSine"`<br />
* `"outSine"`<br />
* `"inOutSine"`<br />
<br />
Following examples demonstrates the possible uses of MovieClip class.<br />
<br />
=== Examples ===
=== Examples ===
'''Example'''<br/>
<syntaxhighlight lang="lua">
<source lang="lua">-- construct a 100 frame animation where x coordinate of sprite tweens from 0 to 200 linearly<br />
local sprite = Pixel.new(0x0, 1, 32, 32)
local mc = MovieClip.new{<br />
local sprite1 = Pixel.new(0xff0000, 1, 32, 32)
{1, 100, sprite, {x = {0, 200, "linear"}}}<br />
local sprite2 = Pixel.new(0x0000ff, 1, 32, 32)
}<br />
 
<br />
-- construct a 100 frame animation where x coordinate of sprite tweens from 0 to 200 linearly
-- construct a 100 frame animation where x coordinate of sprite is 50 (constant) and <br />
local mc = MovieClip.new{
-- y coordinate of sprite tweens from 50 to 150 by using inBounce function<br />
{1, 100, sprite, {x = {0, 200, "linear"}}},
local mc = MovieClip.new{<br />
}
{1, 100, sprite, {x = 50, y = {50, 150, "inBounce"}}}<br />
--mc:play() -- play only once
}<br />
mc:setGotoAction(100, 1) -- play in a loop
<br />
stage:addChild(mc)
-- construct a 200 frame animation where sprite1 and sprite2 tweens differently<br />
 
-- here sprite1 is visible between frames [1, 150]<br />
-- construct a 100 frame animation where x coordinate of sprite is 50 (constant) and  
-- and sprite2 is visible between frames [100, 200]<br />
-- y coordinate of sprite tweens from 50 to 150 by using inBounce function
local mc = MovieClip.new{<br />
local mc = MovieClip.new{
{1, 100, sprite1, {x = {0, 200, "linear"}}},<br />
{1, 100, sprite, {x = 50, y = {50, 150, "inBounce"}}},
{50, 150, sprite1, {y = {0, 100, "linear"}, alpha = {0, 1, "easeOut"}}},<br />
}
{100, 200, sprite2, {x = {0, 200, "linear"}}},<br />
--mc:play() -- play only once
}<br />
mc:setGotoAction(100, 1) -- play in a loop
<br />
stage:addChild(mc)
-- construct a looping 6 frame animation where each frame is a different sprite<br />
 
local mc = MovieClip.new{<br />
-- construct a 200 frame animation where sprite1 and sprite2 tweens differently
{1, 1, frame1}, <br />
-- here sprite1 is visible between frames [1, 150]
{2, 2, frame2}, <br />
-- and sprite2 is visible between frames [100, 200]
{3, 3, frame3}, <br />
local mc = MovieClip.new{
{4, 4, frame4}, <br />
{1, 100, sprite1, {x = {0, 200, "linear"}}},
{5, 5, frame5}, <br />
{50, 150, sprite1, {y = {0, 100, "linear"}, alpha = {0, 1, "easeOut"}}},
{6, 6, frame6},<br />
{100, 200, sprite2, {x = {0, 200, "linear"}}},
}<br />
}
mc:setGotoAction(6, 1) -- if the animation reaches frame 6 then go to frame 1<br />
--mc:play() -- play only once
<br />
mc:setGotoAction(200, 1) -- play in a loop
-- construct a looping 6 frame animation playing 5 times slower than the previous example<br />
stage:addChild(mc)
local mc = MovieClip.new{<br />
 
{1, 5, frame1}, <br />
-- construct a looping 6 frame animation where each frame is a different sprite
{5, 10, frame2}, <br />
local mc = MovieClip.new{
{11, 15, frame3}, <br />
{1, 1, frame1},
{16, 20, frame4}, <br />
{2, 2, frame2},
{21, 25, frame5}, <br />
{3, 3, frame3},
{26, 30, frame6},<br />
{4, 4, frame4},
}<br />
{5, 5, frame5},
mc:setGotoAction(30, 1) -- if the animation reaches frame 30 then go to frame 1</source>
{6, 6, frame6},
}
mc:setGotoAction(6, 1) -- if the animation reaches frame 6 then go to frame 1
stage:addChild(mc)
-- construct a looping 6 frame animation playing 5 times slower than the previous example
local mc = MovieClip.new{
{1, 5, frame1},
{6, 10, frame2},
{11, 15, frame3},
{16, 20, frame4},
{21, 25, frame5},
{26, 30, frame6},
}
mc:setGotoAction(30, 1) -- if the animation reaches frame 30 then go to frame 1
stage:addChild(mc)
</syntaxhighlight>
 
{|-
{|-
| style="width: 50%;"|
| style="width: 50%; vertical-align:top;"|
 
=== Methods ===
=== Methods ===
[[MovieClip.new]] - creates a new MovieClip object<br/>
[[MovieClip.getTweenFunction]] ''retrieves the specified tween/easing function''<br/><!--GIDEROSMTD:MovieClip.getTweenFunction(name) retrieves the specified tween/easing function-->
[[MovieClip:clearAction]] - clears the action at the specified frame<br/>
[[MovieClip.new]] ''creates a new MovieClip object''<br/><!--GIDEROSMTD:MovieClip.new(timeline) creates a new MovieClip object-->
[[MovieClip:getFrame]] - <br/>
 
[[MovieClip:gotoAndPlay]] - goes to the specified frame and starts playing<br/>
[[MovieClip:clearAction]] ''clears the action at the specified frame''<br/><!--GIDEROSMTD:MovieClip:clearAction(frame) clears the action at the specified frame-->
[[MovieClip:gotoAndStop]] - goes to the specified frame and stops<br/>
[[MovieClip:getFrame]] ''gets the current frame''<br/><!--GIDEROSMTD:MovieClip:getFrame() gets the current frame-->
[[MovieClip:play]] - starts playing the movie clip<br/>
[[MovieClip:gotoAndPlay]] ''goes to the specified frame and starts playing''<br/><!--GIDEROSMTD:MovieClip:gotoAndPlay(frame,reverse) goes to the specified frame and starts playing-->
[[MovieClip:setGotoAction]] - sets a &quot;go to&quot; action to the specified frame<br/>
[[MovieClip:gotoAndStop]] ''goes to the specified frame and stops''<br/><!--GIDEROSMTD:MovieClip:gotoAndStop(frame) goes to the specified frame and stops-->
[[MovieClip:setReverseAction]] - sets a &quot;reverse&quot; action to the specified frame<br/>
[[MovieClip:play]] ''starts playing the movie clip''<br/><!--GIDEROSMTD:MovieClip:play(reverse) starts playing the movie clip-->
[[MovieClip:setStopAction]] - sets a &quot;stop&quot; action to the specified frame<br/>
[[MovieClip:isPlaying]] ''returns whether or not current clip is playing''<br/><!--GIDEROSMTD:MovieClip:isPlaying() returns whether or not current clip is playing-->
[[MovieClip:stop]] - stops playing the movie clip<br/>
[[MovieClip:setGotoAction]] ''sets a "go to" action to the specified frame''<br/><!--GIDEROSMTD:MovieClip:setGotoAction(frame,destframe) sets a "go to" action to the specified frame-->
| style="width: 50%;"|
[[MovieClip:setReverseAction]] ''sets a "reverse" action to the specified frame''<br/><!--GIDEROSMTD:MovieClip:setReverseAction(frame) sets a "reverse" action to the specified frame-->
[[MovieClip:setStopAction]] ''sets a "stop" action to the specified frame''<br/><!--GIDEROSMTD:MovieClip:setStopAction(frame) sets a "stop" action to the specified frame-->
[[MovieClip:stop]] ''stops playing the movie clip''<br/><!--GIDEROSMTD:MovieClip:stop() stops playing the movie clip-->
 
| style="width: 50%; vertical-align:top;"|
=== Events ===
=== Events ===
[[Event.COMPLETE]]<br/>
<!--[[Event.COMPLETE]]<br/>-->
[[MovieClip_Event.COMPLETE]]<br/><!--GIDEROSEVT:Event.COMPLETE movie clip complete event-->
=== Constants ===
=== Constants ===
|}
|}
{{GIDEROS IMPORTANT LINKS}}

Latest revision as of 01:21, 12 August 2026

Supported platforms:
Available since: Gideros 2011.6
Inherits from: Sprite

Description

The MovieClip class inherits from the following classes: Sprite > EventDispatcher.

The MovieClip class is used to create static timedlined animations. The timeline parameters are given as an array.

Each array element specifies one timeline element and consists of: the starting frame (frame numbers start from 1), the ending frame, a sprite and an optional tweening parameters.

When a MovieClip object finishes playing (by reaching its final frame or a frame with stop action), it dispatches an Event.COMPLETE event.

The following properties can be tweened (those that can be set through Sprite:set):

  • x
  • y
  • z
  • rotation
  • rotationX
  • rotationY
  • scale
  • scaleX
  • scaleY
  • scaleZ
  • anchorX
  • anchorY
  • anchorZ
  • alpha
  • redMultiplier
  • greenMultiplier
  • blueMultiplier
  • skewX
  • skewY

Additionally MovieClip uses a function to tween properties. If you override the default tween function then you can tween this parameter too. The following easing functions can be used:

  • "inBack"
  • "outBack"
  • "inOutBack"
  • "inBounce"
  • "outBounce"
  • "inOutBounce"
  • "inCircular"
  • "outCircular"
  • "inOutCircular"'
  • "inCubic"
  • "outCubic"
  • "inOutCubic"
  • "inElastic"
  • "outElastic"
  • "inOutElastic"
  • "inExponential"
  • "outExponential"
  • "inOutExponential"
  • "linear"
  • "inQuadratic"
  • "outQuadratic"
  • "inOutQuadratic"
  • "inQuartic"
  • "outQuartic"
  • "inOutQuartic"
  • "inQuintic"
  • "outQuintic"
  • "inOutQuintic"
  • "inSine"
  • "outSine"
  • "inOutSine"

Examples

local sprite = Pixel.new(0x0, 1, 32, 32)
local sprite1 = Pixel.new(0xff0000, 1, 32, 32)
local sprite2 = Pixel.new(0x0000ff, 1, 32, 32)

-- construct a 100 frame animation where x coordinate of sprite tweens from 0 to 200 linearly
local mc = MovieClip.new{
	{1, 100, sprite, {x = {0, 200, "linear"}}},
}
--mc:play() -- play only once
mc:setGotoAction(100, 1) -- play in a loop
stage:addChild(mc)

-- construct a 100 frame animation where x coordinate of sprite is 50 (constant) and 
-- y coordinate of sprite tweens from 50 to 150 by using inBounce function
local mc = MovieClip.new{
	{1, 100, sprite, {x = 50, y = {50, 150, "inBounce"}}},
}
--mc:play() -- play only once
mc:setGotoAction(100, 1) -- play in a loop
stage:addChild(mc)

-- construct a 200 frame animation where sprite1 and sprite2 tweens differently
-- here sprite1 is visible between frames [1, 150]
-- and sprite2 is visible between frames [100, 200]
local mc = MovieClip.new{
	{1, 100, sprite1, {x = {0, 200, "linear"}}},
	{50, 150, sprite1, {y = {0, 100, "linear"}, alpha = {0, 1, "easeOut"}}},
	{100, 200, sprite2, {x = {0, 200, "linear"}}},
}
--mc:play() -- play only once
mc:setGotoAction(200, 1) -- play in a loop
stage:addChild(mc)

-- construct a looping 6 frame animation where each frame is a different sprite
local mc = MovieClip.new{
	{1, 1, frame1},	
	{2, 2, frame2},	
	{3, 3, frame3},	
	{4, 4, frame4},	
	{5, 5, frame5},	
	{6, 6, frame6},
}
mc:setGotoAction(6, 1)	-- if the animation reaches frame 6 then go to frame 1
stage:addChild(mc)
						
-- construct a looping 6 frame animation playing 5 times slower than the previous example
local mc = MovieClip.new{
	{1, 5, frame1},	
	{6, 10, frame2},	
	{11, 15, frame3},	
	{16, 20, frame4},	
	{21, 25, frame5},	
	{26, 30, frame6},
}
mc:setGotoAction(30, 1)	-- if the animation reaches frame 30 then go to frame 1
stage:addChild(mc)

Methods

MovieClip.getTweenFunction retrieves the specified tween/easing function
MovieClip.new creates a new MovieClip object

MovieClip:clearAction clears the action at the specified frame
MovieClip:getFrame gets the current frame
MovieClip:gotoAndPlay goes to the specified frame and starts playing
MovieClip:gotoAndStop goes to the specified frame and stops
MovieClip:play starts playing the movie clip
MovieClip:isPlaying returns whether or not current clip is playing
MovieClip:setGotoAction sets a "go to" action to the specified frame
MovieClip:setReverseAction sets a "reverse" action to the specified frame
MovieClip:setStopAction sets a "stop" action to the specified frame
MovieClip:stop stops playing the movie clip

Events

MovieClip_Event.COMPLETE

Constants