简体   繁体   English

如何在 Cocoa 中移动精灵?

[英]How do I move a sprite in Cocoa?

I'm working in Objective-C for a Mac cocoa application.我正在为 Mac cocoa 应用程序在 Objective-C 工作。 It's a pretty simple question, but I can't find an answer.这是一个非常简单的问题,但我找不到答案。 I just want to move a sprite across the screen, like in a Snake game.我只想在屏幕上移动一个精灵,就像在蛇游戏中一样。 Do I need to use NSTimer or NSAnimation, and how would I use it?我需要使用 NSTimer 还是 NSAnimation,我将如何使用它?

Thanks谢谢

You could use Core Animation.您可以使用核心 Animation。 It provides a unified way to move and animate visual elements on the screen.它提供了一种统一的方式来移动屏幕上的视觉元素并为其设置动画。
If you plan to create a simple game, "Cocoa with Love" has a nice "Asteroid" example:如果您打算创建一个简单的游戏,“Cocoa with Love”有一个很好的“Asteroid”示例:
http://cocoawithlove.com/2009/02/asteroids-style-game-in-coreanimation.html http://cocoawithlove.com/2009/02/asteroids-style-game-in-coreanimation.html

Another game-related Core Animation project is Apple's Geek Game Board: http://developer.apple.com/library/mac/#samplecode/GeekGameBoard/Introduction/Intro.html另一个与游戏相关的Core Animation项目是Apple的Geek Game Board: http://developer.apple.com/library/mac/#samplecode/GeekGameBoard/Introduction/Intro.ZFC35FDC70D2FC69D26EZ888A3

Well, actually it depends on how you imagined your application, there's a lot of way to make things move.嗯,实际上这取决于你如何想象你的应用程序,有很多方法可以让事情移动。 If you do not need anything complex or particularly efficient you may just access and modify the NSView frame property.如果您不需要任何复杂或特别高效的东西,您可以访问和修改 NSView 框架属性。 Otherwise you should consider use Core Animation or OpenGL.否则,您应该考虑使用核心 Animation 或 OpenGL。
Core Animation Programming Guide 内核 Animation 编程指南
OpenGL Programming Guide for MacOSX OpenGL MacOSX 编程指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM