如何在iphone的cocos2d中获取CCSprite的宽度和高度 [英] how to obtain a CCSprite's width and height in cocos2d for iphone

查看:286
本文介绍了如何在iphone的cocos2d中获取CCSprite的宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是问题xD

给定iphone中cocos2d中的CCSprite实例,我可以用什么方法来获取图像的宽度和高度?

Given an instance of a CCSprite in cocos2d in iphone, what method can I use to obtain the image width and height?

推荐答案

CCSprite类有一个边界框属性,它是一个CGRect:

The CCSprite class has a bounding box property that's a CGRect:

  CCSprite *sprite = [CCSprite spriteWithFile: @"file.png"];
  int width = [sprite boundingBox].size.width;

我在我的CCSprite子类中添加了宽度和高度方法。

I added a width and height methods to my CCSprite subclass.

-(CGFloat) width
{
    return [self boundingBox].size.width;
}

-(CGFloat) height
{
    return [self boundingBox].size.height;
}

这篇关于如何在iphone的cocos2d中获取CCSprite的宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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