SpriteKit

使用swift在sprite中显示圆角UIButton按钮

*爱你&永不变心* 提交于 2019-12-14 16:35:31
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 我对objective-C不是很熟,UIKit以前没有用过,SpriteKit也只看了遍教程,然后看了一遍swift语言教程,此时开始编写这个程序,所以遇到的问题比较小儿科,解决方法也是曲线救国,希望有高人指点解决这些问题的简单方法,有好的解决方法后,我会随时进行本日志的修改,以免误导他人。 程序界面很是简单 然后点击中间的游戏区域,会roll色子,随机产生1~6的数字,飞机前进若干步,遇到梯子向前跳若干步,而遇到蛇则后退若干步,指导抵达25格,游戏结束。 上面有一个标签,显示游戏状态和Roll点值。 下面有一个RESTART按钮,用来重新开始游戏,本日志的关键就是这个按钮。 起先我想法很简单,就是在sprite的scene里边添加一个按钮,但是SpriteKit里边我并没有发现类似按钮控件什么的,开始我使用Label替代按钮的功能,就是在点击事件中判断控件,然后再执行按钮相关代码,这种方法一是按钮太丑,二是点击时没有按钮的动作,三是按钮的方法调用实在是太山寨了。 后来我发现了UIButton,我参考了下面添加按钮的Objective-C代码: CGRect frame = CGRectMake(90, 200, 200, 60); UIButton *someAddButton = [UIButton

Spritekit: how to make game screen view move upwards as node “jumps” along the y axis?

匿名 (未验证) 提交于 2019-12-03 09:06:55
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: could someone please post an example code of how i could make my game screen move up as my player node "jumps" up the y axis. the same as doodle jump? at the moment it obviously just jumps straight out of the top of the screen. any help with making my "platform" nodes remove themselves from the parent and then reapear when they go out the bottom of the view as i move up the screen would help aswell. and one last thing, how do i add more than one node to the initial view. [self add child:node] only makes one. i know these are probably amateur

SpriteKit how to get correct screen size

匿名 (未验证) 提交于 2019-12-03 07:36:14
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've tried self.frame.size self.view!.frame.size UIScreen.mainScreen().bounds.size None of them work. How do I get the correct screen size for the device? 回答1: You can use following swift code to get the screen size. let displaySize: CGRect = UIScreen.mainScreen().bounds let displayWidth = displaySize.width let displayHeight = displaySize.height 回答2: You can use: let deviceWidth = UIScreen.mainScreen().bounds.width let deviceHeight = UIScreen.mainScreen().bounds.height And if you need to get the ratio so you can detect what device they are

Spritekit crashes when entering background

匿名 (未验证) 提交于 2019-12-03 02:24:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Allright guys, I've been developing an app in which I have a NSMutableDictionary with an SKAction object in it. The SKAction is for playing a sound. This all works well, except ... the app crashes upon entering background with the following stack trace: * thread #1: tid = 0x187d7, 0x3461b932 libGPUSupportMercury.dylib`gpus_ReturnNotPermittedKillClient + 10, queue = 'com.apple.spritekit.renderQueue, stop reason = EXC_BAD_ACCESS (code=1, address=0x1) frame #0: 0x3461b932 libGPUSupportMercury.dylib`gpus_ReturnNotPermittedKillClient + 10 frame

Bendable arm rotation in SpriteKit - rotate at point

匿名 (未验证) 提交于 2019-12-03 01:46:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to simulate a bendable arm using SpriteKit. I have an upper arm SKShapeNode and a lower arm SKShapeNode . How would I rotate the lower arm so it rotates at the elbow instead of rotating on itself? Here is my straight arm with the upper arm being tan colored and the lower arm being cyan colored. This is what it looks like after a -90 degree rotation on the lower arm How would I simulate the lower arm being connected to the upper arm at the elbow? I've tried multiple SKConstraint s but couldn't find one that worked for me

iOS 9 Spritekit Double Tap Not Working on iPhone 6S

匿名 (未验证) 提交于 2019-12-03 00:56:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have been building a SpriteKit game for a while now. Its a card game that allows double-tap on card sprites for specific behaviors. Now that we're in iOS 9, double taps do not work at all on iPhone 6s. Works fine on iOS8, all devices. In my SKScene , i'm using the touchesBegan method to detect taps: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint touchLocation = [touch locationInNode:self]; if(touch.tapCount==2) { NSLog(@"double-tap, but not for iPhone 6s"); } } Is there

SpriteKit游戏开发适配iPad/iPhone6/7/8/Plus及iPhoneX的尺寸及安全区域

匿名 (未验证) 提交于 2019-12-03 00:39:02
未适配前:Ball球超过屏幕的上下方 适配后:Ball球就在屏幕的可视范围内运动了 一、那么如何适配不同的iPhone、iPhoneX及iPad的屏幕尺寸呢? 我们开发一个App的时候, 通常希望它在 iPhone, iPad, Mac上同时能运行, 尤其是游戏。 这样就需要我们考虑不同设备不同的分辨率,但处理起来比较麻烦,比如说,按照官方的做法,我们需要提供诸如 ifiero@1x,ifiero@2x,ifiero@3x, 这样不同尺寸的图片,那如何简便的适配设备不同的分辨率呢,我们的做法是, 固定一个大小, 向下兼容不同的设备。 即场景中的所有图片, 都按照屏幕大小为 2048 * 1536 来绘制。 也就是说, 我们的背景图的大小是 2048 * 1536, 其他图片也是依照这个比例来绘制。 为什么这样做呢? 我们知道 2048 * 1536 是iPad Retina 的分辨率。也是我们需要适配的设备里面分辨率最高的。 所以我们在游戏中都选择了这个大小,让它来兼容分辨率低的设备。 2048 * 1536 在iPad Retina上是完美显示的。 那在其他设备上呢? 这里就要依靠 AspectFill来进行缩放了,代码如下: if let scene = GameScene ( fileNamed : "GameScene" ) { scene . size = CGSize

iOS SpriteKit/SceneKit/Metal浅析

☆樱花仙子☆ 提交于 2019-11-29 02:49:54
【SpriteKit】 在iOS7中内置了新的SpriteKit框架,该框架主要用来开发2D游戏。是开发iOS和OS X 下的2D游戏引擎,可以使用OC或者Swift来进行开发。目前已经支持的内容包括:精灵、很酷的特效(例如视频、滤镜和遮罩),并且还集成了物理库等许多东西。首先指出在iOS中开发2D游戏SpriteKit并不是唯一的选择,我们先来看看SpriteKit的特点和优缺点: 1.特点: (1)提供了游戏引擎必备的图形渲染和动画API,可以通过这些API让精灵动起来; (2)使用传统的渲染和动画,允许在渲染每一帧之前处理该帧; (3)提供了声音播放; (4)提供的物理引擎; (5)与Xcode集成,可以更容易的创建基于Sprite Kit的游戏工程,调试也很方便; (6)可以使用Swift语言; 2.优点: (1)它是内置到iOS中的,因此并不需要下载额外的库或者其他的外部依赖,并且它是由苹果开发的,所以对他的支持和更新我们可以放心; (2)它内置的工具支持纹理和粒子; (3)它可以让你做一些其他框架难以做到的事情,例如把视频当做精灵一样处理,或者使用很酷的图形效果和遮罩。 3.缺点: (1)如果使用了SpriteKit,那么你将被iOS生态圈绑架,导致很难把游戏移植到Android等其他平台; (2)SpriteKit现在还处于初始阶段,提供的内容还不够丰富