CCScene 对于使用cocos2d的童鞋肯定很熟悉,那么在使用 [[CCDirectorsharedDirector]replaceScene:<#(CCScene *)scene#>]; 对scene进行场景(CCLayout)进行切换时,cocos2d提供了一些特效进行过渡,那么今天仔细翻开cocos2d源码,将所有的动画效果都测试了一遍,大概整理如下,提供大家查阅和使用吧;
因为我使用的是最新的cocos2d的1.0版本,所以一些函数方法跟之前不一样了,所以不要感到奇怪;
由于代码都有备注,所以就直接上代码了,就不详细单独解释了;关于注释的都是我的直观体验,推荐大家放到自己项目中,自己都看看每个的效果,这样记忆深刻;//触摸事件 - 当手指从屏幕抬起时调用的方法-Himi
-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CCScene* scenec = [OtherLayout scene];
//部落格------
//CCTransitionTurnOffTiles *transitionScene = [CCTransitionTurnOffTiles transitionWithDuration:3 scene:scenec];
//近远-远近-----
//CCTransitionShrinkGrow *transitionScene = [CCTransitionShrinkGrow transitionWithDuration:3 scene:scenec];
//另一个layout左侧进入(视觉感觉是屏幕右移)
//CCTransitionSlideInL *transitionScene = [CCTransitionSlideInL transitionWithDuration:3 scene:scenec];
//另一个layout右侧进入(视觉感觉是屏幕左移)
//CCTransitionSlideInR *transitionScene = [CCTransitionSlideInR transitionWithDuration:3 scene:scenec];
//另一个layout上侧进入(视觉感觉是屏幕下移)
//CCTransitionSlideInT *transitionScene = [CCTransitionSlideInT transitionWithDuration:3 scene:scenec];
//另一个layout下侧进入(视觉感觉是屏幕上移)
//CCTransitionSlideInB *transitionScene = [CCTransitionSlideInB transitionWithDuration:3 scene:scenec];
//当前屏幕被分为3列,两则下移,中间上移
//CCTransitionSplitCols *transitionScene = [CCTransitionSplitCols transitionWithDuration:3 scene:scenec];
//当前屏幕被分为3列,两则左移,中间右移
//CCTransitionSplitRows *transitionScene = [CCTransitionSplitRows transitionWithDuration:3 scene:scenec];
//扇形转换-----
//CCTransitionRadialCW *transitionScene = [CCTransitionRadialCW transitionWithDuration:3 scene:scenec];
//平面旋转-----
//CCTransitionRotoZoom *transitionScene = [CCTransitionRotoZoom transitionWithDuration:3 scene:scenec];
//近-远-跳动------
//CCTransitionJumpZoom *transitionScene = [CCTransitionJumpZoom transitionWithDuration:3 scene:scenec];
//立体反转(X轴)--(还有种从近到远,从远到近的感觉)--------
//CCTransitionZoomFlipX *transitionScene = [CCTransitionZoomFlipX transitionWithDuration:3 scene:scenec];
//立体反转(Y轴)-(还有种从近到远,从远到近的感觉)-------
//CCTransitionZoomFlipY *transitionScene = [CCTransitionZoomFlipY transitionWithDuration:3 scene:scenec];
//立体反转(X,Y轴)---(还有种从近到远,从远到近的感觉)-----
//CCTransitionZoomFlipAngular *transitionScene = [CCTransitionZoomFlipAngular transitionWithDuration:3 scene:scenec];
//另外一个layout左侧进入覆盖当前layout
//CCTransitionMoveInL *transitionScene = [CCTransitionMoveInL transitionWithDuration:3 scene:scenec];
//另外一个layout右侧进入覆盖当前layout
//CCTransitionMoveInR *transitionScene = [CCTransitionMoveInR transitionWithDuration:3 scene:scenec];
//另外一个layout上侧进入覆盖当前layout
//CCTransitionMoveInT *transitionScene = [CCTransitionMoveInT transitionWithDuration:3 scene:scenec];
//另外一个layout下侧进入覆盖当前layout
//CCTransitionMoveInB *transitionScene = [CCTransitionMoveInB transitionWithDuration:3 scene:scenec];
//立体反转(X轴)--2D平面反转,没有远近感
//CCTransitionFlipX *transitionScene = [CCTransitionFlipX transitionWithDuration:3 scene:scenec];
//立体反转(Y轴)--2D平面反转,没有远近感
//CCTransitionFlipY *transitionScene = [CCTransitionFlipY transitionWithDuration:3 scene:scenec];
//立体反转(X,Y轴)--2D平面反转,没有远近感
//CCTransitionFlipAngular *transitionScene = [CCTransitionFlipAngular transitionWithDuration:3 scene:scenec];
//实体-透明-实体(默认无颜色,可以附带颜色)
//CCTransitionFade* transitionScene = [CCTransitionFade transitionWithDuration:3 scene:scenec withColor:ccWHITE];
//另外一个直接渐变覆盖当前layout
//CCTransitionCrossFade *transitionScene = [CCTransitionCrossFade transitionWithDuration:3 scene:scenec];
//移动(方格状)部落格,从左下往右上
//CCTransitionFadeTR *transitionScene = [CCTransitionFadeTR transitionWithDuration:3 scene:scenec];
//移动(方格状)部落格,从右上往左下
CCTransitionFadeBL *transitionScene = [CCTransitionFadeBL transitionWithDuration:3 scene:scenec];
//移动(长矩形,宽度是屏幕宽)部落格,从下往上
//CCTransitionFadeUp *transitionScene = [CCTransitionFadeUp transitionWithDuration:3 scene:scenec];
//移动(长矩形,宽度是屏幕宽)部落格,从上往下
//CCTransitionFadeDown *transitionScene = [CCTransitionFadeDown transitionWithDuration:3 scene:scenec];
[[CCDirector sharedDirector] replaceScene: transitionScene];
}
以上代码Himi推荐大家自己常识运行每种特效,毕竟每个人都有不同的感觉,注释都是我的感觉写的,大概注释了一下而已;
下面我来给大家介绍如何在cocos2d 1.0版本中设置竖屏显示,因为默认是横屏;
首先找到RootViewController.m 类(此类在1.0版本存在),然后找到宏定义的一段代码,代码如下:
#elif GAME_AUTOROTATION == kGameAutorotationUIViewController
然后下面能看到cocos2d的默认代码是设置横屏:
return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) );
如果想设置竖屏,请更改如下即可:
return (UIInterfaceOrientationIsPortrait(interfaceOrientation));
ok,今天就先介绍这里~继续学习~下面给出一张,部落格效果,从左下往右上的切换特效截图;zoomin.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator">
<scale android:fromXScale="2.0" android:toXScale="1.0"
android:fromYScale="2.0" android:toYScale="1.0"
android:pivotX="50%p" android:pivotY="50%p"
android:duration="@android:integer/config_mediumAnimTime" />
</set>
zoomout.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
android:zAdjustment="top">
<scale android:fromXScale="1.0" android:toXScale=".5"
android:fromYScale="1.0" android:toYScale=".5"
android:pivotX="50%p" android:pivotY="50%p"
android:duration="@android:integer/config_mediumAnimTime" />
<alpha android:fromAlpha="1.0" android:toAlpha="0"
android:duration="@android:integer/config_mediumAnimTime"/>
</set>
Java
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
startActivityForResult(intent, 11);
//添加界面切换效果,注意只有Android的2.0(SdkVersion版本号为5)以后的版本才支持
int version = Integer.valueOf(android.os.Build.VERSION.SDK);
if(version >= 5) {
overridePendingTransition(R.anim.zoomin, R.anim.zoomout); //此为自定义的动画效果,下面两个为系统的动画效果
//overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
//overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
}
所谓的手机锁屏就是启动一个Service
锁屏后的屏幕:
[img]
[/img]
package com.amaker.lockscreen; import android.app.Service; import android.content.Context; import android.content.Intent; import android.os.IBinder; import android.view.LayoutInflater; import android.view.View; import android.view.WindowManager; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class RemoteLockScreenService extends Service { EditText et; WindowManager wm; View v; @Override public IBinder onBind(Intent intent) { return null; } boolean check(){ String password = et.getText().toString(); //这里先暂时把密码写成静态, if(password.equals("7758520")){ return true; }else{ return false; } } @Override public void onCreate() { super.onCreate(); Context context = getApplicationContext(); wm = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); LayoutInflater inflater = LayoutInflater.from(context); v = inflater.inflate(R.layout.lock_screen, null); Button btn = (Button)v.findViewById(R.id.button1); et = (EditText)v.findViewById(R.id.editText1); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if(check()){ stopSelf(); } } }); WindowManager.LayoutParams params = new WindowManager.LayoutParams(); params.width=-1; params.height=-1; params.flags = 1280; params.type = 2002; wm.addView(v, params); } @Override public void onDestroy() { super.onDestroy(); if(wm!=null&&v!=null){ wm.removeView(v); } } }
切记:在AndroidManifest里一定要加入这个权限:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>