예제 #1
0
        // CONSTRUCTOR ----------------------------------------------------------------------------
        public ButtonEntity( string pLabel, Scene pScene, GamePhysics pGamePhysics, TextureInfo pTextureInfo, Vector2i pTileIndex2D )
            : base(pScene, pGamePhysics, pTextureInfo, pTileIndex2D, null)
        {
            halfWidth = Width / 2.0f;
            halfHeight = Height / 2.0f;
            labelOffset = new Vector2(0.1f, 0.25f);
            this.setPivot(0.5f,0.5f);

            font = Crystallography.UI.FontManager.Instance.GetInGame("Bariol", 25);
            map = Crystallography.UI.FontManager.Instance.GetMap( font );
            if ( pLabel != null ) {
                label = new Label( pLabel, map );
                label.Pivot = new Vector2(0.15f, 0.25f );
                label.Scale = new Vector2(1.0f/this.Width,1.0f/this.Height);
            }

            this.getNode().AddChild(label);

            labelOffset = Vector2.Zero;
            status = NORMAL;
            _onToggle = false;
            _pressed = false;
            _initialized = false;

            #if DEBUG
            Console.WriteLine(GetType().ToString() + " created" );
            #endif
        }
예제 #2
0
        public void AddTextureAsset(String path, Object user, Int32 u, Int32 v)
        {
            if (String.IsNullOrWhiteSpace(path))
                throw new ArgumentException();

            if (user == null)
                throw new ArgumentNullException();

            Vector2i tiles = new Vector2i(u, v);

            if (TextureAssetsByUsers.ContainsKey(path))
            {
                if (TextureAssetsByUsers[path].TextureInfo.NumTiles != tiles)
                    throw new ArgumentException("Duplicate texture asset with different tiles: " + path);

                TextureAssetsByUsers[path].AddUser(user);
            }
            else
            {
                Texture2D t = new Texture2D(path, false);
                TextureInfo ti = new TextureInfo(t, tiles);

                TextureAssetsByUsers[path] = new TextureUsers(ti, user);
            }
        }
예제 #3
0
 //        float VertexZ;
 /// <summary>RawSpriteTile constructor.</summary>
 public RawSpriteTile( TRS positioning, Vector2i tile_index, bool flipu=false, bool flipv=false )
 {
     Quad = positioning;
     TileIndex2D = tile_index;
     FlipU = flipu;
     FlipV = flipv;
     //			VertexZ = vertexz;
 }
예제 #4
0
 public BackgroundTile(Int32 column, Int32 row, BackgroundTileData data)
 {
     Column = column;
     Row = row;
     AssetIndexColumn = data.AssetIndexColumn;
     AssetIndexRow = data.AssetIndexRow;
     AssetIndex = new Vector2i(data.AssetIndexColumn, data.AssetIndexRow);
     Passable = data.Passable;
     Friction = data.Friction;
 }
예제 #5
0
 public BackgroundTile(Int32 column, Int32 row, Int32 assetIndexCol, Int32 assetIndexRow, Boolean passable, Single friction)
 {
     Column = column;
     Row = row;
     AssetIndexColumn = assetIndexCol;
     AssetIndexRow = assetIndexRow;
     AssetIndex = new Vector2i(assetIndexCol, assetIndexRow);
     Passable = passable;
     Friction = friction;
 }
		public static void Main (string[] args)
		{
			Director.Initialize();
			Director.Instance.GL.Context.SetClearColor( Colors.Grey20 );
			//Director.Instance.DebugFlags |= DebugFlags.Navigate; 
			
			Vector2 position = new Vector2(300,300);
			Vector2i sprIndex1 = new Vector2i(0,0);
			int step = 0;
			
			var scene = new Scene();
			
			var texture_info = new TextureInfo( new Texture2D("/Application/Dude1.png", false ),
			                                   new Vector2i(2,1));
			
			var sprite = new SpriteTile(texture_info, sprIndex1);
			scene.Camera.SetViewFromViewport();
			sprite.Quad.S = texture_info.TextureSizef; 
			scene.AddChild( sprite );
			
			var sprite2 = new SpriteUV() { TextureInfo = texture_info};
			sprite2.Quad.S = texture_info.TextureSizef; 
			scene.AddChild( sprite2 );
			//sprite2.Position = scene.Camera.CalcBounds().Center;
			sprite2.Position = position;
			
			Director.Instance.RunWithScene( scene );
			Initialize ();
			
			sprite.TileIndex2D = new Vector2i(1,0);
			
			while (true) {
				GamePadData presses = GamePad.GetData(0);
				//step++;
				//if (step == 20)
				if ((presses.Buttons & GamePadButtons.Down) != 0){
					sprite.TileIndex2D.X = 0;
					position.X++;
				}
					//sprIndex1.X = 0;
				//if (step > 40){
				//	step = 0;
				else
					sprite.TileIndex2D.X = 1;
					//sprIndex1.X = 1;
				//}
				
				//sprite.TileIndex2D = sprIndex1;
				
				SystemEvents.CheckEvents ();
				Update ();
				Render ();
			}
		}
예제 #7
0
 /// <summary>Return the CachedTileData (which contains tile UV information) for a given tile.</summary>
 public CachedTileData GetCachedTiledData( ref Vector2i tile_index )
 {
     //			Common.Assert( 0 <= tile_index.X && tile_index.X < NumTiles.X );
     //			Common.Assert( 0 <= tile_index.Y && tile_index.Y < NumTiles.Y );
     return m_tiles_uvs[ tile_index.X + NumTiles.X * tile_index.Y ];
 }
예제 #8
0
        /// <summary></summary>
        public TransitionFadeBase( Scene next_scene )
            : base(next_scene)
        {
            Vector2i size = new Vector2i( Director.Instance.GL.Context.GetViewport().Width,
                                         Director.Instance.GL.Context.GetViewport().Height );

            if ( !m_graphics_resources_init )
            {
                m_previous_scene_render = new TextureInfo( new Texture2D( size.X, size.Y, false, PixelFormat.Rgba, PixelBufferOption.Renderable ) );
                m_next_scene_render = new TextureInfo( new Texture2D( size.X, size.Y, false, PixelFormat.Rgba, PixelBufferOption.Renderable ) );

                m_fbuf1 = new FrameBuffer();
                m_fbuf2 = new FrameBuffer();

                m_fbuf1.SetColorTarget( m_previous_scene_render.Texture, 0 );
                m_fbuf2.SetColorTarget( m_next_scene_render.Texture, 0 );

                m_graphics_resources_init = true;
            }
            else
            {
                Common.Assert( m_previous_scene_render.TextureSizei == size );
                Common.Assert( m_next_scene_render.TextureSizei == size );
            }
        }
예제 #9
0
        internal void AddName(String name, Int32 column, Int32 row)
        {
            if(String.IsNullOrWhiteSpace(name))
                throw new ArgumentNullException();

            if(Names.ContainsKey(name))
                throw new ArgumentException("Duplicate name encountered.");

            Names[name] = new Vector2i(column, row);
        }
예제 #10
0
        /// <summary>
        /// Add a sprite to batch rendering of sprites, must be called between BeginSprites and EndSprites.
        /// </summary>
        /// <param name="quad">The sprite geometry.</param>
        /// <param name="tile_index">Sprite UVs are specified by a tile index.</param>
        /// <param name="mat">A per sprite transform matrix.</param>
        public void AddSprite( ref TRS quad, Vector2i tile_index, ref Matrix3 mat )
        {
            Vector2 posX = quad.X;
            Vector2 posY = quad.Y;

            TextureInfo.CachedTileData uvs = m_current_texture_info.GetCachedTiledData( ref tile_index );

            m_v0 = new Vector4( transform_point( ref mat, quad.T ), uvs.UV_00 );
            m_v1 = new Vector4( transform_point( ref mat, quad.T + posX ), uvs.UV_10 );
            m_v2 = new Vector4( transform_point( ref mat, quad.T + posY ), uvs.UV_01 );
            m_v3 = new Vector4( transform_point( ref mat, quad.T + posX + posY ), uvs.UV_11 );

            add_quad();
        }
예제 #11
0
 /// <summary>Element wise min.</summary>
 public Vector2i Min( Vector2i value )
 {
     return new Vector2i( Common.Min( X, value.X ) ,
                          Common.Min( Y, value.Y ) );
 }
예제 #12
0
        //use new TRS { T=a_T, R=a_S, S=a_S } instead?
        //        public TRS( Vector2 a_T ,
        //                    Vector2 a_R ,
        //                    Vector2 a_S )
        //        {
        //            T = a_T;
        //            R = a_R;
        //            S = a_S;
        //        }
        /// <summary>
        /// Get a subregion from source_area, given a number of tiles and a tile index,
        /// assuming evenly spaced subdivision. Typically source_area will be Quad0_1
        /// (the unit quad, means the whole texture) and we return the uv info for a 
        /// given tile in the tiled texture.
        /// </summary>
        public static TRS Tile( Vector2i num_tiles, Vector2i tile_index, TRS source_area )
        {
            Vector2 num_tiles_f = num_tiles.Vector2();
            Vector2 tile_index_f = tile_index.Vector2();

            Vector2 tile_size = source_area.S / num_tiles_f;

            Vector2 X = source_area.X;
            Vector2 Y = source_area.Y;

            TRS ret = new TRS();

            ret.T = source_area.T + tile_index_f * tile_size;
            ret.R = source_area.R;
            ret.S = tile_size;

            return ret;
        }
예제 #13
0
 /// <summary>
 /// TextureInfo constructor.
 /// Note: TextureInfo takes ownership of the Texture2D passed to this constructor, and disposes of it in Dispose.
 /// </summary>
 /// <param name="texture">The source texture.</param>
 /// <param name="num_tiles">The number of tile subdivisions on x and y.</param>
 /// <param name="source_area">The source rectangle, in UV domain, on which we are going to build the tiles (bottom left is 0,0).</param>
 public TextureInfo( Texture2D texture, Vector2i num_tiles, TRS source_area )
 {
     Initialize( texture, num_tiles, source_area );
 }
예제 #14
0
 /// <summary>
 /// Element wise index clamp.
 /// X is clamped to [0,n.X-1]
 /// Y is clamped to [0,n.Y-1]
 /// <param name="n">The 2d size "this" components must be clamped against. The components of n are assumed to be positive (values of n.X or n.Y negative or zero will result in undefined behaviour).</param>
 /// </summary>
 public Vector2i ClampIndex( Vector2i n )
 {
     return new Vector2i( Common.ClampIndex( X, n.X ) ,
                          Common.ClampIndex( Y, n.Y ) );
 }
예제 #15
0
 public void Register(SpriteBatchType type, Vector2 position, Vector2i tile, bool flip_u)
 {
     Register( type, position, tile, flip_u, Vector2.One);
 }
예제 #16
0
 public void Register(SpriteBatchType type, Vector2 position, Vector2i tile, bool flip_u, Vector2 scale)
 {
     if(SpriteItemLists[(int)type]==null) {
         SpriteItemLists[(int)type] = new List<SpriteItem>();
     }
     var list = SpriteItemLists[(int)type];
     var item = new SpriteItem();
     item.position = position;
     item.tile = tile;
     item.flip_u = flip_u;
     item.scale = scale;
     list.Add(item);
 }
예제 #17
0
 /// <summary>Vector3i constructor.</summary>
 public Vector3i( Vector2i xy, int z )
 {
     X = xy.X;
     Y = xy.Y;
     Z = z;
 }
예제 #18
0
 /// <summary>
 /// Element wise index wrap. 
 /// X wraps around [0,n.X-1]
 /// Y wraps around [0,n.Y-1]
 /// This's (X,Y) is assumed to be a 2d index in a 2d table of size (n.X,n.Y).
 /// If X or Y are not in the valid array range, they are wrapped around [0,n.X-1] and [0,n.Y-1] respectively (-1 becomes n-1, n becomes 0, n+1 becomes 1 etc), else their value is unchanged.
 /// <param name="n">The 2d size "this" components must be wrapped around. The components of n are assumed to be positive (values of n.X or n.Y negative or zero will result in undefined behaviour).</param>
 /// </summary>
 public Vector2i WrapIndex( Vector2i n )
 {
     return new Vector2i( Common.WrapIndex( X, n.X ) ,
                          Common.WrapIndex( Y, n.Y ) );
 }
예제 #19
0
        /// <summary>
        /// The actual init function called by TextureInfo constructors.
        /// </summary>
        /// <param name="texture">The source texture.</param>
        /// <param name="num_tiles">The number of tiles/cells, horitonally and vertically.</param>
        /// <param name="source_area">The source rectangle, in UV domain, on which we are going to build the tiles (bottom left is 0,0).</param>
        public void Initialize( Texture2D texture, Vector2i num_tiles, TRS source_area )
        {
            Texture = texture;
            TileSizeInUV = source_area.S / num_tiles.Vector2();
            NumTiles = num_tiles;
            m_tiles_uvs = new CachedTileData[ num_tiles.Product() ];

            for ( int y=0; y < NumTiles.Y; ++y )
            {
                for ( int x=0; x < NumTiles.X; ++x )
                {
                    Vector2i tile_index = new Vector2i( x, y );
                    TRS tile = TRS.Tile( NumTiles, tile_index, source_area ); // lots of calculation duplicated, but this is an init function

                    int index = tile_index.X + tile_index.Y * NumTiles.X;

                    m_tiles_uvs[ index ] = new CachedTileData()
                    {
                        UV_00 = tile.Point00 ,
                        UV_10 = tile.Point10 ,
                        UV_01 = tile.Point01 ,
                        UV_11 = tile.Point11
                    };
                }
            }
        }
예제 #20
0
 /// <summary>
 /// TextureInfo constructor.
 /// Note: TextureInfo takes ownership of the Texture2D passed to this constructor, and disposes of it in Dispose.
 /// </summary>
 /// <param name="texture">The source texture.</param>
 /// <param name="num_tiles">The number of tile subdivisions on x and y.</param>
 public TextureInfo( Texture2D texture, Vector2i num_tiles )
 {
     Initialize( texture, num_tiles, TRS.Quad0_1 );
 }
예제 #21
0
        // 初期化
        public void Initialize()
        {
            // GameEngine2D 画面クリアー色の設定
            Director.Instance.GL.Context.SetClearColor (Colors.Grey20);

            // 画面解像度情報
            //			ScreenSize = new Vector2i (854, 480);
            ScreenSize = new Vector2i (960, 544);

            // 効果音の設定
            var soundObj = new Sound ("/Application/assets/se.wav");
            Sound = soundObj.CreatePlayer ();

            // BGMの設定
            bgm = new Bgm ("/Application/assets/bgm.mp3");
            player = bgm.CreatePlayer ();
            player.Loop = true; // リピート再生する
            // BGMの再生
            player.Play ();

            // シーン生成(ノードのルートになる)
            var scene = new Sce.PlayStation.HighLevel.GameEngine2D.Scene ();

            // 2Dゲーム向けにカメラを設定
            scene.Camera.SetViewFromViewport ();

            // GameEngine2Dを実行
            Director.Instance.RunWithScene (scene, true);

            Pause = false;

            World = new Node ();
            //	Interface = new Node ();
            // シーンにWorldを追加する
            scene.AddChild (World);
            // シーンにInterface(UIで利用する)を追加する
            //	scene.AddChild (Interface);

            // 背景登録
            for (int y = 0; y < 7; y++) {
                for (int x = 0; x < 6; x++) {
                    var backGround = new BackGround (new Vector2 (x * 192, y * 128));
                    World.AddChild (backGround);
                }
            }

            // 自機(プレイヤー)登録
            Player = new Player (new Vector2 (Game.Instance.ScreenSize.X/2, 100));
            World.AddChild (Player);
            // 敵機(ボス)登録
            Boss = new Boss (new Vector2 (Game.Instance.ScreenSize.X/2, 250));
            World.AddChild (Boss);
            // UI登録
            UI = new UI ();
            //Interface.AddChild (UI);
            scene.AddChild (UI);
            // 当たり判定処理の生成
            HitTest = new HitTest ();
            // 登録キュー
            AddQueue = new List<GameEntity> ();
            // 削除キュー
            RemoveQueue = new List<GameEntity> ();
        }
예제 #22
0
        //初期化 ・・・AppMainから呼ばれる
        public void Initialize()
        {
            flg = false;
            var width = Director.Instance.GL.Context.GetViewport().Width;
            var height = Director.Instance.GL.Context.GetViewport().Height;

            Director.Instance.GL.Context.SetClearColor(Colors.Grey20);
            ScreenSize = new Vector2i(width,height);

            //sceneの作成
            Sce.PlayStation.HighLevel.GameEngine2D.Scene scene = new Sce.PlayStation.HighLevel.GameEngine2D.Scene();
            scene.Camera.SetViewFromViewport();

            //GameEngine2Dの設定・実行
            Director.Instance.RunWithScene(scene,true);

            World = new Node();
            scene.AddChild(World);

            //自弾敵弾はキューで管理
            AddQueue = new List<BulletEntity>();
            RemoveQueue = new List<BulletEntity>();

            HitTest = new HitTest();

            //背景登録
            for (int y = 0; y < 3; y++) {
                for (int x = 0; x < 3; x++) {
                    var backGround = new BackGround (new Vector2 (x * 416f*2.5f, y * 232f * 2.5f),Const.BACKGROUND_PATH,2.5f);
                    World.AddChild (backGround);
                }
            }

            //敵機登録
            Boss = new Boss(new Vector2(Game.Instance.ScreenSize.X-Game.Instance.ScreenSize.X/8,0),Const.BOSS_SHIP_PATH);
            World.AddChild (Boss);

            //自機登録・・・(初期位置,自機画像path)で自機ノードを作成してworldに登録
            Player = new Player(new Vector2(50,Game.Instance.ScreenSize.Y/2),Const.PLAYER_SHIP_PATH);
            World.AddChild(Player);

            HpBar = new hpDialog();
        }
예제 #23
0
 /// <summary>Element wise clamp.</summary>
 public Vector2i Clamp( Vector2i min, Vector2i max )
 {
     return new Vector2i( Common.Clamp( X, min.X, max.X ) ,
                          Common.Clamp( Y, min.Y, max.Y ) );
 }
예제 #24
0
 /// <summary>
 /// SpriteTile constructor.
 /// TileIndex2D is set to (0,0) by default.
 /// </summary>
 /// <param name="texture_info">The tiled texture object.</param>
 /// <param name="index">2D tile index. (0,0) is the bottom left tile.</param>
 public SpriteTile( TextureInfo texture_info, Vector2i index )
     : base(texture_info)
 {
     TileIndex2D = index;
 }
예제 #25
0
 /// <summary>Equality test.</summary>
 public bool Equals( Vector2i v )
 {
     return( X == v.X ) && ( Y == v.Y );
 }
예제 #26
0
        /// <summary>
        /// Create a Texture2D object containing the font data.
        /// It is up to the caller to Dipose of the created texture.
        /// </summary>
        public static Texture2D CreateTexture()
        {
            Texture2D texture;

            // SCEI PSP font

            uint[] SCE_PSP_FONT_DATA = new uint[95 * 2]
            {
                0x00000000, 0x00000000, // ' '
                0x10101010, 0x00100000, // '!'
                0x00282828, 0x00000000, // '"'
                0x287c2828, 0x0028287c, // '#'
                0x38147810, 0x00103c50, // '$'
                0x10204c0c, 0x00606408, // '%'
                0x08141408, 0x00582454, // '&'
                0x00102040, 0x00000000, // '''
                0x10102040, 0x00402010, // '('
                0x10100804, 0x00040810, // ')'
                0x10385410, 0x00105438, // '*'
                0x7c101000, 0x00001010, // '+'
                0x00000000, 0x08101000, // ','
                0x7c000000, 0x00000000, // '-'
                0x00000000, 0x00181800, // '.'
                0x10204000, 0x00000408, // '/'
                0x54644438, 0x0038444c, // '0'
                0x10141810, 0x007c1010, // '1'
                0x20404438, 0x007c0418, // '2'
                0x30404438, 0x00384440, // '3'
                0x24283020, 0x0020207c, // '4'
                0x403c047c, 0x00384440, // '5'
                0x3c040830, 0x00384444, // '6'
                0x1020447c, 0x00101010, // '7'
                0x38444438, 0x00384444, // '8'
                0x78444438, 0x00182040, // '9'
                0x00100000, 0x00001000, // ':'
                0x00100000, 0x08101000, // ';'
                0x0c183060, 0x00603018, // '<'
                0x007c0000, 0x0000007c, // '='
                0x6030180c, 0x000c1830, // '>'
                0x20404438, 0x00100010, // '?'
                0x54744438, 0x00380474, // '@'
                0x44442810, 0x0044447c, // 'A'
                0x3c48483c, 0x003c4848, // 'B'
                0x04044830, 0x00304804, // 'C'
                0x4848281c, 0x001c2848, // 'D'
                0x3c04047c, 0x007c0404, // 'E'
                0x3c04047c, 0x00040404, // 'F'
                0x74044438, 0x00384444, // 'G'
                0x7c444444, 0x00444444, // 'H'
                0x10101038, 0x00381010, // 'I'
                0x20202070, 0x00182420, // 'J'
                0x0c142444, 0x00442414, // 'K'
                0x04040404, 0x007c0404, // 'L'
                0x54546c44, 0x00444444, // 'M'
                0x544c4c44, 0x00446464, // 'N'
                0x44444438, 0x00384444, // 'O'
                0x3c44443c, 0x00040404, // 'P'
                0x44444438, 0x00582454, // 'Q'
                0x3c44443c, 0x00442414, // 'R'
                0x38044438, 0x00384440, // 'S'
                0x1010107c, 0x00101010, // 'T'
                0x44444444, 0x00384444, // 'U'
                0x44444444, 0x00102828, // 'V'
                0x54444444, 0x00446c54, // 'W'
                0x10284444, 0x00444428, // 'X'
                0x38444444, 0x00101010, // 'Y'
                0x1020407c, 0x007c0408, // 'Z'
                0x10101070, 0x00701010, // '['
                0x10080400, 0x00004020, // '\'
                0x1010101c, 0x001c1010, // ']'
                0x00442810, 0x00000000, // '^'
                0x00000000, 0x007c0000, // '_'
                0x00100804, 0x00000000, // '`'
                0x40380000, 0x00784478, // 'a'
                0x4c340404, 0x00344c44, // 'b'
                0x44380000, 0x00384404, // 'c'
                0x64584040, 0x00586444, // 'd'
                0x44380000, 0x0038047c, // 'e'
                0x7c105020, 0x00101010, // 'f'
                0x64580000, 0x38405864, // 'g'
                0x4c340404, 0x00444444, // 'h'
                0x10180010, 0x00381010, // 'i'
                0x10180010, 0x0c121010, // 'j'
                0x14240404, 0x0024140c, // 'k'
                0x10101018, 0x00381010, // 'l'
                0x542c0000, 0x00545454, // 'm'
                0x4c340000, 0x00444444, // 'n'
                0x44380000, 0x00384444, // 'o'
                0x4c340000, 0x0404344c, // 'p'
                0x64580000, 0x40405864, // 'q'
                0x4c340000, 0x00040404, // 'r'
                0x04780000, 0x003c403c, // 's'
                0x083c0808, 0x00304808, // 't'
                0x24240000, 0x00582424, // 'u'
                0x44440000, 0x00102844, // 'v'
                0x54440000, 0x00285454, // 'w'
                0x28440000, 0x00442810, // 'x'
                0x44440000, 0x38405864, // 'y'
                0x207c0000, 0x007c0810, // 'z'
                0x04080830, 0x00300808, // '{'
                0x10101010, 0x00101010, // '|'
                0x2010100c, 0x000c1010, // '}'
                0x0000007c, 0x00000000, // '~'
            };

            Vector2i font_size = new Vector2i (1024, 8);

            byte[] data = new byte[font_size.X * font_size.Y];

            for (int i=0; i < data.Length; ++i)
                data [i] = 0x00;

            for (int c = 0; c != NumChars; ++c)
            {
                for (int y = 0; y != CharSizei.Y; ++y)
                {
                    for (int x = 0; x != CharSizei.X; ++x)
                    {
                        // get the pixel (x,y) for character c:
                        bool white = false;

                        uint a = SCE_PSP_FONT_DATA [c * 2 + 0];
                        uint b = SCE_PSP_FONT_DATA [c * 2 + 1];
                        uint index = (uint)(x + CharSizei.X * y);

                        if (index < (uint)32)
                            white = ((a & (1 << (int)index)) != 0);
                        else
                            white = ((b & (1 << (int)(index - 32))) != 0);

                        Int32 ddd = (c * CharSizei.X + x) + y * font_size.X;
                        data[ddd] = (byte)(white ? 0xff : 0x00);
                    }
                }
            }

            texture = new Texture2D(font_size.X, font_size.Y, false, PixelFormat.Luminance);
            texture.SetPixels (0, data, PixelFormat.Luminance);

            texture.SetFilter (TextureFilterMode.Nearest, TextureFilterMode.Nearest, TextureFilterMode.Nearest);

            return texture;
        }
예제 #27
0
        /// <summary>
        /// Add a sprite to batch rendering of sprites, must be called between BeginSprites and EndSprites.
        /// </summary>
        /// <param name="quad">The sprite geometry.</param>
        /// <param name="tile_index">Sprite UVs are specified by a tile index.</param>
        public void AddSprite( ref TRS quad, Vector2i tile_index )
        {
            Vector2 posX = quad.X;
            Vector2 posY = quad.Y;

            TextureInfo.CachedTileData uvs = m_current_texture_info.GetCachedTiledData( ref tile_index );

            m_v0 = new Vector4( quad.T , uvs.UV_00 );
            m_v1 = new Vector4( quad.T + posX , uvs.UV_10 );
            m_v2 = new Vector4( quad.T + posY , uvs.UV_01 );
            m_v3 = new Vector4( quad.T + posX + posY , uvs.UV_11 );

            add_quad();
        }
예제 #28
0
        private void addToTexture(Image img, Vector2i offset, int[] color)
        {
            data = img.ToBuffer ();

            for (int j=0; j < data.Length/4; j++) {
                if (data[j*4+3] != 0) {
                    if( 255 == data[j*4] && 255 == data[j*4+1] && 255 == data[j*4+2]) {
                        data[j*4] = (Byte)color[0];
                        data[j*4+1] = (Byte)color[1];
                        data[j*4+2] = (Byte)color[2];
                    }
                    var x = j%168 + offset.X;
                    var y = (j-x)/168 - offset.Y;
                    this.TextureInfo.Texture.SetPixels(0,data,PixelFormat.Rgba,j*4,167*4,x,y,1,1);
                }
            }
        }
예제 #29
0
        /// <summary>
        /// </summary>
        /// <param name="font">The font to use to render characters. Note that FontMap disposes of this Font object.</param>
        /// <param name="charset">A string containing all the characters you will ever need when drawing text with this FontMap.</param>
        /// <param name="fontmap_width">The internal with used by the texture (height is adjusted automatically).</param>
        public void Initialize( Font font, string charset, int fontmap_width = 512 )
        {
            CharSet = new Dictionary< char, CharData >();

            CharPixelHeight = font.Metrics.Height;

            Image image = null;
            Vector2i totalsize = new Vector2i( 0, 0 );

            for ( int k=0; k < 2; ++k )
            {
                Vector2i turtle = new Vector2i( 0, 0 );	// turtle is in Sce.PlayStation.Core.Imaging.Font's coordinate system
                int max_height = 0;

                for ( int i=0; i < charset.Length; ++i )
                {
                    if ( CharSet.ContainsKey( charset[i] ) )
                        continue; // this character is already in the map

                    Vector2i char_size = new Vector2i(
                        font.GetTextWidth( charset[i].ToString(), 0, 1 ),
                        font.Metrics.Height
                        );

                    max_height = Common.Max( max_height, char_size.Y );

                    if ( turtle.X + char_size.X > fontmap_width )
                    {
                        // hit the right side, go to next line
                        turtle.X = 0;
                        turtle.Y += max_height;	// Sce.PlayStation.Core.Imaging.Font's coordinate system: top is 0, so we += to move down
                        max_height = 0;

                        // make sure we are noit going to newline forever due to lack of fontmap_width
                        Common.Assert( char_size.Y <= fontmap_width );
                    }

                    if ( k > 0 )
                    {
                        // that starts from top left
                        image.DrawText( charset[i].ToString(), new ImageColor(255,255,255,255), font
                                        , new ImagePosition( turtle.X, turtle.Y ) );

                        var uv = new Bounds2( turtle.Vector2() / totalsize.Vector2()
                                             , ( turtle + char_size ).Vector2() / totalsize.Vector2() );

                        // now fix the UV to be in GameEngine2D's UV coordinate system, where 0,0 is bottom left
                        uv = uv.OutrageousYVCoordFlip().OutrageousYTopBottomSwap();

                        CharSet.Add( charset[i], new CharData(){ UV = uv, PixelSize = char_size.Vector2()} );
                    }

                    turtle.X += char_size.X;

                    if ( k == 0 )
                    {
                        totalsize.X = Common.Max( totalsize.X, turtle.X );
                        totalsize.Y = Common.Max( totalsize.Y, turtle.Y + max_height );
                    }
                }

                if ( k == 0 )
                {
            //					System.Console.WriteLine( "FontMap.Initialize: totalsize " + totalsize );
                    image = new Image( ImageMode.A, new ImageSize( totalsize.X, totalsize.Y ), new ImageColor(0,0,0,0) );

                    CharSet.Clear(); // we want to go through the same add logic on second pass, so clear
                }
            }

            Texture = new Texture2D( image.Size.Width, image.Size.Height, false, PixelFormat.Luminance );
            Texture.SetPixels( 0, image.ToBuffer() );
            //			image.Export("uh?","hey.png");
            image.Dispose();

            {
                // cache ascii entries so we can skip TryGetValue logic for those
                m_ascii_char_data = new CharData[ AsciiCharSet.Length ];
                m_ascii_char_data_valid = new bool[ AsciiCharSet.Length ];
                for ( int i=0; i < AsciiCharSet.Length; ++i )
                {
                    CharData cdata;
                    m_ascii_char_data_valid[i] = CharSet.TryGetValue( AsciiCharSet[i], out cdata );
                    m_ascii_char_data[i] = cdata;
                }
            }

            // dispose of the font by default
            font.Dispose();
        }