当前位置: 首页>>代码示例>>Java>>正文


Java FlxSprite类代码示例

本文整理汇总了Java中org.flixel.FlxSprite的典型用法代码示例。如果您正苦于以下问题:Java FlxSprite类的具体用法?Java FlxSprite怎么用?Java FlxSprite使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FlxSprite类属于org.flixel包,在下文中一共展示了FlxSprite类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkOverlapRect

import org.flixel.FlxSprite; //导入依赖的package包/类
/**
 * This function checks collision detection between a circle and a normal FlxSprite,but does not resolve it!
 * @param circle you want to collide with
 * @param rect you want to collide with
 * @return whether or not there is collision detection
 */
public boolean checkOverlapRect(FlxCircleSprite circle, FlxSprite rect)
{
	FlxPoint circleDistance = new FlxPoint();
    circleDistance.x = FlxU.abs(circle.x - (rect.x + rect.width*.5f));
    circleDistance.y = FlxU.abs(circle.y - (rect.y + rect.height*.5f));
    
    //is the circle far away,then dont check collision detection
    if (circleDistance.x > (rect.width*.5f + circle.radius)) { return false; }
    if (circleDistance.y > (rect.height*.5f + circle.radius)) { return false; }

    if (circleDistance.x <= (rect.width*.5f)) { return true; } 
    if (circleDistance.y <= (rect.height*.5f)) { return true; }

    float dis = (float) (Math.pow(circleDistance.x - rect.width*.5f,2) + 
    		Math.pow(circleDistance.y - rect.height*.5f,2));

    return (dis <= Math.pow(circle.radius,2));
}
 
开发者ID:Murii,项目名称:Flixel-Libgdx-Addons,代码行数:25,代码来源:FlxCircleSprite.java

示例2: collide

import org.flixel.FlxSprite; //导入依赖的package包/类
public void collide(FlxCircleSprite circle,FlxSprite rect){
	if (checkOverlapRect(circle, rect)) {
        // Create new velocities
		float vxTotal = circle.velocity.x - rect.velocity.x;
        float vyTotal = circle.velocity.y - rect.velocity.y;        
        float newVelX1 = (circle.velocity.x + (rect.velocity.x/circle.mass));
        float newVelY1 = (circle.velocity.y + (rect.velocity.y/circle.mass));
        float newVelX2 = vxTotal + newVelX1;
        float newVelY2 = vyTotal + newVelY1;
            
        float halfW = rect.width*.5f;
        float halfH = rect.height*.5f;
        
        // Move the circles so that they don't overlap
        float midpointX = ((circle.x * halfW) + ((rect.x+halfW) * circle.radius))/(circle.radius + halfW);
        float midpointY = ((circle.y * halfH) + ((rect.y+halfH) * circle.radius))/(circle.radius + halfH);
        float dist = (float) Math.sqrt(Math.pow(circle.x - (rect.x+halfW),2) + Math.pow(circle.y - (rect.y+halfH),2));
        circle.x = midpointX + circle.radius * (circle.x - (rect.x+halfW))/dist;
        circle.y = midpointY + circle.radius * (circle.y - (rect.y+halfH))/dist;
        rect.x = midpointX + circle.radius*.5f * (rect.x-circle.radius*.5f - circle.x)/dist;
        rect.y = midpointY + circle.radius*.5f * (rect.y-circle.radius*.5f - circle.y)/dist;
        
        // Update the velocities
        circle.velocity.x = newVelX1;
        rect.velocity.y = newVelY1;
        rect.velocity.x = newVelX2;
        rect.velocity.y = newVelY2;
	}
}
 
开发者ID:Murii,项目名称:Flixel-Libgdx-Addons,代码行数:30,代码来源:FlxCircleSprite.java

示例3: create

import org.flixel.FlxSprite; //导入依赖的package包/类
@Override
public void create() {
	bg = new FlxSprite(0, 0);
	bg.makeGraphic(FlxG.width, FlxG.height, 0x111111);
	
	t = new FlxText(0, 0, 600, Rg.gameTitle);
	
	teamblacklogo = new FlxSprite();
	teamblacklogo.loadGraphic("teamblacklogo.png");
	teamblacklogo.x = (FlxG.width/2) - 104;
	teamblacklogo.y = (FlxG.height/2) - 85;
	
	gamelogo = new FlxSprite();
	gamelogo.loadGraphic("fruitswirllogo.png");
	gamelogo.x = (FlxG.width/2) - 190;
	gamelogo.y = (FlxG.height/2) - 50;
	gamelogo.visible = false;
	
	playBtn = new FlxButton(FlxG.width/2 - 35, 110, "Play", playIBtn);
	playBtn.y += 50;
	playBtn.visible = false;
	
	add(bg);
	add(t);
	add(gamelogo);
	add(playBtn);
	add(teamblacklogo);
}
 
开发者ID:guythundar,项目名称:FruitSwirl,代码行数:29,代码来源:AlphaMenuState.java

示例4: loadTiles

import org.flixel.FlxSprite; //导入依赖的package包/类
/**
 * Fills the block with a randomly arranged selection of graphics from the image provided.
 * @param	TileGraphic 	The graphic class that contains the tiles that should fill this block.
 * @param	TileWidth		The width of a single tile in the graphic.
 * @param	TileHeight		The height of a single tile in the graphic.
 * @param	Empties			The number of "empty" tiles to add to the auto-fill algorithm (e.g. 8 tiles + 4 empties = 1/3 of block will be open holes).
 */
public B2FlxTileblock loadTiles(String TileGraphic, int TileWidth, int TileHeight, int Empties)
{
	if(TileGraphic == null)
		return this;

	//First create a tile brush
	FlxSprite sprite = new FlxSprite().loadGraphic(TileGraphic,true,false,TileWidth,TileHeight);		
	int spriteWidth = (int) sprite.width;
	int spriteHeight = (int) sprite.height;
	int total = sprite.getNumFrames() + Empties;

	//Then prep the "canvas" as it were (just doublechecking that the size is on tile boundaries)
	boolean regen = false;
	if(width % sprite.width != 0)
	{
		width = (int)(width/spriteWidth+1)*spriteWidth;
		regen = true;
	}
	if(height % sprite.height != 0)
	{
		height = (int)(height/spriteHeight+1)*spriteHeight;
		regen = true;
	}
	if(regen)
		makeGraphic((int)width,(int)height,0,true);
	else
		this.fill(0);
	
	TextureData brushTextureData = sprite.framePixels.getTexture().getTextureData();
	
	if(!brushTextureData.isPrepared())
		brushTextureData.prepare();
			
	Pixmap brushPixmap = brushTextureData.consumePixmap();
	
	//Stamp random tiles onto the canvas
	int row = 0;
	int column;
	int destinationX;
	int destinationY = 0;
	int widthInTiles = (int) (width/spriteWidth);
	int heightInTiles = (int) (height/spriteHeight);
	while(row < heightInTiles)
	{
		destinationX = 0;
		column = 0;
		while(column < widthInTiles)
		{
			if(FlxG.random()*total > Empties)
			{
				sprite.randomFrame();
				sprite.drawFrame();
				stamp(brushPixmap, sprite.framePixels.getRegionX(), sprite.framePixels.getRegionY() - sprite.frameHeight, sprite.frameWidth, sprite.frameHeight, destinationX + _pixels.getRegionX(), destinationY + _pixels.getRegionY());
			}
			destinationX += spriteWidth;
			column++;
		}
		destinationY += spriteHeight;
		row++;
	}
	
	if (brushTextureData.disposePixmap())
		brushPixmap.dispose();
	
	return this;
}
 
开发者ID:flixel-gdx,项目名称:flixel-gdx-box2d,代码行数:74,代码来源:B2FlxTileblock.java

示例5: create

import org.flixel.FlxSprite; //导入依赖的package包/类
@Override
public void create()
{
	
	//level score thresholds
	levelThres[0] = 50;
	for ( int i = 1; i < 10; i++ )
		levelThres[i] += levelThres[i-1] + 50 + ( (i-1) * 25 );
	//try and score this much!
	levelThres[10] = Integer.MAX_VALUE - Rg.rng.nextInt(9999);
	
	//prep
	bg = new FlxSprite(0,0);
	bg.makeGraphic(FlxG.width, FlxG.height, 0xFF000000);
	
	t = new FlxText(0, 0, 600, Rg.gameTitle);
	
	lvlComplete = new FlxSprite();
	lvlComplete.loadGraphic("lvl_complete.png");
	lvlComplete.x = (FlxG.width/2) - (lvlComplete.width/2) + 15;
	lvlComplete.y = (FlxG.height/2) - (lvlComplete.height/2) - 40;
	
	lvlcompletetexta = new FlxText(lvlComplete.x - 75, lvlComplete.y+95, 400);
	lvlcompletetexta.setText("Nice work! This game is still only in " +
			"Alpha, so we'll add more soon (hopefully)!");
	
	lvlcompletetextb = new FlxText(lvlcompletetexta.x, lvlcompletetexta.y+20, 400);
	lvlcompletetextb.setText("To help us out, would you mind answering a" +
			" few questions about the app? Please?");
	
	lvl_ok = new FlxButton((FlxG.width/2) - 75, (FlxG.height/2)+58,
			"Take Survey", okIBtn);
	lvl_cancel = new FlxButton((FlxG.width/2) + 15, (FlxG.height/2)+58,
			"Keep Playing", cancelIBtn);
	
	pauseStuff.add(lvlComplete);
	pauseStuff.add(lvlcompletetexta);
	pauseStuff.add(lvlcompletetextb);
	pauseStuff.add(lvl_cancel);
	pauseStuff.add(lvl_ok);
	
	g = new Grid();
	g.makeFirstBoard();
	g.initGravityPoints();
	
	lvlText = new FlxText(g.minPoint.x, g.maxPoint.y + Fruit.SIZE_Y + 3, 50, "Level: 1");
	scoreText = new FlxText(lvlText.x + 50, lvlText.y, 200, "Score: 0");
	
	Rg.spinner.alignToGridMember(g.getFirstVisible());
	
	//gridPoints for debugging
	for (int i = 0; i < g.gravityPoints.size(); i++){
		FlxSprite s = new FlxSprite(g.gravityPoints.get(i).x,
									g.gravityPoints.get(i).y);
		s.makeGraphic(2, 2, Color.GRAY.toIntBits());
		guideGridPoints.add(s);
	}
	
	gameStuff.add(g.bg);
	gameStuff.add(Rg.spinner);
	gameStuff.add(g.fruits);
	gameStuff.add(guideGridPoints);
	gameStuff.add(scoreText);
	gameStuff.add(lvlText);
	
	//render
	add(bg);
	add(gameStuff);
	add(pauseStuff);
	add(t);
	
	pauseStuff.setAll("visible", false);
	
}
 
开发者ID:guythundar,项目名称:FruitSwirl,代码行数:75,代码来源:PlayState.java


注:本文中的org.flixel.FlxSprite类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。