int number值-保存并从另一个页面检索. [英] int number value - saving and retrieving from another page.

查看:79
本文介绍了int number值-保存并从另一个页面检索.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好亲爱的朋友,

我在处理int值时遇到了一个小问题.所以我有一个游戏,也有一个计分板.每次一个对象与另一个对象碰撞时,我都会增加30点(将int值增加30)

因此,我遇到的问题是,我想在创建的GameOver页面上显示该分数.但是问题在于,当转到另一个视图时,会删除int编号.所以我想知道是否有人可以帮助我保存该int值,然后检索 在GameOver页面中.

这是代码:

我有一个int所在的类:

这是我的代码:

Hello dear friends,

I am having a small issue with int values. So I have a game and I have a score board. Every time an object collides with a another, I add 30 points(+30 to the int)

So the issue that I am having is that I want to show that score in the GameOver page that I created. But the issue is that the int number is erased when going to another view. So I was wondering if someone could help me to save that int value and then retrieve it in the GameOver Page.

Here is the code:

I have a class where the int is:

Here is my code:

命名空间 BomberBird  绘制得分
    公共   &HUD 
    { 
        //score  
       私有        public 获取 设置 ; } 
 
       public int 获取 set ; } 
 
 
       
       public        } 
 
       public void            //;在屏幕的左上角
           spriteBatch.DrawString( 
             n ;              nbsp; nbsp; span style ="color:green">//  SpriteFont  
                ;&" // 文本  
            nbsp; n ;                           n >// 位置  
               Microsoft.Xna.sp   //&tint  
       } 
 
   } 
namespace BomberBird 
    public class HUD 
    { 
        //score 
        private Vector2 scorePos = new Vector2(20, 10); 
 
        public SpriteFont Font { getset; } 
 
        public int Score { getset; } 
 
 
        
        public HUD() 
        { 
        } 
 
        public void DrawScore(SpriteBatch spriteBatch) 
        { 
            // Draw the Score in the top-left of screen 
            spriteBatch.DrawString( 
                Font,                          // SpriteFont 
                "Score: " + Score.ToString(),  // Text 
                scorePos,                      // Position 
                Microsoft.Xna.Framework.Color.White);   // Tint 
        } 
 
    } 

推荐答案

...我想在我创建的GameOver页面中显示该分数.但是问题在于,进入另一个视图时,会删除int编号...
...I want to show that score in the GameOver page that I created. But the issue is that the int number is erased when going to another view...


您需要将对象保留在上下文中.

简单的方法是将分数存储在Game类之类的中央类中,并将其传递到每个屏幕.

一些伪代码:


You need to keep the object in context.

The simple method is to store the Score in a central class like the Game class and pass that to each of your screens.

Some pseudo code:

公共   游戏 
   公共     Score;  
 
   公共   Game() 
   { 
    myscreen  =    Screen( );  
 } 
 
公共   class  屏幕 
 < span style ="color:#0000ff">私有   Game  theGame;  
 
 < span style ="color:#0000ff">公共  屏幕(游戏)(全局) 
   { 
    theGame  =  global;  
 } 
 
   公共   无效   Update() 
 <b;
   如果   ;(done  something) 
    { 
      theGame.Score  + =  30;  
   } 
 } 
public class Game  
{  
  public int Score;  
 
  public Game()  
  {  
    myscreen = new Screen(this);  
  }  
}  
 
public class Screen  
{  
  private Game theGame;  
 
  public Screen(Game global)  
  {  
    theGame = global;  
  }  
 
  public void Update()  
  {  
    if (done something)  
    {  
      theGame.Score += 30;  
    }  
  }  


这篇关于int number值-保存并从另一个页面检索.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆