GVKun编程网logo

SpriteBuilder Demo学习笔记(spriter教程)

13

本文将分享SpriteBuilderDemo学习笔记的详细内容,并且还将对spriter教程进行详尽解释,此外,我们还将为大家带来关于android.test.suitebuilder.TestSui

本文将分享SpriteBuilder Demo学习笔记的详细内容,并且还将对spriter教程进行详尽解释,此外,我们还将为大家带来关于android.test.suitebuilder.TestSuiteBuilder的实例源码、Apache Commons EqualsBuilder and HashCodeBuilder、apache.commons.lang.builder 学习(一) ToStringBuilder、cocos2d-iphone – xCode 5.1构建崩溃 – SpriteBuilder的相关知识,希望对你有所帮助。

本文目录一览:

SpriteBuilder Demo学习笔记(spriter教程)

SpriteBuilder Demo学习笔记(spriter教程)

1、资源的auto-scaling。只需提供最高级别的resolution,SpriteBuilder会自动生成低级别的。SpriteBuilder默认是从4x(两倍于Retina屏)开始scaling,可以在File->Project Settings中设置为2x,然后点击publish。 2、Smart Sprite Sheets。自动生成精灵表单将所有资源放在一张大图上,只需一次读入到内存。右键单击资源文件夹,点击Make Smart Sprite Sheet,然后点击publish即可。 3、使用SpriteBuilder创建动画(以熊为例) ···新建一个结点Bear,选择Node为根容器。将涉及到的资源图片拖到根节点(Node)中。由于接下来使用手臂的旋转动画,所以设置手臂的anchorPoint,旋转会根据锚点来。 ···一个动画有一个TimeLine,可以为结点添加多个TimeLine使其支持多个动画。点击按钮编辑名称和持续时间 ···使用右上角的滑竿缩放TimeLine ···添加KeyFrame。(旋转)按下r,在第一个时间点填上旋转角度,拖动到第二个时间点,按下r,填上旋转角度,再拖到第三个时间点,以此类推。完成后,链接动画, 4、从TimeLine上选择根Node—CCSprite,然后在Sprite Frame属性设置精灵图片。在右边第三栏中选择Enable Physics使用物理,此时粉色的点组成的图形代表物理Body的shape。默认为矩形,可更改。在右边第二栏填入Custom Class连接到OC类。 5、连接到代码。在Xcode中根据.ccb文件创建OC类,父类要与根节点一致。点击Publish,然后可以通过在Xcode中的AppDelegate.m中[self setupCocos2dWithOptions:cocos2dSetup];后添加[CCBReader load”@“Penguin”]:来加载精灵。 6、将背景图片添加到ccb文件中,位置设定方面以百分比设置可以确保支持多尺寸的设备。 7、添加一个按钮,选择其普通或Highlight状态下的在照片,还应该设置Preferred Size为Retina下image size的一半。在第二栏中填写selector的名称并选择target,Document Root表示其所在的根节点的类作为target。 8、将其他ccb添加到当前ccb。从对象库中添加一个Sub File结点,选择想要添加的ccb文件。 9、physics object 只能添加到 physics node下。 10、选中一个结点(对象),在第二栏Code Connection中Doc Root var栏可以填写实例变量名,这样就连接到代码了。要在代码中定义同名的实例变量。 11、CCB文件加载完后会调用didLoadFromCCB方法。 12、在TimeLine中可以将结点拖拽到CCPhysicsNode下,让其支持物理引擎(一般为静态物体)。可以在第三栏选择其类型为static 13、Pivot链接(Joint)将物理结点链接于一点。 14、使用SpriteBuilder创建链接。将Pivot Joint拖到想要链接的点上,放置好后,下面会出现两个点,将两个点分别拖到被链接的两个物理结点上。该过程也可以通过在右边对bodyA和bodyB属性进行选择来设置。 15、物理引擎中使直杆竖立的小技巧:与一个不可见的物理结点建立链接。此例中建立的是Spring链接,便于后续旋转与反弹。当要链接的结点没有contentSize时可以链接到TimeLine。通过改变Spring链接的AnchorPoint或者拖动链接的终点。Spring链接中rest length表示弹簧收缩或扩张的长度, 16、使用SpriteBuilder创建的链接是存在于整个游戏中的链接,如果我们想动态创建、消除链接,则需要在代码中完成。 17、addPostStepBlock:key:方法确保块方法只被调用一次,per frame and key. 18、粒子效果。新建ccb文件选择Particle为Root Node。在TimeLine中选择CCParticleSystem后在右边面板中第四栏选择类型,第一栏设置数值。 19、使用SpriteBuilder创建精灵帧动画。选中精灵,在左侧资源面板中选中所有相关文件,然后右键单击选择Create Keyframes from selection。 20、TimeLine可以从代码中通过actionManager获取。方法是新建+命名。通过该名称获取,方法是runAnimationForSequenceNamed: 21、iPad适配。 ①根节点的大小。为了适配iPad大屏幕,设置contentSize为按百分比,并让height为100% ②控件的位置。可以在SpriteBuilder中设置控件相对于四个角(左上、左下、右上、右下)中任意一角的位置。

android.test.suitebuilder.TestSuiteBuilder的实例源码

android.test.suitebuilder.TestSuiteBuilder的实例源码

项目:AntennaPodSP    文件:AntennaPodTestRunner.java   
@Override
public TestSuite getAllTests() {
    return new TestSuiteBuilder(AntennaPodTestRunner.class).includeAllPackagesUnderHere()
            .excludePackages("instrumentationTest.de.test.antennapod.syndication.handler")
                    //        .excludePackages("instrumentationTest.de.test.antennapod.gpodnet")
            .build();
}
项目:EinschlafenpodcastAndroidApp    文件:AntennaPodTestRunner.java   
@Override
public TestSuite getAllTests() {
    return new TestSuiteBuilder(AntennaPodTestRunner.class).includeAllPackagesUnderHere()
            .excludePackages("instrumentationTest.de.test.antennapod.syndication.handler")
                    //        .excludePackages("instrumentationTest.de.test.antennapod.gpodnet")
            .build();
}
项目:CodeWatch    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:Udacity_Sunshine    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:Advanced_Android_Development_Wear    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:SunshineWithWear    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:nano-go-ubiquitous    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:popular-movies    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:getting-ready-for-android-n    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:udacity-p3    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:Go-Ubiquitous    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:YouTube-In-Background    文件:ExtractorTest.java   
public static Test suite() {
    return new TestSuiteBuilder(ExtractorTest.class).includeAllPackagesUnderHere().build();
}
项目:Wearapp    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:go-ubiquitous    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:UdacityProject6    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:PopularMovies    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:Sunshinewear    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:Sunshine    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:DBUFR    文件:FullTestSuite.java   
public static Test suite() {
  return new TestSuiteBuilder(FullTestSuite.class)
      .includeAllPackagesUnderHere().build();
}
项目:Sunshine_WeatherApp    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:SunshineApp    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:SunshineWear    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:Sunshine-Android-Wear    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:Komica    文件:ExtractorTest.java   
public static Test suite() {
    return new TestSuiteBuilder(ExtractorTest.class).includeAllPackagesUnderHere().build();
}
项目:intellij-ce-playground    文件:AllTests.java   
public static Test suite() {
    return new TestSuiteBuilder(AllTests.class)
            .includeAllPackagesUnderHere()
            .build();
}
项目:Sunshine.Wear    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:super-duo    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:android-weather-app    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:Advanced_Android_Development    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:android-tv-leanback    文件:search_AllTests.java   
public static Test suite() {
    return new TestSuiteBuilder(search_AllTests.class)
            .includeAllPackagesUnderHere()
            .build();
}
项目:Sunshine.Advanced    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:mysunshine    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:SunshineWatchFace    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:spst    文件:FullTestSuite.java   
public static Test suite() {
    return new TestSuiteBuilder(FullTestSuite.class)
            .includeAllPackagesUnderHere().build();
}
项目:Handle    文件:AllTests.java   
public static Test suite() {
    return new TestSuiteBuilder(AllTests.class)
            .includeAllPackagesUnderHere()
            .build();
}

Apache Commons EqualsBuilder and HashCodeBuilder

Apache Commons EqualsBuilder and HashCodeBuilder

Introduction

Before we go ahead and explore Apache Commons**_ EqualsBuilder_** and HashCodeBuilder, we must know the relationship between equals and hashCode.

java.lang.Object which is the super class of all Java classes has two very important methods defined in it. They are:

public boolean equals(Object obj)

public int hashCode()

These two methods are very important when our classes deal with other Java classes such as Collection API used for searching, sorting, comparison and eliminate duplicate objects from a set.

public boolean equals(Object obj)

This method checks if some other object passed to it as an argument is equal to the object on which this method is invoked. The default implementation of this method in ** Object** class simply checks if two object references x and y refer to the same object, i.e., it checks if ** x == y**. This particular comparison is also known as “shallow comparison”. However, the classes providing their own implementations of the equals method are supposed to perform a “deep comparison”

public int hashCode()

This method returns the hash code value for the object on which this method is invoked. This method returns the hash code value as an integer and is supported for the benefit of hashing based collection classes such as Hashtable, HashMap,_ HashSet_, etc.

Relationship between equals and hashCode

Equal objects must produce the same hash code as long as they are equal, however unequal objects need not produce distinct hash codes.

Implementation

While_** hashCode()_ and_ equals()_ typically impact logic and performance, they are also often more tricky to implement correctly. The most important rule is that when one of these two methods is overridden, the other one should be as well. Because it can be tricky to implement hashCode() and equals() correctly, it is helpful to have_ EqualsBuilder_** and_** HashCodeBuilder**_ two reusable implementations of these provided as part of Apache Commons Lang builder package.

I particularly like the way how EqualsBuilder uses reflection to determine if the two Objects are equal or HashCodeBuilder uses reflection to build a valid hash code. But reflection hits the performance of application, so use it where the performance is not very critical. However these two builders also provide the alternative approach. Let’s demonstrate both approaches one by one:

  • Using Reflection:

Let’s create a simple class called Employee as the following mentioned code:

package blog.commons;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

public class Employee {

	private int id;
	private String name;
	private int deptId;
	private String designation;

	public Employee(int id, String name, int deptId, String designation) {
		this.id = id;
		this.name = name;
		this.deptId = deptId;
		this.designation = designation;
	}

	@Override
	public boolean equals(Object obj) {
		return EqualsBuilder.reflectionEquals(this, obj);
	}

	@Override
	public int hashCode() {
		return HashCodeBuilder.reflectionHashCode(this);
	}
}

Now create a _ Main_ class to check how it works:

package blog.commons;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Employee emp1 = new Employee(1, "Allen", 12, "Accountant");
		Employee emp2 = new Employee(1, "Allen", 13, "Accountant");
		System.out.println
			("Is emp1 equals to emp2: " + emp1.equals(emp2));
		Set<Employee> employees = new HashSet<Employee>();
		employees.addAll(Arrays.asList(emp1,emp2));

		System.out.println("Size of set: " + employees.size());

	}
}

If you execute the**_ main_** method, the output will be as follows:

Is emp1 equals to emp2: false
Size of set: 2

Here you can see that the employee “Allen” whose employee Id is “1? is an “Accountant” does his book keeping job for two different departments which department ids are**_ 12_** and 13 respectively. But the object**_ emp1_** and emp2 are treated as two different persons.

Now, let’s exclude the**_ deptId_** field to determine equality and build hashCode and see the effect. For doing this, you need to slightly modify the code of Employee class:

package blog.commons;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

public class Employee {

	private int id;
	private String name;
	private int deptId;
	private String designation;

	public Employee(int id, String name, int deptId, String designation) {
		this.id = id;
		this.name = name;
		this.deptId = deptId;
		this.designation = designation;
	}

	@Override
	public boolean equals(Object obj) {
		return EqualsBuilder.reflectionEquals
			(this, obj,new String[] {"deptId"});
	}

	@Override
	public int hashCode() {
		return HashCodeBuilder.reflectionHashCode
				(this,new String[] {"deptId"});
	}
}

Again, execute the same**_ main_** method to see the output:

Is emp1 equals to emp2: true
Size of set: 1

Here, as you can see, now**_ emp1_** and emp2 are treated as equal but**_ emp1_** are been replaced by emp2, hence the size of the set employees is one. To overcome this problem, do not exclude the deptId while generating hashCode. Your**_ hashCode_** method should look like the following:

@Override
	public int hashCode() {
		return HashCodeBuilder.reflectionHashCode(this);
	}

Now the output should be shown as below if you execute the**_ main_** method again:

Is emp1 equals to emp2: true
Size of set: 2
  • Without Using Reflection:

In my previous examples, you have seen how easily and in a fascinating manner we can use reflection capability of EqualsBuilder and HashCodeBuilder to override**_ equals _**and hashCode methods. Now, I am going to show you how can you achieve the same output without using reflection which helps to improve performance:

package blog.commons;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

public class Employee {

	private int id;
	private String name;
	private int deptId;
	private String designation;

	public Employee(int id, String name, int deptId, String designation) {
		this.id = id;
		this.name = name;
		this.deptId = deptId;
		this.designation = designation;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Employee == false) {
			return false;
		}

		if (this == obj) {
			return true;
		}
		Employee other = (Employee) obj;
		return new EqualsBuilder().append(this.id , other.id)
		.append(this.name , other.name)
		.append(this.designation , other.designation).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(this.id)
		.append(this.name)
		.append(this.deptId)
		.append(this.designation)
		.hashCode();
	}
}

If you run the _ main_ method this time, you get similar output as it has been shown in the last output result. Just notice here that I am not appending deptId in _ EqualsBuilder_ but I am doing it while generating _ hashCode_.

apache.commons.lang.builder 学习(一) ToStringBuilder

apache.commons.lang.builder 学习(一) ToStringBuilder

版本:commons-lang-2.4.jar

学习内容:apache.commons.lang.builder.ToStringBuilder

当你需要重载 toString 函数而不想写代码把当前类的所有成员信息列出来,可以用这个函数。

public class People {
	private String name;
	private int age;
	private String sex;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}
}

 构造一个对象,sex不赋值,容易比较值为null的情况。

People people = new People();
people.setAge(18);
people.setName("小树");
System.out.println(people.toString());

如果不重写People类的toString()方法,控制台输出:test.People@2faadcc6

如果默认重写People类的toString()方法,控制台输出:People [name=小树, age=18, sex=null]

备注:默认重写的toString()方法是使用字符串拼接:"People [name=" + name + ", age=" + age + ", sex=" + sex + "]"。字符串用“+”拼接效率很低。

System.out.println(ToStringBuilder.reflectionToString(people));

 控制台输出:test.People@2faadcc6[name=小树,age=18,sex=<null>]

System.out.println(ToStringBuilder.reflectionToString(people, ToStringStyle.DEFAULT_STYLE));

控制台输出:test.People@2faadcc6[name=小树,age=18,sex=<null>]

System.out.println(ToStringBuilder.reflectionToString(people, ToStringStyle.MULTI_LINE_STYLE));

控制台输出:test.People@2faadcc6[
  name=小树
  age=18
  sex=<null>

System.out.println(ToStringBuilder.reflectionToString(people, ToStringStyle.NO_FIELD_NAMES_STYLE));

 控制台输出:test.People@2faadcc6[小树,18,<null>]

System.out.println(ToStringBuilder.reflectionToString(people, ToStringStyle.SHORT_PREFIX_STYLE));

控制台输出:People[name=小树,age=18,sex=<null>]

System.out.println(ToStringBuilder.reflectionToString(people, ToStringStyle.SIMPLE_STYLE));

控制台输出:小树,18,<null>

cocos2d-iphone – xCode 5.1构建崩溃 – SpriteBuilder

cocos2d-iphone – xCode 5.1构建崩溃 – SpriteBuilder

我最近将xCode更新为5.1.发布到我的iPhone 5s(iOS 7.1)时,我的(cocos2d)构建突然崩溃了.它在模拟器(iOS 7.1)中工作正常.
我在这里截图: http://puu.sh/7rB8S.png

自从我将xCode更新为5.1后,我收到了一些警告.
替换为:“7rBfp.png”(由于缺乏声誉……)

如果您愿意重现该问题,我遵循了本教程:https://www.makegameswith.us/tutorials/getting-started-with-spritebuilder/menus/
一旦我添加了MainScene背景(以及按钮方法),我就无法在iPhone上构建了.

我错过了什么吗?在我今天更新xCode和我的手机之前,一切都运转良好.

要更新Cocos2D,请下载最新版本( https://s3.amazonaws.com/spritebuilder/cocos2d-iphone-3.0.0.rc.4.zip24),解压缩文件并将其重命名为cocos2d-iphone并替换当前项目中的版本.它位于Source / libs / cocos2d-iphone中.

在这个答案的SpriteBuilder forums致Vic的信贷.

我们今天的关于SpriteBuilder Demo学习笔记spriter教程的分享就到这里,谢谢您的阅读,如果想了解更多关于android.test.suitebuilder.TestSuiteBuilder的实例源码、Apache Commons EqualsBuilder and HashCodeBuilder、apache.commons.lang.builder 学习(一) ToStringBuilder、cocos2d-iphone – xCode 5.1构建崩溃 – SpriteBuilder的相关信息,可以在本站进行搜索。

本文标签: