我想自动缩放场景的大小,因为在GameScene.sks中,我只能为场景大小选择一些iPhone型号(iPhone 4s,iPhone SE,iPhone 6s和iPhone 6 Plus)。因此,我尝试自动缩放以自动支持所有模型。
这是我的SKScene中的代码:
class GameScene: SKScene {
override init(size: CGSize) {
super.init(size: size)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
.......
语法似乎是正确的,但是当我在模拟器中切换到GameScene时,应用程序将崩溃。我是一个初学者,所以可能是重写init函数使用错误。
答案 0 :(得分:0)
import SpriteKit
class GameScene: SKScene {
let backgroundNode = SKSpriteNode()
override func didMove(to view: SKView) {
backgroundNode.size = CGSize(width: displaySize.width, height: displaySize.height)
backgroundNode.color = .red
self.addChild(backgroundNode)
}
}
答案 1 :(得分:0)
我建议您在GameDViewController中的viewDidLoad()方法中设置scaleMode,而不是手动设置每个大小。您可以将scaleMode设置为AspectFill / AspectFit / resizeFill等。这是示例代码。
import pandas as pd
df = pd.read_csv('test')
df2 = pd.read_csv('test.csv')
df2 = df2.rename(columns={'col1' : 'species'})
print(df)
# species seq_names value
# 0 dog seq_C 0.67
# 1 cat seq_F 1.40
# 2 cat seq_E 0.40
# 3 dolphin seq_F 0.70
# 4 dolphin seq_A 1.90
# 5 frog seq_A 0.80
# 6 frog seq_B 0.40
print(df2)
# group_number species
# 0 1 cat
# 1 1 dog
# 2 2 dolphin
# 3 2 frog
# We now don't immediatly drop the duplicates, we want to save the merge before.
# Doing this, we're able to keep the seq_names associated with their group_number.
ndf = df.merge(df2, on='species')\
.sort_values(by='value', ascending=False)
# I make a copy so that I get a whole new DataFrame.
# If I didn't. Changes made to seq_groups would have affected the original.
seq_groups_df = ndf[['seq_names', 'group_number']].copy()
seq_groups_df = seq_groups_df.rename(columns={'seq_names' : 'sp_seq_names'})
print(seq_groups_df)
# seq_names group_number
# 4 seq_A 2
# 1 seq_F 1
# 5 seq_A 2
# 3 seq_F 2
# 0 seq_C 1
# 2 seq_E 1
# 6 seq_B 2
ndf = ndf.drop_duplicates(subset='seq_names', keep='first')
# Either select the interesting columns.
ndf = ndf[['group_number', 'species']]
ndf = ndf.rename(columns={'species' : 'sp_seq_names'})
print(ndf)
# group_number sp_seq_names
# 4 2 dolphin
# 1 1 cat
# 0 1 dog
# 2 1 cat
# 6 2 frog
result_df = ndf.append(seq_groups_df).reset_index(drop=True)
print(result_df)
# group_number sp_seq_names
# 0 2 dolphin
# 1 1 cat
# 2 1 dog
# 3 1 cat
# 4 2 frog
# 5 2 seq_A
# 6 1 seq_F
# 7 2 seq_A
# 8 2 seq_F
# 9 1 seq_C
# 10 1 seq_E
# 11 2 seq_B
这里是缩放场景内容以适合视图的文档。 https://developer.apple.com/documentation/spritekit/skscene/scaling_a_scene_s_content_to_fit_the_view