Changeset 6545


Ignore:
Timestamp:
2015-06-29 22:20:48 (4 years ago)
Author:
sieerinn
Message:

Animaatioiden latausjuttu ja pari animaatiota.

Location:
2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel
Files:
25 added
3 edited

Legend:

Unmodified
Added
Removed
  • 2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel.cs

    r6544 r6545  
    22using System.Collections.Generic; 
    33using System.Linq; 
     4using System.Reflection; 
    45using Jypeli; 
    56using Jypeli.Assets; 
     
    6162    List<Exit> exits = new List<Exit>(); 
    6263 
    63     public override void Begin()         
     64    #region Resources 
     65 
     66    [AssetName("walkright")] 
     67    private Animation playerWalkRight; 
     68    [AssetName("walkright", mirror: true)] 
     69    private Animation playerWalkLeft; 
     70 
     71    #endregion 
     72 
     73    public override void Begin() 
    6474    { 
    6575        SmoothTextures = false; 
     76        LoadAnimations(); 
    6677        StartGame(); 
     78    } 
     79 
     80    /// <summary> 
     81    /// Lataa automaagisesti kaikki animaatiot. 
     82    /// </summary> 
     83    private void LoadAnimations() 
     84    { 
     85        // Haetaan tämän luokan kaikki ei-julkiset attribuutit. 
     86        foreach (var field in GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance)) 
     87        { 
     88            // Jos attribuutille on laitettu AsseName, niin ladataan sen niminen animaatio. 
     89            var assetAttr = Attribute.GetCustomAttribute(field, typeof(AssetNameAttribute)) as AssetNameAttribute; 
     90            if (assetAttr == null) continue; 
     91            var anim = LoadAnimation(assetAttr.AssetName); 
     92            field.SetValue(this, assetAttr.Mirror ? MirrorAnimation(anim) : anim); 
     93        } 
     94    } 
     95 
     96    /// <summary> 
     97    /// Peilaa kaikki animaation kuvat. 
     98    /// </summary> 
     99    private static Animation MirrorAnimation(Animation anim) 
     100    { 
     101        return new Animation(anim.Select(Image.Mirror).ToArray()) { FPS = anim.FPS }; 
    67102    } 
    68103 
     
    71106        ClearAll(); 
    72107        CreateLevel("level1"); 
    73       //  CreatePlayer(new Vector(-Level.Width/3, Level.Bottom + TILE_SIZE * 2)); 
     108        //  CreatePlayer(new Vector(-Level.Width/3, Level.Bottom + TILE_SIZE * 2)); 
    74109        SetControls(); 
    75110        Camera.ZoomToLevel(); 
  • 2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel.csproj

    r6536 r6545  
    111111  </ItemGroup> 
    112112  <ItemGroup> 
     113    <Compile Include="AssetNameAttribute.cs" /> 
    113114    <Compile Include="LevelCreation.cs" /> 
    114115    <Compile Include="Ohjelma.cs" /> 
  • 2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabrielContent/TheLegendOfGabrielContent.contentproj

    r6544 r6545  
    9292    </Compile> 
    9393  </ItemGroup> 
     94  <ItemGroup> 
     95    <Compile Include="walkdown.anim"> 
     96      <Name>walkdown</Name> 
     97      <Importer>AnimationImporter</Importer> 
     98      <Processor>AnimationContentProcessor</Processor> 
     99    </Compile> 
     100    <Compile Include="walkright.anim"> 
     101      <Name>walkright</Name> 
     102      <Importer>AnimationImporter</Importer> 
     103      <Processor>AnimationContentProcessor</Processor> 
     104    </Compile> 
     105    <Compile Include="walkup.anim"> 
     106      <Name>walkup</Name> 
     107      <Importer>AnimationImporter</Importer> 
     108      <Processor>AnimationContentProcessor</Processor> 
     109    </Compile> 
     110  </ItemGroup> 
    94111  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    95112  <!--  To modify your build process, add your task inside one of the targets below and uncomment it.  
Note: See TracChangeset for help on using the changeset viewer.