Setup
Before we start practical application, we need to set up a project so that we can focus on chipmunk.
Open xcode, create a new project, and use the 'view-based 'application.ProgramTemplate to create a simple application. After the application is started, a view is displayed.
We generally need to import the chipmunk file. This task will be completed in several steps, including creating a static library and connecting to our project. In this example, we simply copy the files we need to the project folder. Then download the latest chipmunkCode, Decompress, this folder will contain multiple files, examples and documents, but we only need to pay attention to the contents in the SRC folder.
Before importing these files, we recommend that you create a new group in other source. Then, use 'add existing file' and select the SRC folder mentioned above. Make sure to select 'Copy items into the destination group's folder (if needed) '. After these steps, if you compile the project, no error will be reported.
Now we have completed the setup step. We don't plan to use any game engine, and create several images to represent our objects. Although you can use a changed code to replace these images, I suggest you use images and code to reduce your misunderstanding of the Code.
Now open View Controller and add this to the file.
View plaincopy to clipboardprint?
-
- Uiimageview * floor;// Holds our floor Image
- Uiimageview * ball;// Holds our ball Image
Then, the viewdidload is uninjected to implement the following code. You can copy the code and put it after [Super viewdidload:
View plaincopy to clipboardprint?
- Floor = [[uiimageview alloc] initwithimage: [uiimage imagenamed :@"Floor.png"];
-
- Floor. Center = cgpointmake (160,350 );
-
- Ball = [[uiimageview alloc] initwithimage: [uiimage imagenamed :@"Ball.png"];
-
- Ball. Center = cgpointmake (160,230 );
-
-
- [Self. View addsubview: Floor];
-
- [Self. View addsubview: Ball];
After running the startup program, you will see the two pictures I mentioned above in the program.