Citrus Engine Learning note Second play using picture sound material

Source: Internet
Author: User

Start by reviewing the previous entry class, both of which are possible:

public class Main extends Starlingcitrusengine
	{public
		
		function main (): void 
		{
			setupstarling (true);
			
		}
		
		Override Public Function Handlestarlingready (): void {state
			= new Starlinggamestate ();
		}

	}

Or

public class Main extends Starlingcitrusengine
	{public
		
		function main (): void 
		{
			
			
		}
		
		override Public Function Initialize (): void {
			setupstarling (true);
		}
		
		Override public Function Handlestarlingready (): void {state
			= new Starlinggamestate ();
		}

	}

Then is the topic of today's notes, summarizing three ways to use the image footage under the starling framework and how to invoke the sound.


The first type: directly to the address in the bin directory. This method is useful for assigning skins to objects that generally do not change appearance, such as the large background (sky), secondary backgrounds (sun moon trees, etc.), which are very convenient.

I have tried to use jpg,png, and I wonder if I can use GIF animated diagram directly. Here's how to use it:

1, in the project root directory under the Bin folder to deploy the corresponding picture material

2. Assign values under the object's view property, such as:

var coin:coin = new coin ("coin", {x:60, y:100, view: "Levels/soundpatchdemo/jewel.png"});
Note, however, that the path in "" is in the bin file by default, and don't get it wrong. And the size of the image material to match the size of the object, otherwise the visual effect and the physical collision body size is not uniform.


The second type: Use Starling's quad class. About Guad class, you can refer to the Chinese API Starling Chinese Station, very detailed explanation http://www.starlinglib.com/wiki/APIReference.

This way, you can fill a large solid color or gradient, can be used to fill the interface background layout (boundary or blue sky), can also be easily populated platform. Here's how to use it:

A, defined directly in the object view attribute:

Add (New Platform ("P1", {x:700, Y:STAGE.STAGEHEIGHT/4, WIDTH:STAGE.STAGEWIDTH/5, height:40, Oneway:true, View:new 
				Quad (0x333333)});
B. Set the View property after the object is generated:

var floor:platform = new Platform ("floor", 
				{X:STAGE.STAGEWIDTH/2, y:550, height:40, width:stage.stageWidth}); 
  floor.view = new Quad (+,-0x000000, true);
			Add (floor);
C, pre-generate a quad, you can set the color of each vertex to build the gradient effect, and then assign to the object's View property:

			var sky:quad = new Quad (+,-0x777777);
			Sky.setvertexcolor (0, 0x123456);
			Sky.setvertexcolor (1, 0x666666);
			Sky.setvertexcolor (2, 0x337883);
			Sky.setvertexcolor (3, 0x999569);

var floor:platform = new Platform ("floor", 
				{X:STAGE.STAGEWIDTH/2, y:550, height:40, width:stage.stageWidth}); 
  floor.view = Sky; 
			Add (floor);

Third: Embed footage using embed. The advantage of this approach is that you can use the SWF or PNG atlas to call an animation sequence with XML, primarily for characters or other objects that contain animation effects. For detailed usage of the texture class and the Textureatlas class, you can also refer to the API document Http://www.starlinglib.com/wiki/APIReference of the Starling Chinese station. There are several steps:

1. Prepare the Atlas and XML and deploy it in any folder under the project root directory

2. Embed the resource file in front of the scene class (both the Atlas and XML are embedded)

3. Add the embedded resource file to the Textureatlas texture set

4. Set the View property of the desired animation object to the texture set

The code is as follows:

Package {import Citrus.core.starling.StarlingState;
	Import Citrus.objects.platformer.box2d.Hero;
	Import Citrus.objects.platformer.box2d.Platform;
	Import Citrus.physics.box2d.Box2D;
	Import citrus.view.starlingview.AnimationSequence; Import Citrus.view.starlingview.
	Starlingart;
	Import Flash.display.Bitmap;
	Import Starling.display.Quad;
	Import Starling.textures.Texture;
	
	Import Starling.textures.TextureAtlas; /** * *. * @author Roshan */public class Starlinggamestate extends Starlingstate {[Embed (source=]/...
		
		/img/fighter.xml ", mimetype=" Application/octet-stream ")] private var _heroconfig:class; [Embed (source= "/.
		
		/img/fighter.png ")] private var _heropng:class;
			
		Public Function Starlinggamestate () {super ();
			
			} Override Public Function Initialize (): void {super.initialize ();
			var physics:box2d = new box2d ("box2d");
			Physics.visible = true;
			
			Add (physics);
			var sky:quad = new Quad (+,-0x777777); Sky.setvertExcolor (0, 0x123456);
			Sky.setvertexcolor (1, 0x666666);
			Sky.setvertexcolor (2, 0x337883);
			
			Sky.setvertexcolor (3, 0x999569); Add (New Platform ("P1", {x:700, Y:STAGE.STAGEHEIGHT/4, WIDTH:STAGE.STAGEWIDTH/5, height:40, Oneway:true, View:ne
			
			W Quad (0x333333)});
			var floor:platform = new Platform ("floor", {X:STAGE.STAGEWIDTH/2, y:550, height:40, width:stage.stageWidth}); Floor.view = Sky;
			New Quad (+,-0x000000, true);
			
			Add (floor);
			var bitmap:bitmap = new _heropng ();
			var texture:texture = Texture.frombitmap (bitmap);
			var xml:xml = XML (New _heroconfig ());
			
			var stextureatlas:textureatlas = new Textureatlas (texture,xml);
			var Hero:hero = new Hero ("Hero", {x:100, y:300, width:100, height:215, Hurtvelocityx:5, hurtvelocityy:8});
			
			Add (Hero);
			Hero.view = new Animationsequence (Stextureatlas, ["Idle", "Walk", "duck", "Jump", "hurt"], "idle", (+), true);
			
			
		Starlingart.setloopanimations (["Idle"]);}
		
	}

} 

Among them, "/. /img/fighter.xml "is the resource under the IMG folder in the project root directory and is not placed in the bin directory.


			var bitmap:bitmap = new _heropng ();
			var texture:texture = Texture.frombitmap (bitmap);
			var xml:xml = XML (New _heroconfig ());
			var stextureatlas:textureatlas = new Textureatlas (texture,xml);
In these words, textureatlas texture set building requires two parameters, texture texture graph and XML file, so the previous two sentences produce these two things respectively. And the starling mechanism seems to need to create a texture through bitmap, so first construct a bitmap as a container, get the picture before embed.

And the following two sentences used in the two things animationsequence and Starlingart is citrus engine inside the class, usage can refer to the full API introduction http://citrusengine.com/documentation/

Hero.view = new Animationsequence (Stextureatlas, ["Idle", "Walk", "duck", "Jump", "hurt"], "idle", (+), true);
			Starlingart.setloopanimations (["Idle"]);

Examples of materials are almost all used in the Citrus engine official case of the material, you can download the source and material here Https://github.com/alamboley/Citrus-Engine-Examples


Finally, the sound file is called, and the simple steps include:

1. Load the sound file in the main class: Format, Sound.addsound ("Identity name", Voice: "Full path under the project Directory Bin folder");

2, in the scene class through the _ce.sound.playsound ("Identity name"), to invoke

For example:

Main class loading sound files

Override Public Function Initialize (): void {
			setupstarling (true);
			
			Sound.addsound ("beep", {sound: "Sounds/beep1.mp3"});
		

and call it in the scene class.

var coin:coin = new coin ("coin", {x:600, y:400, width:50, height:50});
			Add (coin);
			Coin.onBeginContact.add (function (c:b2contact): void {
				trace (' Coin colledted! ');
				_ce.sound.playsound ("beep");
			});

Oh, after the call, today's notes on the note here first, lol go

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.