xamarin - 如何在 CocosSharp 中添加背景图片?
问题描述
我已使用此代码在 CCLayer 中添加背景图像,但它不起作用:
public class GameLayer : CCLayerColor
{
private CCSprite background;
public GameLayer() : base(CCColor4B.Transparent)
{
background = new CCSprite("cbg")
{
AnchorPoint = new CCPoint(0, 0),
IsAntialiased = true,
Position = new CCPoint(0, 0),
};
this.AddChild(background);
}
}
我的问题是图像正在显示,但不是屏幕大小作为背景图像,它只显示在屏幕的左下角。
编辑:已
解决:
为了解决此问题,我已将 Contnetsize 添加到与屏幕尺寸相同的图像中。
解决方案
这是我用来显示背景的代码:
var sprite = new CCSprite("bg.jpg");
sprite.AnchorPoint = new CCPoint(0, 0);
sprite.IsAntialiased = false;
layer.AddChild(sprite);
几乎相同的代码,但 CocosSharp 有时会出现奇怪的行为。
推荐阅读
- php - 拒绝,因为 php8.0 可能会导致无效的组合
- notifications - 当构建在依赖项后面排队时,Teamcity 通知?
- firebase - “用户”不是函数。尝试更正名称以匹配现有函数,或定义名为 'User'.dartinvocation_of_non_func 的方法或函数
- javascript - 使用 XHR 请求 API 时出现 CORS 错误
- reactjs - NextJs:仅在登录/注册页面中隐藏页眉和页脚?
- javascript - 使用 jQuery 和 CSS 选择器计算元素
- javascript - How to automatically add a new name to cloned radio buttons in a new card
- javascript - 如何验证是否已使用 Yup 验证设置状态?
- python - PostgreSQL 批量更新记录
- javascript - 在 javascript 中使用 new Date() 格式化当前小时和分钟