When I start to write Apps for iOS, I found a little different difference between Objective-C and Other OO language.
e.g.
-(void) accelerometer:(UIAccelerometer *)accelerometer
didAccelerate:(UIAcceleration *)acceleration
{
player.position.x += acceleration.x * 10;
player.position = pos;
}
If you try to build the code above, it will get error(Error: lvalue required as left operand of assignment).We write someting like player.position.x += value won't work with Objective-C properties, The problom lies how properties work in Objective-C and also how assignment works in the C language, on which Objective-C based.
The statement player.position.x is actually a calll to the position getter method [player position], which means you're actually retrieving a temporary position and then trying to change the x member of the temporary CGPoint. But the temporary CGPoint would then get thrown away. The position setter [player setPosition] simply will not be called automagically. You can only assign to the player.position property directly, in the case a new CGPoint.
In Objective-C you’ll have to live with this unfortunate issue—and possibly change programming habits if you come from a Java, C++ or C#background.
So we should try the code like this:
-(void) accelerometer:(UIAccelerometer *)accelerometer
didAccelerate:(UIAcceleration *)acceleration
{
CGPoint pos = player.position;
pos.x += acceleration.x * 10;
player.position = pos;
}
[Notes from" Learn iPhone and iPad Cocos2D Game Development"
分享到:
相关推荐
《A Little Java, A Few Patterns》是一本关于Java编程语言以及设计模式的书籍,作者为Matthias Felleisen和Daniel P. Friedman,这本书籍受到了豆瓣8.2高分的评价,被认为是学习Java语言和设计模式方面的优秀教程。...
> Curated collection of useful little Java 8 functions that you can understand quickly. Table of Contents Array View contents chunk countOccurrences deepFlatten difference differenceWith ...
3. `main.c`:这是项目的主要入口点,通常包含初始化代码,如LCD驱动设置、LittlevGL库的初始化,以及运行示例代码的逻辑。 4. `Makefile`或类似构建文件:用于编译和链接项目的源代码,以便在目标硬件上运行。 ...
标题中的"littlefs_python-0.1.2-cp35-cp35m-win_amd64.whl"指的是一个Python库的发行版本,它主要用于处理文件系统操作。这个库是littlefs的一个Python实现,名为littlefs_python,版本号为0.1.2。"cp35"表示它是...
Java is a new object-oriented programming language that was developed by Sun Microsystems for programming the Internet and intelligent appliances. In a very short time it has become one of the most ...
在英语中,"few" 和 "a few" 通常用来修饰可数名词,而 "little" 和 "a little" 修饰不可数名词。这些词在表达数量和程度时有着微妙的区别。 1. "Few" 表示几乎没有,具有否定含义,用于修饰可数名词;"a few" 表示...
资源来自pypi官网。 资源全名:littlefs_python-0.3.0-cp36-cp36m-win32.whl
A Little Java A Few Patterns 不错的书
Test-Driven Development (TDD) is a methodology that helps you to write as little as code as possible to satisfy software requirements, and ensures that what you've written does what it's supposed to ...
在实际应用中,你可能还需要考虑字节序的问题,因为不同系统可能使用不同的字节序(Big-Endian或Little-Endian)来表示16位的CRC值。此外,为了提高性能,可以考虑使用位操作和优化算法来减少循环次数。 在提供的...
这个压缩包文件"little-bear-dictionary-master.zip"很可能包含了关于SQL语言的学习资料或者一个用于查询和学习SQL的工具集。在深入探讨之前,让我们先了解一下SQL的基础知识。 SQL,全称Structured Query Language...
30 seconds of java8 > 你可以在30秒或更短时间内收集有用的Java8代码片段。 使用 Ctrl F 或者 command F 来查找代码片段。...代码片段基于 Java8,如果你还不熟悉...代码片段翻译自 little-java-functions 目录
《PyPI官网下载 | little-bio-parser-0.8.1.tar.gz——探索Python生物信息学解析库》 在IT领域,尤其是生物信息学中,数据解析是至关重要的环节。Python作为一门强大且易用的编程语言,拥有丰富的库支持各种科学...
MyBatis couples objects with stored procedures or SQL statements using a XML descriptor. Simplicity is the biggest advantage of the MyBatis data mapper over object relational mapping tools. To use ...
前言作为一个三维地球,在场景中来点雨雪效果,貌似可以增加一点真实感。Cesium 官网 Demo 中有天气系统的实例,用的是 Cesium 中的粒子系统做的。效
**LittlevGL应用程序综合应用详解** 在嵌入式系统开发中,图形用户界面(GUI)的设计与实现是一项关键任务,而LittlevGL就是这样一款强大的开源图形库,专为微控制器和资源有限的设备设计。本综合应用项目——...
首先,要在VS2019中成功编译LittlevGL应用,需要确保安装了C/C++编译器支持。这通常包括安装适用于VS2019的C++工作负载,确保拥有必要的工具链来处理嵌入式开发。此外,可能还需要安装特定的交叉编译工具链,以便...