1. Location: Modifier_example --> Modifier2. class name: Modifier
(1). You can use modifier to make special effects, such as rotation, skew, transparency, amplification, and reduction of Genie. The commonly used modifier is as follows,
<1>. AlphaModifier transparency modifier
<2>. ColorModifier color modifier
<3>. CubicBezierCurveMoveModifier cubic Beiser curve modifier
<4>. DelayModifier delay modifier
<5>. FadeInModifier light-in modifier
<6>. FadeOutModifier fade-out modifier
<7>. JumpModifier jump modifier
<8>. MoveByModifier movement modifier (starting from the current position)
<9>. MoveModifier: move the modifier from one point to another)
<10>. MoveXModifier: Move X modifier
<11>. MoveYModifier move Y modifier
<12>. PathModifier path modifier
<13>. QuadraticBezierCurveMoveModifier secondary besell curve modifier
<14>. RotationAtModifier rotation modifier (the center of rotation needs to be input)
<15>. RotationByModifier rotation modifier (you only need to input the target angle of rotation)
<16>. RotationModifier rotation modifier (from one angle to another)
<17>. ScaleAtModifier zoom modifier (you need to input the zoom center point)
<18>. ScaleModifier scaling modifier (from how many multiples to another multiple)
<19>. SkewModifier skew modifier
<20>. SkewXModifier skew X modifier
<21>. SkewYModifier skew Y modifier
<22>. LoopEntityModifier loop container modifier (so that an action modifier is implemented cyclically)
<23>. SequenceEntityModifier sequence container modifier (so that several action modifiers are implemented in sequence)
<24>. ParallelEntityModifier parallel entity container modifier (so that several action modifiers are implemented simultaneously)
(2) the following example uses modifier:
/** General Modifier usage */
Private void setGeneralModifier (){
// Fill the screen with a blue background
Rectangle rectangle = new Rectangle (0, 0, getWidth (), getHeight (), getVertexBufferObjectManager ());
Rectangle. setColor (0.09804f, 0.6274f, 0.8784f );
This. attachChild (rectangle); // add the scenario
AnimatedSprite face_rect = new AnimatedSprite (gap * 1,150, Regions. FACE_RECTANGLE, getVertexBufferObjectManager ());
This. attachChild (face_rect );
// Change from 0 to 360 degrees in 2 seconds
RotationModifier rotation_mod = new RotationModifier (2, 0,360 );
// Register a Modifier (Modifier) in face_rect
Face_rect.registerEntityModifier (rotation_mod );
}
/** Run the Modifier statement in sequence after security first */
Private void setSequenceEntityModifier (){
AnimatedSprite face_rect = new AnimatedSprite (gap * 2,150, Regions. FACE_RECTANGLE, getVertexBufferObjectManager ());
This. attachChild (face_rect );
// Change from 0 to 360 degrees in 2 seconds
RotationModifier rotation_mod = new RotationModifier (2, 0,360 );
// Within 1 second, it is increased from 1 to 2 times
ScaleModifier scale_mod = new ScaleModifier (1, 1, 2 );
// Customizes two modifiers for sequential execution
SequenceEntityModifier sequence_mod = new SequenceEntityModifier (rotation_mod, scale_mod );
// Register a Modifier (Modifier) in face_rect
Face_rect.registerEntityModifier (sequence_mod );
}
/** Modifier for loop execution */
Private void setLoopEntityModifier (){
AnimatedSprite face_rect = new AnimatedSprite (gap * 3,150, Regions. FACE_RECTANGLE, getVertexBufferObjectManager ());
This. attachChild (face_rect );
// Change from 0 to 360 degrees in 2 seconds
RotationModifier rotation_mod = new RotationModifier (2, 0,360 );
// Within 1 second, it is increased from 1 to 2 times
ScaleModifier scale_mod = new ScaleModifier (1, 1, 2 );
// Latency: 0.5 s
DelayModifier delay_mod = new DelayModifier (0.5f );
// Modifier is executed sequentially.
SequenceEntityModifier sequence_mod = new SequenceEntityModifier (rotation_mod, delay_mod, scale_mod );
// Modifier executes cyclically
LoopEntityModifier loop_mod = new LoopEntityModifier (sequence_mod );
// Register a Modifier (Modifier) in face_rect
Face_rect.registerEntityModifier (loop_mod );
}
/** Add Modifier to the listener */
Private void setModifierListener (){
AnimatedSprite face_rect = new AnimatedSprite (gap * 4,150, Regions. FACE_RECTANGLE, getVertexBufferObjectManager ());
This. attachChild (face_rect );
// Change from 0 to 360 degrees in 2 seconds
RotationModifier rotation_mod = new RotationModifier (2, 0,360 );
// IEntityModifierListener Modifier listener, listener start and end
LoopEntityModifier loop_mod = new LoopEntityModifier (rotation_mod, 5, new IEntityModifierListener (){
@ Override
Public void onModifierStarted (IModifier <IEntity> pModifier, IEntity pItem ){
// PItem = which will be register
System. out. println ("onModifierStarted ");
PItem. setVisible (true );
}
@ Override
Public void onModifierFinished (IModifier <IEntity> pModifier, IEntity pItem ){
// PItem = which will be register
System. out. println ("onModifierFinished ");
PItem. setVisible (false );
}
});
// Register a Modifier (Modifier) in face_rect
Face_rect.registerEntityModifier (loop_mod );
}
/** A parallel Modifier */
Private void setParallelEntityModifier (){
AnimatedSprite face_ball = new AnimatedSprite (gap * 1,300, Regions. FACE_BALL, getVertexBufferObjectManager ());
// Change from 0 degrees to 360 degrees in 1 second
RotationModifier rotation_mod = new RotationModifier (1, 0,360 );
// Within 1 second, it is increased from 1 to 2 times
ScaleModifier scale_mod = new ScaleModifier (1, 1, 2 );
// The Transparency ranges from 1 to 0 in 1 second.
AlphaModifier alpha_mod = new AlphaModifier (1, 1, 0 );
// Parallel Modifier
ParallelEntityModifier parallel_mod = new ParallelEntityModifier (rotation_mod, scale_mod, alpha_mod );
// Cyclically Modifier
LoopEntityModifier loop_mod = new LoopEntityModifier (parallel_mod );
// Register Modifier
Face_ball.registerEntityModifier (loop_mod );
// Add scenario
This. attachChild (face_ball );
}
Private void irregular_EntityModifiers (){
Final AnimatedSprite face1 = new AnimatedSprite (gap * 2,300, Regions. FACE_BALL, this. getVertexBufferObjectManager ());
Face1.setRotationCenter (0, 0); // you can specify the center of rotation in the upper left corner.
Face1.setScaleCenter (0, 0); // you can specify the center to be enlarged in the upper left corner.
Face1.animate (100 );
Final AnimatedSprite face2 = new AnimatedSprite (gap * 3,300, Regions. FACE_RECTANGLE, this. getVertexBufferObjectManager ());
Face2.animate (100 );
Final SequenceEntityModifier entityModifier = new SequenceEntityModifier (
New IEntityModifierListener (){
@ Override
Public void onModifierStarted (final IModifier <IEntity> pModifier, final IEntity pItem ){
System. out. println ("Sequence started .");
}
@ Override
Public void onModifierFinished (final IModifier <IEntity> pEntityModifier, final IEntity pEntity ){
System. out. println ("Sequence finished .");
}
},
// Step 1: 2 seconds X from 1.0 to 0.75, and Y from 1.0 to 2.0
New ScaleModifier (2, 1.0f, 0.75f, 1.0f, 2.0f ),
// Step 2: 2 seconds X from 0.75 to 2.0, and Y from 2.0 to 1.25
New ScaleModifier (2, 0.75f, 2.0f, 2.0f, 1.25f ),
// Step 3: zoom in and rotate
New ParallelEntityModifier (
New ScaleModifier (3, 2.0f, 5.0f, 1.25f, 5.0f), // 3 seconds X from 2.0 to 5.0, Y from 1.25 to 5.0
New RotationByModifier (3,180) // rotate to 180 degrees in 3 seconds
),
// Step 4: zoom out and rotate
New ParallelEntityModifier (
New ScaleModifier (3, 5, 1), // reduce from 5 to 1 in 3 seconds
New RotationModifier (3,180, 0) // rotate from 180 to 0 in 3 seconds
)
);
// Register entityModifier to face1
Face1.registerEntityModifier (entityModifier );
// Copy an entityModifier and register it with face2.
Face2.registerEntityModifier (entityModifier. deepCopy ());
This. attachChild (face1); // add the scenario
This. attachChild (face2); // add the scenario
/* Create some not-modified sprites, that act as fixed references to the modified ones .*/
/* Add two Genie without any action as a reference */
Final AnimatedSprite face1Reference = new AnimatedSprite (face1.getX (), face1.getY (), face1.getTiledTextureRegion (), this. getVertexBufferObjectManager ());
Final AnimatedSprite face2Reference = new AnimatedSprite (face2.getX (), face2.getY (), face2.getTiledTextureRegion (), this. getVertexBufferObjectManager ());
This. attachChild (face1Reference );
This. attachChild (face2Reference );
}
OGE_Example project source code
[V2.x OGE-example Chapter 2 (section 2) modifier usage]