• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright 2011 See AUTHORS file.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************/
16 
17 package com.badlogic.gdx.tests;
18 
19 import com.badlogic.gdx.Gdx;
20 import com.badlogic.gdx.InputProcessor;
21 import com.badlogic.gdx.graphics.GL20;
22 import com.badlogic.gdx.graphics.Texture;
23 import com.badlogic.gdx.graphics.g2d.Sprite;
24 import com.badlogic.gdx.graphics.g2d.SpriteCache;
25 import com.badlogic.gdx.tests.utils.GdxTest;
26 
27 public class SpriteCacheOffsetTest extends GdxTest implements InputProcessor {
28 	private int tileMapWidth = 10;
29 	private int tileMapHeight = 5;
30 	private int tileSize = 32;
31 	private SpriteCache cache;
32 	private Texture texture;
33 
create()34 	public void create () {
35 		texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg"));
36 		Sprite sprite = new Sprite(texture);
37 		sprite.setSize(tileSize, tileSize);
38 
39 		cache = new SpriteCache(1000, false);
40 		for (int y = 0; y < tileMapHeight; y++) {
41 			cache.beginCache();
42 			for (int x = 0; x < tileMapWidth; x++) {
43 				sprite.setPosition(x * tileSize, y * tileSize);
44 				cache.add(sprite);
45 			}
46 			cache.endCache();
47 			sprite.rotate90(true);
48 		}
49 	}
50 
render()51 	public void render () {
52 		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
53 		cache.begin();
54 		for (int y = 1; y < tileMapHeight - 1; y++)
55 			cache.draw(y, 1, tileMapWidth - 2);
56 		cache.end();
57 	}
58 
59 	@Override
dispose()60 	public void dispose () {
61 		cache.dispose();
62 		texture.dispose();
63 	}
64 }
65