创建后台精灵节点

时间:2018-04-30 02:00:36

标签: swift sprite-kit

我正在尝试创建一个无尽的滚动游戏,我正在尝试创建两个背景。

我有一个像这样的背景课,

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
template="/user_templates/template.xhtml">
<ui:define name="metadata">
</ui:define>
<ui:define name="content">
    <h:form id="formId" style="margin-top:35;">
        <p:contextMenu>
            <p:menuitem value="© Indomaret" />
        </p:contextMenu>
        <p:breadCrumb>
            <p:menuitem value="PRPK" />
            <p:menuitem value="PRPK" />
            <p:menuitem value="List PRPK" />
            <p:menuitem value="Add New PRPK"
                url="/prpk/prpk_new.xhtml?faces-redirect=true" />
            <p:menuitem value="#{pRPKUserNonItBean.header}" />
        </p:breadCrumb>

        <h:panelGrid style="margin-left:5;margin-top:20;">
            <h2>PIC PRPK *</h2>
        </h:panelGrid>
        <h:panelGrid style="margin-left:0;margin-bottom:20;margin-top:5;">

            <p:commandButton value="Select PIC PRPK" icon="ui-icon-circle-plus"
                action="#{pRPKUserNonItBean.showPicPRPKDialog}" immediate="true">
                <p:ajax event="dialogReturn" update="roleTbl" />
            </p:commandButton>

            <p:dataTable var="prpk" id="roleTbl"
                value="#{chooseNonITUserDialogBean.listUserTemp}">
                <p:column headerText="Name">
                    <h:outputText value="#{prpk.name}" />
                </p:column>
                <p:column headerText="Department">
                    <h:outputText value="#{prpk.departmentName}" />
                </p:column>
                <p:column headerText="Head user">
                    <h:outputText value="#{prpk.headUserName}" />
                </p:column>
                <p:column headerText="Delete" width="10%">
                    <center>
                         <p:commandButton icon="ui-icon-trash"
                            action="#{chooseNonITUserDialogBean.deleteUser(prpk)}" 
                            update="roleTbl"
                            immediate="true" />
                    </center>
                </p:column>
            </p:dataTable>
        </h:panelGrid>

        <h:panelGrid columns="3" cellpadding="5" style="margin-left:10;">

            <p:outputLabel value="Request" for="requestTxt"
                style="display:block; width:100px;" />
            <p:inputTextarea id="requestTxt" required="true"
                style="width:700; height:25" value="#{pRPKUserNonItBean.prpkRequest}" />
            <p:message for="requestTxt" display="icon"></p:message>

            <p:outputLabel value="Background" for="backgroundTxt" />
            <p:inputTextarea id="backgroundTxt" style="width:700; height:25"
                value="#{pRPKUserNonItBean.prpkBackground}" />
            <p:message for="backgroundTxt" display="icon"></p:message>

            <p:outputLabel value="Benefit Analysis" for="beNalTxt" />
            <p:inputTextarea id="beNalTxt" style="width:700; height:25"
                value="#{pRPKUserNonItBean.prpk_analysisBenefit}" />
            <p:message for="beNalTxt" display="icon"></p:message>

        </h:panelGrid>

        <h:panelGrid columns="2" style="margin-left:120;">
        <p:commandButton value="Back"
            style="height:25; font-weight:bold; margin-left:5;"
            icon="ui-icon-circle-close" process="@this"
            action="/prpk/prpk_new.xhtml?faces-redirect=true" />

        <p:commandButton id="submitBtn" value="#{pRPKUserNonItBean.buttonName}"
            style=" font-weight:bold;margin-left:10;"
            type="submit" icon="ui-icon-disk" action="#{pRPKUserNonItBean.saveEdit}"
            update="formId" />
        <p:defaultCommand target="submitBtn" />
        </h:panelGrid>

        <p:dialog modal="false" widgetVar="successDialog" header="Info"
            closable="false">
            <h:panelGrid columns="1" cellpadding="2">
                <h:outputText value="Save data berhasil" />
                <center>
                    <p:commandButton value="Ok"
                        action="/prpk/master_prpk.xhtml?faces-redirect=true"
                        onclick="PF('successDialog').hide()" />
                </center>
            </h:panelGrid>
        </p:dialog>
        <p:dialog modal="false" widgetVar="failedDialog" header="Info"
            closable="false">
            <h:panelGrid columns="1" cellpadding="2">
                <h:outputText value="Save data failed" />
                <center>
                    <p:commandButton value="Ok" action="#"
                        onclick="PF('failedDialog').hide()" />
                </center>
            </h:panelGrid>
        </p:dialog>

    </h:form>
</ui:define>

我将用其他对象填充我的背景,所以我需要它作为一个类,而不仅仅是静态图像。

我有这样的游戏场景,

class BackgroundMG1: SKNode {
    let background: SKSpriteNode
    let size: CGSize

    init(size: CGSize) {
        self.size = size
        let hue = CGFloat((arc4random() % 1000) / 1000)
        let randomColor = UIColor(hue: hue, saturation: 1, brightness: 1, alpha: 1)
        self.background = SKSpriteNode(color: randomColor, size: size)

        super.init()

        setup()
    }

    func setup() {
        background.position.x = 0
        background.position.y = 0
        addChild(background)
    }
}

您还可以假设我设置了地面和相机对象。我不得不省略该代码,因为它与此问题无关。玩家留在地上,相机跟随玩家。

现在,当我加载游戏时,玩家对象会按预期向右移动。我看到一个背景,但第二个没有出现。

我觉得我在定位方面犯了一些错误。我不是100%坐标系在Swift中的工作方式。

编辑:我的场景已连接到.sks文件,此文件现在完全为空。游戏是横向的。

0 个答案:

没有答案