<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Java Bulgaria &#187; Java Game Development</title>
	<atom:link href="http://javabg.eu/category/java-game-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://javabg.eu</link>
	<description>Всичко за Java</description>
	<lastBuildDate>Tue, 24 Jan 2012 16:46:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Developing Applications with JBoss and Hibernate: Part 1</title>
		<link>http://javabg.eu/2010/02/developing-applications-with-jboss-and-hibernate-part-1/</link>
		<comments>http://javabg.eu/2010/02/developing-applications-with-jboss-and-hibernate-part-1/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 18:04:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Java Game Development]]></category>
		<category><![CDATA[английски]]></category>
		<category><![CDATA[уроци]]></category>

		<guid isPermaLink="false">http://javabg.eu/?p=357</guid>
		<description><![CDATA[In this article, by Francesco Marchioni, we will introduce Hibernate, which is the de facto standard object-relational mapping framework for Java applications. The Hibernate galaxy is quite large and needs a book of its own to be fully explored. Our mission will be to take over one sector of this galaxy, especially where Hibernate applications [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<blockquote><p><em>In this article, by <strong>Francesco Marchioni</strong>, we  will introduce Hibernate, which is the <em>de facto</em> standard  object-relational mapping framework for Java applications. The Hibernate  galaxy is quite large and needs a book of its own to be fully explored.  Our mission will be to take over one sector of this galaxy, especially  where Hibernate applications are managed by JBoss AS.</p>
<p>In this two-part article, we will cover the following topics:</p>
<ul>
<li>A short introduction to Hibernate</li>
<li>Setting up our proof of concept for the Hibernate project</li>
<li>Reverse engineering a database schema into Hibernate POJOs and  mapping files</li>
<li>Deploying the application to JBoss AS</li>
<li>Comparing the Hibernate technology with EJB 3 persistence (JPA)</li>
</ul>
<p></em></p></blockquote>
<h1>Introducing Hibernate</h1>
<p>Hibernate provides a bridge between the  database and the application by persisting application objects in the  database, rather than requiring the developer to write and maintain lots  of code to store and retrieve objects.</p>
<p>The main configuration  file, <em>hibernate.cfg.xml</em>, specifies how Hibernate obtains database  connections, either from a JNDI DataSource or from a JDBC connection  pool. Additionally, the configuration file defines the persistent  classes, which are backed by mapping definition files.</p>
<p>This is a  sample <em>hibernate.cfg.xml</em> configuration file that is used to  handle connections to a MySQL database, mapping the <em>com.sample.MySample</em> class.</p>
<pre style="margin-left: 40px;">&lt;hibernate-configuration&gt;
&lt;session-factory&gt;
&lt;property name="connection.username"&gt;user&lt;/property&gt;
&lt;property name="connection.password"&gt;password&lt;/property&gt;
&lt;property name="connection.url"&gt;
 jdbc:mysql://localhost/database
&lt;/property&gt;
&lt;property name="connection.driver_class"&gt;
 com.mysql.jdbc.Driver
&lt;/property&gt;
&lt;property name="dialect"&gt;
 org.hibernate.dialect.MySQLDialect
&lt;/property&gt;
&lt;mapping resource="com/sample/MyClass.hbm.xml"/&gt;
&lt;/session-factory&gt;
&lt;/hibernate-configuration&gt;</pre>
<p>From  our point of view, it is important to know that Hibernate applications  can coexist in both the <strong>managed</strong> environment and the <strong>non-managed</strong> environment. An application server is a typical example of a managed  environment that provides services to hosting applications, such as  connection pooling and transaction.</p>
<p>On the other hand, a  non-managed application refers to standalone applications, such as Swing  Java clients that typically lack any built-in service.</p>
<p>In this  article, we will focus on managed environment applications, installed on  JBoss Application Server. You will not need to download any library to  your JBoss installation. As a matter of fact, JBoss persistence layer is  designed around Hibernate API, so it already contains all the core  libraries.</p>
<h1>Creating a Hibernate application</h1>
<p>You can choose  different strategies for building a Hibernate application. For example,  you could start building Java classes and map files from scratch, and  then let Hibernate generate the database schema accordingly. You can  also start from a database schema and reverse engineer it into Java  classes and Hibernate mapping files. We will choose the latter option,  which is also the fastest. Here&#8217;s an overview of our application.</p>
<p>In  this example, we will design an employee agenda divided into  departments. The persistence model will be developed with Hibernate,  using the reverse engineering facet of JBoss tools. We will then need an  interface for recording our employees and departments, and to query  them as well.</p>
<p>The web interface will be developed using a simple <strong>Model-View-Controller</strong> (<strong>MVC</strong>) pattern and basic JSP 2.0 and servlet features.</p>
<p>The  overall architecture of this system resembles the AppStore application  that has been used to introduce JPA. As a matter of fact, this example  can be used to compare the two persistence models and to decide which  option best suits your project needs. We have added a short section at  the end of this example to stress a few important points about this  choice.</p>
<h2>Setting up the database schema</h2>
<p>The overall  architecture of this system resembles the AppStore application that has  been used to introduce JPA. As a matter of fact, this example can be  used to compare the two persistence models and to decide which option  best suits your project needs. We have added a short section at the end  of this example to stress a few important points about this choice.</p>
<pre style="margin-left: 40px;">CREATE schema hibernate;
GRANT ALL PRIVILEGES ON hibernate.* TO 'jboss'@'localhost' WITH GRANT
OPTION;
CREATE TABLE `hibernate`.`department` (
`department_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`department_name` VARCHAR(45) NOT NULL,
PRIMARY KEY (`department_id`)
)
ENGINE = InnoDB;
CREATE TABLE `hibernate`.`employee` (
`employee_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`employee_name` VARCHAR(45) NOT NULL,
`employee_salary` INTEGER UNSIGNED NOT NULL,
`employee_department_id` INTEGER UNSIGNED NOT NULL,
PRIMARY KEY (`employee_id`),
CONSTRAINT `FK_employee_1` FOREIGN KEY `FK_employee_1` (`employee_
department_id`)
REFERENCES `department` (`department_id`)
ON DELETE CASCADE
ON UPDATE CASCADE
)
ENGINE = InnoDB;</pre>
<p>With  the first <strong>Data Definition Language</strong> (<strong>DDL</strong>) command, we have  created a schema named Hibernate that will be used to store our tables.  Then, we have assigned the necessary privileges on the Hibernate schema  to the user jboss.</p>
<p>Finally, we created a table named <em>department</em> that contains the list of company units, and another table named <em>employee</em> that contains the list of workers. The <em>employee</em> table references  the <em>department</em> with a foreign key constraint.</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/jboss5-article2-image01.png" alt="" /></p>
<h2>A new Eclipse project</h2>
<p>Now start Eclipse. You don&#8217;t have a  specific project for Hibernate applications, so a utility project (which  simply packs the classes in an archive) will be enough. You can reach  this option from the menu by going to <strong>New</strong> | <strong>Other</strong> | <strong>Java  EE</strong> | <strong>Utility Project</strong>.</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/jboss5-article2-image02.png" alt="" /></p>
<p>Name  the project <strong>HibernateProject</strong> and target it to <strong>JBoss AS 5.0  Runtime</strong>. You can leave the default JBoss AS configuration and hit <strong>Finish</strong>.</p>
<p>Now,  we are going to unleash the full potential of <strong>Hibernate tools</strong>.  Select from the menu <strong>New</strong> | <strong>Other</strong> | <strong>Hibernate</strong> | <strong>Hibernate  Configuration File</strong>. The Hibernate configuration contains all of the  details for wiring your application to the database. You will be asked  for the name and the parent folder of the configuration file. Accept the  default <em>hibernate.cfg.xml</em> at the root of your project.</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/jboss5-article2-image03.png" alt="" /></p>
<p>Next,  insert the details of your Hibernate configuration. Choose a name for  your <strong>SessionFactory</strong>, which will contain your MySQL connection  facets. Remember to check the flag <strong>Create a console configuration</strong>,  so that the wizard will complete the console configuration as the next  step.</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/jboss5-article2-image04.png" alt="" /></p>
<p>A  <strong>console configuration</strong> describes how the Hibernate plugin should  interact with Hibernate and what configuration files (including the  classpath) are needed to load the POJOs, JDBC drivers, and so on. This  step is required to make use of query prototyping, reverse engineering,  and code generation.</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/jboss5-article2-image05.png" alt="" /></p>
<p>The  console wizard will look at the current selection in the IDE and will  try to autodetect the settings, which you can approve or modify to suit  your needs. For example, you don&#8217;t need to enter the <strong>Configuration  file</strong> or the <strong>Property file</strong> if you have just one in your  project; Eclipse will select it automatically.</p>
<p>One important  selection is the <strong>Type</strong> option that lets you choose between the <strong>Core</strong> hibernate configuration (Java classes backed by mapping files), <strong>Annotations</strong>,  or even <strong>JPA</strong> annotations. We will leave the selected <strong>Core</strong> option.</p>
<p>Before clicking <strong>Finish</strong>, select <strong>MySQL</strong> (<strong>InnoDB</strong>)  as <strong>Database dialect</strong> in the <strong>Options</strong> tab. No other changes  are required.</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/jboss5-article2-image06.png" alt="" /></p>
<p>Now  verify that you have successfully linked to Hibernate by switching to <strong>Hibernate  Perspective</strong>. This view will be composed by a tree of three objects:<strong> Configuration</strong>, <strong>Session Factory</strong>, and <strong>Database</strong>. Choose <strong>Database</strong> and verify that it expands correctly to show the database tables of  your schema.</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/jboss5-article2-image07.png" alt="" /></p>
<p>If  you fail to browse the database schema, check that you have correctly  set up your Hibernate configuration.</p>
<h2>Reversing your schema into  Java classes</h2>
<p>The next move will be reversing our database schema  into Java classes and mapping files. This powerful feature is available  from the menu: <strong>File</strong> | <strong>New</strong> |<strong> Hibernate</strong> | <strong>Hibernate  Reverse Engineering file</strong>. You can place this file in a convenient  location for your project and choose a name for it. The default name  proposed is <em>hibernate.reveng.xml</em>, which looks rather the tile of  another fiction movie from G. Lucas.</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/jboss5-article2-image08.png" alt="" /></p>
<p>On  the next page, select your <strong>Console configuration</strong> and choose the  tables that will be included in your reverse engineering process. (Hint:  You have to hit <strong>Refresh</strong> first to show the database schema and  then click <strong>Include&#8230;</strong>.)</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/jboss5-article2-image09.png" alt="" /></p>
<p>What  Eclipse has just created for you is a file named <em>hibernate.reveng.xml</em> that should resemble the following code snippet:</p>
<pre style="margin-left: 40px;">&lt;hibernate-reverse-engineering&gt;
&lt;table-filter match-catalog="hibernate" match-name="department"/&gt;
&lt;table-filter match-catalog="hibernate" match-name="employee"/&gt;
&lt;/hibernate-reverse-engineering&gt;</pre>
<p>If  you are smart at noticing variations, you might have discovered a new  icon in your toolbar. This is your gateway to the reverse engineering  process. (Notice: this icon is visible only in the Hibernate  Perspective, you will not be able to find it anywhere else.)</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/jboss5-article2-image10.png" alt="" /></p>
<p>Click  on Hibernate&#8217;s down arrow icon and select <strong>Hibernate Code Generation  Configurations</strong>. In the next dialog, you will first have to create a  new <strong>Hibernate Code Generation Configuration</strong> that will contain all  the details of your reverse engineering process. Click on the <strong>New</strong> button located in the left corner of the wizard.</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/jboss5-article2-image11.png" alt="" /></p>
<p>Now,  select your brand new configuration and carefully choose the following  options. First, wire the <strong>Console configuration</strong> to your project  (HibernateProject). Then, choose an output directory for your generated  files. We would suggest you to point to your <em>src</em> folder. (Be  aware that existing files will be overwritten, that&#8217;s why I just said  you have to be <em>careful!</em>)</p>
<p>Just below, you will find the  checkbox <strong>Reverse engineer from JDBC Connection</strong>. If enabled, the  tools will reverse engineer the available database using the connection  information in the selected Hibernate Console configuration. Check this  option and enter the package name for the generated classes, which will  be <strong>com.packtpub.hibernate</strong>. Leave the other text fields to the  defaults and move to the tab <strong>Exporters</strong>.</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/jboss5-article2-image12.png" alt="" /></p>
<p>The  <strong>Exporters</strong> tab menu is used to specify which type of code should  be generated. Each selection represents an Exporter that is responsible  for generating the code, hence the name.</p>
<p>In the upper area of the  dialog, you will notice an interesting checkbox named <strong>Generate EJB 3  annotations</strong>. We will return to this useful option later. At the  moment, what we need is just to check the <strong>Domain code</strong> and <strong>Hibernate  XML Mappings</strong> options, which will generate the Java POJOs and  mapping files respectively.</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/jboss5-article2-image13.png" alt="" /></p>
<p>It  took a bit of time to complete all of these steps; however, now your  Java classes and configuration files are handy and waiting to be  packaged.</p>
<h2>Adding Hibernate configuration to your project</h2>
<p>The  advantage of embedding the Hibernate application in JBoss AS is that  you can expose <strong>Hibernate SessionFactory</strong> through a JNDI tree and  modify its configuration at runtime.</p>
<p>This is indeed a great  configuration advantage; before the new release of JBoss AS, you had to  delegate to an MBean the creation of the Hibernate <em>SessionFactory</em> and its exposure through JNDI.</p>
<p>For example, if you wanted to  configure a <em>SessionFactory</em> at the naming context <em>hibernate/SessionFactory</em>,  you would have to package your Hibernate application with a file named <em>xxx-service.xml</em> in the <em>META-INF</em> folder. Here&#8217;s a sample of it:</p>
<pre style="margin-left: 40px;">&lt;server&gt;
&lt;mbean code="org.jboss.hibernate.jmx.Hibernate"
name="jboss.har:service=Hibernate"&gt;
&lt;attribute name="DatasourceName"&gt;java:/ MySqlDS&lt;/attribute&gt;
&lt;attribute name="Dialect"&gt;
org.hibernate.dialect.MySQLDialect
&lt;/attribute&gt;
&lt;attribute name="SessionFactoryName"&gt;
java:/hibernate/SessionFactory
&lt;/attribute&gt;
&lt;attribute name="CacheProviderClass"&gt;
org.hibernate.cache.HashtableCacheProvider
&lt;/attribute&gt;
&lt;/mbean&gt;
&lt;/server&gt;</pre>
<p>This  configuration is still valid for pre 5.0 releases of JBoss AS. With the  introduction of the new <strong>Virtual Deployment Framework</strong> (<strong>VDF</strong>),  you now have to provide your <strong>SessionFactory</strong> configuration using  the Hibernate XML schema. For example, if you want to link your <em>SessionFactory</em> to your MySQL database, you have to add the following <em>service-hibernate.xml</em>.  (Be aware, the suffix is <em>-hibernate.xml</em> and not <em>–service.xml</em>.)</p>
<pre style="margin-left: 40px;">&lt;hibernate-configuration xmlns="urn:jboss:hibernate-deployer:1.0"&gt;
&lt;session-factory name="java:/hibernate/SessionFactory"
bean="jboss.test.har:service=Hibernate,
testcase=TimersUnitTestCase"&gt;
&lt;property name="datasourceName"&gt;java:/MySqlDS&lt;/property&gt;
&lt;property name="dialect"&gt;
org.hibernate.dialect.MySQLDialect
&lt;/property&gt;
&lt;depends&gt;jboss:service=Naming&lt;/depends&gt;
&lt;depends&gt;jboss:service=TransactionManager&lt;/depends&gt;
&lt;/session-factory&gt;
&lt;/hibernate-configuration&gt;</pre>
<p>The  preceding configuration file needs to be stored in the <em>META-INF</em> folder of your <strong>Hibernate archive</strong> (<strong>HAR</strong>) file. The structure  of the updated project from the <strong>Package Explorer</strong> is as shown in  the following snapshot:</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/jboss5-article2-image14.png" alt="" /></p>
<img src="http://javabg.eu/?ak_action=api_record_view&id=357&type=feed" alt="" />

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://javabg.eu/2010/02/developing-applications-with-jboss-and-hibernate-part-1/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>First demo of Flixel on Android</title>
		<link>http://javabg.eu/2010/02/first-demo-of-flixel-on-android/</link>
		<comments>http://javabg.eu/2010/02/first-demo-of-flixel-on-android/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 17:55:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Java Game Development]]></category>
		<category><![CDATA[английски]]></category>
		<category><![CDATA[уроци]]></category>

		<guid isPermaLink="false">http://javabg.eu/?p=355</guid>
		<description><![CDATA[Demo The last article showed you how to get a minimal Flixel game running on Android. Here we will add a player controlled character that will run and jump on the screen. First we need a way to move from the MenuState to a new state called GameState. To do this we override the update [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<blockquote><p><strong>Demo</strong></p>
<p><embed height="500px" width="500px" name="plugin" src="http://www.brighthub.com/cfs-filesystemfile.ashx/__key/CommunityServer.Components.PostAttachments/00.00.06.04.46/andriod-flixel.swf" type="application/x-shockwave-flash"></p></blockquote>
<p>The last article showed you how to get a minimal Flixel game running  on Android. Here we will add a player controlled character that will run  and jump on the screen.</p>
<p>First we need a way to move from the MenuState to a new state called  GameState. To do this we override the update function in the MenuState  class and watch for a keypress which we will use as a trigger to swap to  the GameState.</p>
<p>Most of the Flixel classes have an update function, and it is in this  function that an object can update itself, usually by modifying the  underlying physics properties like acceleration and velocity and (as is  the case here) watching for input.</p>
<p>For those not familiar with Flixel, FlxG is a kind of utility class  that contains a number of static functions and properties giving the  developer easy access to things like state changes, keyboard input and  more.</p>
<p><strong>MenuState.java</strong></p>
<pre>package org.myname.flixeldemo;

import org.flixel.*;

import android.view.KeyEvent;

public class MenuState extends FlxState
{
 public MenuState()
 {
  super();
  add(new FlxText(10, 10, 250, "Press the center DPad key to continue."));
 }

<strong> public void update()
 {
  super.update();
  if (FlxG.keys.justPressed(KeyEvent.KEYCODE_DPAD_CENTER))
   FlxG.switchState(GameState.class);
 }</strong>
}</pre>
<p>Obviously we now need a state called GameState to switch to.</p>
<p><strong>GameState.java</strong></p>
<pre>package org.myname.flixeldemo;

import java.util.ArrayList;

import org.flixel.*;</pre>
<p>Just like the MenuState, the GameState class extends the FlxState  class.</p>
<pre>public class GameState extends FlxState
{
 protected ArrayList levelBlocks = new ArrayList();
 protected Player player = null;

 public GameState()
 {</pre>
<p>The level is made up of FlxBlock objects, which are blocks that are  placed in the level space. These blocks are used in collision detection  to give the player a surface to walk on. Here we create a long  horizontal block to serve as the ground, load the tech_tiles.png image  to display the block, and then add the block to both to the state (all  objects that need to be rendered and updated need to be added to the  state) and a local collection called levelBlocks.</p>
<pre>  FlxBlock ground = new FlxBlock(0, 640-16, 640, 16);
  ground.loadGraphic(R.drawable.tech_tiles);
  levelBlocks.add(this.add(ground));</pre>
<p>We then create a new player object, which will be detailed later. We  then ask Flixel to keep the player in front of the “camera” using the  FlxG follow function. The followAdjust function makes the camera lag  behind the movement of the player slightly, while the followBounds  function defines the limit of the cameras movement across the level.</p>
<pre>  player = new Player();
  this.add(player);
  FlxG.follow(player, 2.5f);
  FlxG.followAdjust(0.5f, 0.0f);
  FlxG.followBounds(0, 0, 640, 640);</pre>
<p>Finally we play some background music.</p>
<pre>  FlxG.playMusic(R.raw.mode);
 }</pre>
<p>In the update function we need to check for a collision between the  player and the blocks that make up the level. The collideArrayList  function will test the players position against the level blocks (this  is why we added the blocks to a local collection), and will push the  player out of the blocks if there is a collision.</p>
<pre> public void update()
 {
  super.update();
  FlxG.collideArrayList(levelBlocks, player);
 }
}</pre>
<p>The Player class represents the player on the screen.</p>
<p><strong>Player.java</strong></p>
<pre>package org.myname.flixeldemo;

import java.util.ArrayList;
import java.util.Arrays;
import android.view.*;

import org.flixel.*;</pre>
<p>We extend the FlxSprite class, which will allow us to draw a static  or animated sprite on the screen.</p>
<pre>public class Player extends FlxSprite
{
 protected static final int PLAYER_START_X = 300;
 protected static final int PLAYER_START_Y = 300;
 protected static final int PLAYER_RUN_SPEED = 80;
 protected static final float GRAVITY_ACCELERATION = 420;
 protected static final float JUMP_ACCELERATION = 200;

 public Player()
 {</pre>
<p>We start by calling the underlying FlxSrpite constructor, passing in  the initial position of the sprite, the image that will be used to  display the sprite, and true to indicate that the sprite should be  automatically reversed when it is facing left (by default the source  images for all Flixel sprites should be drawn facing right).</p>
<pre>  super(PLAYER_START_X, PLAYER_START_Y, R.drawable.spaceman, true);</pre>
<p>The physics for the player are defined. The drag, maxVelocity and  acceleration defines how the player will move and fall in the level.</p>
<pre>  drag.x = PLAYER_RUN_SPEED * 8;
  acceleration.y = GRAVITY_ACCELERATION;
  maxVelocity.x = PLAYER_RUN_SPEED;
  maxVelocity.y = JUMP_ACCELERATION;</pre>
<p>The final step is to define the animations and the frames that they  will use from the source image that is used to display the sprite. You  can see this image <a rel="nofollow" href="http://farm3.static.flickr.com/2704/4243937042_aba8924f14_o.png">here</a>.</p>
<p>As you can see this image is like a film strip. Each of these  individual frames of animation are mapped to an animation like “run” or  “fall”. The code to initialise a Java collection from an inline array is  a little messy, but all we are doing is saying something like “map  frames 0, 1, 2 to the animation called run”.</p>
<pre>  addAnimation("idle", new ArrayList(Arrays.asList(new Integer[] {0})));
  addAnimation("run",  new ArrayList(Arrays.asList(new Integer[] {1, 2, 3, 0})), 12);
  addAnimation("jump",  new ArrayList(Arrays.asList(new Integer[] {4})));
  addAnimation("idle_up",  new ArrayList(Arrays.asList(new Integer[] {5})));
  addAnimation("run_up",  new ArrayList(Arrays.asList(new Integer[] {6, 7, 8, 5})), 12);
  addAnimation("jump_up",  new ArrayList(Arrays.asList(new Integer[] {9})));
  addAnimation("jump_down",  new ArrayList(Arrays.asList(new Integer[] {10})));
 }</pre>
<p>In the update function we use the keyboard input to modify the  acceleration and velocity of the player, which will in turn be used to  modify the position of the player on the screen.</p>
<pre> public void update()
 {
  acceleration.x = 0;
  if(FlxG.keys.pressed(KeyEvent.KEYCODE_DPAD_LEFT))
  {
   setFacing(LEFT);
   acceleration.x = -drag.x;
  }
  else if(FlxG.keys.pressed(KeyEvent.KEYCODE_DPAD_RIGHT))
  {
   setFacing(RIGHT);
   acceleration.x = drag.x;
  }
  if(FlxG.keys.justPressed(KeyEvent.KEYCODE_DPAD_UP) &amp;&amp; velocity.y==0)
  {
   velocity.y = -JUMP_ACCELERATION;
  }</pre>
<p>We then use the velocity of the player to determine which animation  should be playing.</p>
<pre>  if(velocity.y != 0)
  {
   play("jump");
  }
  else if(velocity.x == 0)
  {
   play("idle");
  }
  else
  {
   play("run");
  }

  super.update();
 }
}</pre>
<img src="http://javabg.eu/?ak_action=api_record_view&id=355&type=feed" alt="" />

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://javabg.eu/2010/02/first-demo-of-flixel-on-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a Flash platform game with Flixel and Flex &#8211; Enemies</title>
		<link>http://javabg.eu/2010/02/creating-a-flash-platform-game-with-flixel-and-flex-enemies/</link>
		<comments>http://javabg.eu/2010/02/creating-a-flash-platform-game-with-flixel-and-flex-enemies/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 17:52:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Java Game Development]]></category>
		<category><![CDATA[английски]]></category>
		<category><![CDATA[уроци]]></category>

		<guid isPermaLink="false">http://javabg.eu/?p=349</guid>
		<description><![CDATA[Demo To give the player something to do we will add some enemies. These enemies will be quite dumb, simply moving left and right across the top of the blocks we have added. Even though this is not particularly advanced behaviour, it was fairly common with a lot of old 8/16 bit platform games. First [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p><strong></p>
<blockquote><p>Demo<br />
<embed height="500px" width="500px" name="plugin" src="http://www.brighthub.com/cfs-filesystemfile.ashx/__key/CommunityServer.Components.PostAttachments/00.00.06.10.78/main.swf" type="application/x-shockwave-flash">
</p></blockquote>
<p></strong></p>
<p>To give the player something to do we will add  some enemies. These enemies will be quite dumb, simply moving left and  right across the top of the blocks we have added. Even though this is  not particularly advanced behaviour, it was fairly common with a lot of  old 8/16 bit platform games.</p>
<p>First up we define a constant that controls how many enemies will be  added to the level in the <strong>GameState </strong>class.</p>
<pre>protected static const ENEMY_COUNT:uint = 10;</pre>
<p>Then we add a <strong>FlxArray </strong>to hold the new enemies.</p>
<pre>protected var enemies:FlxArray = new FlxArray();</pre>
<p>We then make a call to the new function <strong>addEnemies</strong> in the constructor (after we have added the blocks to the level).</p>
<pre>public function GameState()
{
 // ...

 for (var j:uint = 0; j &lt; NUMBER_RANDOM_BLOCKS; ++j)
  addRandomBlocks();

 addEnemies();

 // ...
}</pre>
<p>The addEnemies function will place the enemies on top of the blocks  randomly throughout the level. However, we can’t place an enemy on top  of any block, because there is a good chance that two blocks have been  placed in top of each other, meaning there is no room for our enemy.</p>
<pre>protected function addEnemies():void
{
 var enemyCount:uint = 0;

 for each (var block1:FlxBlock in this.levelBlocks)
 {
  var enemyStartX:Number = block1.x;
  var enemyStartY:Number = block1.y;
  var collides:Boolean = false;

  for each (var block2:FlxBlock in this.levelBlocks)
  {
   var xCollision:int = enemyStartX + (BLOCK_DIMENSIONS&gt;&gt;1);
   var xCollision2:int = xCollision + BLOCK_DIMENSIONS;
   var yCollision:int = enemyStartY - (BLOCK_DIMENSIONS&gt;&gt;1);
   var yCollision2:int = yCollision - BLOCK_DIMENSIONS;

   if (block1 !== block2 &amp;&amp;
    (block2.overlapsPoint(xCollision, yCollision) ||
    block2.overlapsPoint(xCollision, yCollision2) ||
    block2.overlapsPoint(xCollision2, yCollision) ||
    block2.overlapsPoint(xCollision2, yCollision2)))
   {
    collides = true;
    break;
   }
  }</pre>
<p>To check this we loop through the level blocks twice. This way we can  test each block for a collision in the space above it with every other  block in the level. We need to find a block where a 2&#215;2 block area (so  16&#215;16 pixels) above the top left corner is free (this is because our  enemies take up the space of 4 blocks).</p>
<p>To test this we need to test 4 points in space. The first will be  half a block up, and half a block across. This effectively tests the  area highlighted in red below.</p>
<p>If you are not familiar with it, the <strong>&gt;&gt;</strong> operator is called a bit shift. The actual details of this operator are  not important; all you need to know is that by calling <strong>&gt;&gt;1</strong> on an int you are effectively halving its value. It is more efficient  that calling <strong>BLOCK_DIMENSIONS/2</strong>, and you get to impress  all your friends with an obscure operation.</p>
<p><img src="http://farm3.static.flickr.com/2740/4164882854_13eff8f082_o.png" alt="" /></p>
<p>We then test the area of the next block up.</p>
<p><img src="http://farm3.static.flickr.com/2510/4164125921_01a35487a4_o.png" alt="" /></p>
<p>Then we repeat the process one block to the right.</p>
<p><img src="http://farm3.static.flickr.com/2585/4164125937_e56706d17c_o.png" alt="" /><img src="http://farm3.static.flickr.com/2518/4164882932_9cb5e4558a_o.png" alt="" /></p>
<p>In the example above, the block at the bottom of the image would not  be suitable for an enemy placement because there is a collision with the  second test. This sets the <strong>collision</strong> flag to true,  which means we do not add an enemy here.</p>
<pre>  if (!collides &amp;&amp; enemyStartX &gt; 0 &amp;&amp; enemyStartY &gt; 0)
  {
   enemies.add(this.add(new Enemy(enemyStartX, enemyStartY, block1.width)));
   ++enemyCount;
  }

  if (enemyCount &gt;= ENEMY_COUNT)
   break;
 }
}</pre>
<p>If the space above the block was clear we then create a new <strong>Enemy</strong>,  which is added both to the <strong>GameState</strong> and to the <strong>enemies </strong>collection. We increment the <strong>enemyCount</strong> counter, and then either place the next enemy, or if they have all been  placed break out of the loop.</p>
<pre>public override function update():void
{
 super.update();
 FlxG.collideArray(levelBlocks, player);
 FlxG.collideArrays(playerBullets, levelBlocks);
 FlxG.collideArrays(enemies, levelBlocks);
 FlxG.overlapArrays(playerBullets,enemies,bulletHitEnemy);
}</pre>
<p>The enemies will collide with the level blocks, and with the players  bullets. In the <strong>update </strong>function we test for these  collisions. For the bullet / enemy collision, we set the <strong>bulletHitEnemy </strong>function to be called in the event of a collision.</p>
<pre>private function bulletHitEnemy(Bullet:FlxSprite,Bot:FlxSprite):void
{
 Bullet.hurt(0);
 Bot.hurt(1);
}</pre>
<p>In the <strong>bulletHitEnemy </strong>function we call the <strong>hurt </strong>function on both the bullet and the enemy. This will remove  the bullet from the level, and cause the enemy to suffer some damage. If  the enemy suffers enough damage it will then be killed.</p>
<p>Next we need to create the <strong>Enemy </strong>class.</p>
<pre>package
{
 import org.flixel.*;

 public class Enemy extends FlxSprite
 {
  [Embed(source="../media/enemy.png")]
  protected var EnemyImage:Class;

  [Embed(source="../media/enemygibs.png")]
  protected var EnemyGibsImage:Class;

  protected static const ENEMY_SPEED:Number = 20;
  protected static const ENEMY_HEALTH:int = 2;</pre>
<p>To start with we embed some images, one for the enemy itself, and one  for the gibs that will fly when the enemy is killed. We also specify  some constants the define the enemy’s health and speed.</p>
<pre>  protected var startingX:int;
  protected var maxHorizontalMovement:int;
  protected var gibs:FlxEmitter;</pre>
<p>The <strong>startingX</strong> variable stores the starting position  of the enemy. Since all enemies start at the left of a block, and we  know how wide a block is, we can use starting with the enemies current  position to determine when it should move back to the right to avoid  falling off the edge.</p>
<p>The <strong>maxHorizontalMovement</strong> variable is the width of  the underlying block. This, in combination with the <strong>startingX</strong> variable, stops the enemies moving off the edge of the block.</p>
<p>The <strong>gibs</strong> variable will hold a FlxEmitter, which is  like a particle system, which will be display an explosion of gibs when  the enemy is destroyed.</p>
<pre>  public function Enemy(X:int, Y:int, maxHorizontalMovement:int)
  {
   super(EnemyImage, X, Y, true);

   this.y -= this.height;
   this.startingX = X;
   this.maxHorizontalMovement = maxHorizontalMovement - this.width;
   this.velocity.x = ENEMY_SPEED;
   this.health = ENEMY_HEALTH;
   this.gibs = FlxG.state.add(new FlxEmitter(0,0,0,0,null,-1.5,-150,150,-200,
      0,-720,720,400,0,EnemyGibsImage,20,true)) as FlxEmitter;

   addAnimation("anim", [0, 1], 12);
   this.play("anim");
  }</pre>
<p>All of this code is straight forward. We simply setup the underlying <strong>FlxSprite </strong>variables along with those we specified ourselves, and then  setup the enemy’s animation. We also create a new <strong>FlxEmitter</strong>,  which will display the shower of gibs when the enemy dies.</p>
<pre>  public override function update():void
  {
   super.update();

   if (this.x - this.startingX &gt;= maxHorizontalMovement)
   {
    this.x = this.startingX + maxHorizontalMovement;
    this.velocity.x = -ENEMY_SPEED;
   }
   else if (this.x - this.startingX &lt;= 0)
   {
    this.x = this.startingX;
    this.velocity.x = ENEMY_SPEED;
   }
  }</pre>
<p>In the <strong>update</strong> function we change the velocity of the  enemy if it has moved over the edge of the underlying block.</p>
<pre>  public override function hitWall(Contact:FlxCore=null):Boolean
  {
   this.velocity.x = -this.velocity.x;
   return true;
  }</pre>
<p>The <strong>hitWall</strong> function will be called if the enemy has  hit a wall. Since we know the path is clear over the left of the  underlying block, this means that the enemy hit a block as it moved  right. In this case we simply set the velocity to move the enemy back to  the left.</p>
<pre>  public override function kill():void
  {
   super.kill();

   this.gibs.x = this.x + (this.width&gt;&gt;1);
   this.gibs.y = this.y + (this.height&gt;&gt;1);
   this.gibs.restart();
  }

 }
}</pre>
<p>The <strong>kill</strong> function is called once the enemy’s health  has dropped to 0. Managing the health value is all taken care of by the  underlying <strong>FlxSprite</strong> class. Calling the <strong>FlxSprite</strong> <strong>kill</strong> function will remove the enemy from the level. We  then position the <strong>FlxEmitter</strong> referenced by the <strong>gibs</strong> variable to the enemy’s last position, and call restart to play the  effect.</p>
<img src="http://javabg.eu/?ak_action=api_record_view&id=349&type=feed" alt="" />

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://javabg.eu/2010/02/creating-a-flash-platform-game-with-flixel-and-flex-enemies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a game on Google Android game with Flixel &#8211; Getting Started</title>
		<link>http://javabg.eu/2010/02/creating-a-game-on-google-android-game-with-flixel-getting-started/</link>
		<comments>http://javabg.eu/2010/02/creating-a-game-on-google-android-game-with-flixel-getting-started/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 17:47:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Java Game Development]]></category>
		<category><![CDATA[английски]]></category>
		<category><![CDATA[уроци]]></category>

		<guid isPermaLink="false">http://javabg.eu/?p=347</guid>
		<description><![CDATA[The iPhone has taken the world by storm, but with the backing of Google the Android platform is picking up steam and has a bright future ahead of it. But while there are dozens of tools to create games on the iPhone, Android has only a few examples showing how to make a game, and [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<div>
<p>The iPhone has taken the world by storm, but  with the backing of Google the Android platform is picking up steam and  has a bright future ahead of it. But while there are dozens of tools to  create games on the iPhone, Android has only a few examples showing how  to make a game, and I could not find any decent engines or middleware on  which to build a game on Android.</p>
<p>Flixel is a game engine for Flash that I have used quite a bit  lately, and after my experiences <a rel="nofollow" href="http://www.brighthub.com/hubfolio/matthew-casperson/blog/archive/2009/11/29/flixel-for-silverlight.aspx">porting  it to Silverlight</a> I felt confident that Flixel would make a great  platform for Android on which to make games. This tutorial series will  show you how to make your own simple platform game on Android using the  ported Flixel engine.</p>
<h3>Step 1</h3>
<p>Download a copy of Eclipse from <a rel="nofollow" href="http://www.eclipse.org/downloads/">here</a>, and then download  both the Android SDK and the Eclipse plugins from the Android site <a rel="nofollow" href="http://developer.android.com/sdk/index.html">here</a>. You can  find step by step instructions on how to do this on the Android  developer site.</p>
<h3>Step 2</h3>
<p>Start Eclipse once the Android plugins for Eclipse have been  installed. Open Window-&gt;Preferences.</p>
<p><a rel="nofollow" href="http://farm5.static.flickr.com/4041/4243306494_1f4c572636_o.png"><img src="http://farm5.static.flickr.com/4041/4243306494_edca748b86.jpg" alt="" /></a></p>
<p>In the Android section browse to the location where you extracted the  Andorid SDK and click the Apply button. The SDK should then be listed.</p>
<p><img src="http://farm3.static.flickr.com/2781/4242534287_253d03f615.jpg" alt="" /></p>
<h3>Step 3</h3>
<p>Create a new Android Application.</p>
<p><a rel="nofollow" href="http://farm3.static.flickr.com/2781/4242534287_0f08e72d41_o.png"><img src="http://farm3.static.flickr.com/2787/4243306836_33d51a7ed4.jpg" alt="" /></a></p>
<p>If you get the error below make sure you have completed step 2  successfully.</p>
<p><a rel="nofollow" href="http://farm3.static.flickr.com/2725/4243306864_1e8e8a36ba_o.png"><img src="http://farm3.static.flickr.com/2725/4243306864_f6d8b22324.jpg" alt="" /></a></p>
<p>Fill out the first New Android Project screen like below. You can  change the names of the application and packages as long as these  changes are made to the rest of the classes where appropriate.</p>
<p><a rel="nofollow" href="http://farm3.static.flickr.com/2682/4243306932_a75b6dcd1d_o.png"><img src="http://farm3.static.flickr.com/2682/4243306932_13feaca8f2.jpg" alt="" /></a></p>
<p>There is no need to create a Test Project, so  do not tick Create a  Test Project.</p>
<p><a rel="nofollow" href="http://farm5.static.flickr.com/4027/4242566793_c76e79526f_o.png"><img src="http://farm5.static.flickr.com/4027/4242566793_3531cf90ae.jpg" alt="" /></a></p>
<h3>Step 4</h3>
<p>Extract the contents of the <a rel="nofollow" href="http://www.brighthub.com/hubfolio/matthew-casperson/media/p/60447.aspx">Android  Flixel SDK</a> into your project folder. This will extract a number of  standard mp3s and images, along with the Flixel source files (under the  org.flixel and flash packages).</p>
<h3>Step 5</h3>
<p>Create a new class called MenuState in the org.myname.flixeldemo  package. It will extend the FlxState class.</p>
<p><a rel="nofollow" href="http://farm5.static.flickr.com/4027/4242566793_c76e79526f_o.png"><img src="http://farm5.static.flickr.com/4006/4242534899_730b7ea869.jpg" alt="" /></a></p>
<p>In Flixel the various states in a game (like the main menu, the game  itself, a high scrore screen etc) are represented by classes that extend  the FlxState class. As the player progressed through the game these  FlxState classes are created and destroyed to present the different  aspects of the game.</p>
<p>Add the following code to the MenuState class. Here we are going to  display a text field just so we have something on the screen.</p>
<pre>package org.myname.flixeldemo;

import org.flixel.*;

public class MenuState extends FlxState
{
 public MenuState()
 {
  super();
  add(new FlxText(10, 10, 100, "Hello World!"));
 }
}</pre>
<h3>Step 6</h3>
<p>Create a new class called GameView in the org.myname.flixeldemo  package. It will extend the FlxGameView class.</p>
<p><a rel="nofollow" href="http://farm5.static.flickr.com/4027/4242566793_c76e79526f_o.png"><img src="http://farm5.static.flickr.com/4051/4243307310_e73eab4ae5.jpg" alt="" /></a></p>
<p>Unlike a Flash game made with Flixel, where graphical objects can be  added directly to the screen, Andoid has a fairly complicated system for  allowing continuously running applications (like games) to draw to the  screen. You have to create a thread to contain the render loop and then  pass in events like key presses to the thread while maintaining thread  safety. You can view the <a rel="nofollow" href="http://developer.android.com/guide/samples/LunarLander/index.html">Lunar  Landing demo</a> for an example of how this works. Fortunately the  FlxGameView class hides all of the underlying logic required to  implement the render loop.</p>
<p>Add the following code to the GameView class. Here we pass a new  FlxGame, which is the root of every Flixel game, to the FlxGameView  constructor. The FlxGame constructor takes a few parameters like the  context (which allows Flixel to create graphics and sound resources),  the initial state class information of the game (which will be the  MenuState we created above) and the R class information (the R object is  created automatically to contain references to the graphics and sound  resources).</p>
<pre>package org.myname.flixeldemo;

import org.flixel.FlxGame;
import org.flixel.FlxGameView;

import android.content.Context;
import android.util.AttributeSet;

public class GameView extends FlxGameView
{
 public GameView(Context context, AttributeSet attrs)
 {
  super(
   new FlxGame(320, 455, MenuState.class, context, R.class),
   context,
   attrs
  );
 }
}</pre>
<h3>Step 7</h3>
<p>In order to display the GameView object we just created we need to  modify the main.xml file under the res/layout folder. Change it so it  looks like the image below. This will cause the FlixelDemo Activity,  created when the project was created, to display the GameView object.</p>
<p><a rel="nofollow" href="http://farm3.static.flickr.com/2781/4242535423_3fbe257858_o.png"><img src="http://farm3.static.flickr.com/2781/4242535423_f92bf37a60.jpg" alt="" /></a></p>
<h3>Step 8</h3>
<p>Add the line of code</p>
<pre>requestWindowFeature(Window.FEATURE_NO_TITLE);</pre>
<p>to the FlixelDemo class like the screen shot below. This will remove  the title bar from the application.</p>
<p><a rel="nofollow" href="http://farm5.static.flickr.com/4026/4243308278_049339218a_o.png"><img src="http://farm5.static.flickr.com/4026/4243308278_6114ce8e70.jpg" alt="" /></a></p>
<h3>Step 9</h3>
<p>To test the game we need to setup a Android elmulator. Click  Window-&gt;Android SDK and AVD Manager.</p>
<p><a rel="nofollow" href="http://farm5.static.flickr.com/4026/4243308278_049339218a_o.png"><img src="http://farm5.static.flickr.com/4040/4243307720_144a74e51a.jpg" alt="" /></a></p>
<p>Click the New button. Add in the details for the AVD (Android Virtual  Device) like the screenshot below. Click Create AVD.</p>
<p><a rel="nofollow" href="http://farm5.static.flickr.com/4057/4243307748_2fc77f0474.jpg"><img src="http://farm5.static.flickr.com/4057/4243307748_2fc77f0474.jpg" alt="" /></a></p>
<p>You should now have a Virtual Device listed.</p>
<p><a rel="nofollow" href="http://farm5.static.flickr.com/4038/4242535659_4392782c21_o.png"><img src="http://farm5.static.flickr.com/4038/4242535659_6e44d4d37b.jpg" alt="" /></a></p>
<h3>Step 10</h3>
<p>Now we can run the demo. Click the Run button on the toolbar.</p>
<p><a rel="nofollow" href="http://farm3.static.flickr.com/2649/4243307800_7fcec8b5a5_o.png"><img src="http://farm3.static.flickr.com/2649/4243307800_7fcec8b5a5_o.png" alt="" /></a></p>
<p>Select Android Application and click OK.</p>
<p><a rel="nofollow" href="http://farm5.static.flickr.com/4025/4242535725_cd4a36a7ac_o.png"><img src="http://farm5.static.flickr.com/4025/4242535725_5518d24772.jpg" alt="" /></a></p>
<p>The AVD will start up. This can take some time initially, so be  patient.</p>
<p><a rel="nofollow" href="http://farm3.static.flickr.com/2741/4242535767_3b0c6f6c9b_o.png"><img src="http://farm3.static.flickr.com/2741/4242535767_4da2a550af.jpg" alt="" /></a></p>
<p><a rel="nofollow" href="http://farm3.static.flickr.com/2711/4242535821_258b25a8db_o.png"><img src="http://farm3.static.flickr.com/2711/4242535821_ee58af684a.jpg" alt="" /></a></p>
<p><a rel="nofollow" href="http://farm5.static.flickr.com/4014/4242535933_a3394160d9_o.png"><img src="http://farm5.static.flickr.com/4014/4242535933_65d81a0fa3.jpg" alt="" /></a></p>
<p><a rel="nofollow" href="http://farm3.static.flickr.com/2529/4242535979_12f0d629fd_o.png"><img src="http://farm3.static.flickr.com/2529/4242535979_05fef1b96c.jpg" alt="" /></a></p>
<p><a rel="nofollow" href="http://farm3.static.flickr.com/2804/4243308170_7c85392064_o.png"><img src="http://farm3.static.flickr.com/2804/4243308170_435eecd661.jpg" alt="" /></a></p>
<p>Congratulations – you have created you first Android game.</p></div>
<img src="http://javabg.eu/?ak_action=api_record_view&id=347&type=feed" alt="" />

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://javabg.eu/2010/02/creating-a-game-on-google-android-game-with-flixel-getting-started/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Чертане на текст</title>
		<link>http://javabg.eu/2010/01/%d1%87%d0%b5%d1%80%d1%82%d0%b0%d0%bd%d0%b5-%d0%bd%d0%b0-%d1%82%d0%b5%d0%ba%d1%81%d1%82/</link>
		<comments>http://javabg.eu/2010/01/%d1%87%d0%b5%d1%80%d1%82%d0%b0%d0%bd%d0%b5-%d0%bd%d0%b0-%d1%82%d0%b5%d0%ba%d1%81%d1%82/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 09:14:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Java Game Development]]></category>
		<category><![CDATA[уроци]]></category>

		<guid isPermaLink="false">http://javabg.eu/?p=278</guid>
		<description><![CDATA[Тъй като Java аплети са изцяло в графичен характер, трябва да използвате Graphics обект, дори когато искате да съставяте текст.Трябва да използвате setFont. void setFont&#40;Font font&#41; Шрифтовете, могат да бъдат от видовете на italic , bold и други. Конструктора приема параметъра на име , стил , точка и шрифт. Font f = new Font&#40;&#34;Helvetica&#34;, Font.BOLD [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p> <img style="border:0px;" src="thumbs/jn.jpg"  /><br />
Тъй като Java аплети са изцяло в графичен характер, трябва да използвате Graphics обект, дори когато искате да съставяте<br />
текст.Трябва да използвате setFont.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size: 18; font-family:monospace;"><span style="color: #8B0000 ; font-weight: bold;">void</span> setFont<span style="color: #FFFF00;">&#40;</span><span style="color: #8B0000 ;">Font</span> font<span style="color: #FFFF00;">&#41;</span></pre></div></div>

<p>Шрифтовете, могат да бъдат от видовете на italic , bold и други.</p>
<p>Конструктора приема параметъра на име , стил , точка и шрифт.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size: 18; font-family:monospace;"><span style="color: #8B0000 ;">Font</span> f <span style="color: #F0FFFF;">=</span> <span style="color: #00FFFF  ; font-weight: bold;">new</span> <span style="color: #8B0000 ;">Font</span><span style="color: #FFFF00;">&#40;</span><span style="color: #EEE8AA;">&quot;Helvetica&quot;</span>, <span style="color: #8B0000 ;">Font</span>.<span style="color: #4B0082;">BOLD</span> <span style="color: #F0FFFF;">+</span> <span style="color: #8B0000 ;">Font</span>.<span style="color: #4B0082;">ITALIC</span>, <span style="color: #E0FFFF;">22</span><span style="color: #FFFF00;">&#41;</span><span style="color: #F0FFFF;">;</span></pre></div></div>

<p>Сега ще създадем текст.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size: 18; font-family:monospace;"><span style="color: #8B0000 ; font-weight: bold;">void</span> drawString<span style="color: #FFFF00;">&#40;</span><span style="color: #8B0000 ;">String</span> str, <span style="color: #8B0000 ; font-weight: bold;">int</span> x, <span style="color: #8B0000 ; font-weight: bold;">int</span> y<span style="color: #FFFF00;">&#41;</span></pre></div></div>

<p>drawString взима обект низ като първи параметър.Последните два параметъра , поставят позиция на чертане на текста; x определя левия край на текста , а y определя изходното ниво на текста.<br />
Сега ще начертаем обикновен applet.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size: 18; font-family:monospace;"><span style="color: #7FFF00 ; font-style: italic;">// Drawtext Class</span>
<span style="color: #7FFF00 ; font-style: italic;">// Drawtext.java</span>
&nbsp;
<span style="color: #7FFF00 ; font-style: italic;">// Вмъкване</span>
<span style="color: #00FFFF  ; font-weight: bold;">import</span> <span style="color: #7FFF00 ;">java.applet.*</span><span style="color: #F0FFFF;">;</span>
<span style="color: #00FFFF  ; font-weight: bold;">import</span> <span style="color: #7FFF00 ;">java.awt.*</span><span style="color: #F0FFFF;">;</span>
&nbsp;
<span style="color: #00FFFF  ; font-weight: bold;">public</span> <span style="color: #00FFFF  ; font-weight: bold;">class</span> Drawtext <span style="color: #00FFFF  ; font-weight: bold;">extends</span> <span style="color: #8B0000 ;">Applet</span> <span style="color: #FFFF00;">&#123;</span>
  <span style="color: #00FFFF  ; font-weight: bold;">public</span> <span style="color: #8B0000 ; font-weight: bold;">void</span> paint<span style="color: #FFFF00;">&#40;</span><span style="color: #8B0000 ;">Graphics</span> g<span style="color: #FFFF00;">&#41;</span> <span style="color: #FFFF00;">&#123;</span>
    <span style="color: #8B0000 ;">Font</span>        font <span style="color: #F0FFFF;">=</span> <span style="color: #00FFFF  ; font-weight: bold;">new</span> <span style="color: #8B0000 ;">Font</span><span style="color: #FFFF00;">&#40;</span><span style="color: #EEE8AA;">&quot;Helvetica&quot;</span>, <span style="color: #8B0000 ;">Font</span>.<span style="color: #4B0082;">BOLD</span> <span style="color: #F0FFFF;">+</span>
      <span style="color: #8B0000 ;">Font</span>.<span style="color: #4B0082;">ITALIC</span>, <span style="color: #E0FFFF;">22</span><span style="color: #FFFF00;">&#41;</span><span style="color: #F0FFFF;">;</span>
    <span style="color: #8B0000 ;">FontMetrics</span> fm <span style="color: #F0FFFF;">=</span> g.<span style="color: #4B0082;">getFontMetrics</span><span style="color: #FFFF00;">&#40;</span>font<span style="color: #FFFF00;">&#41;</span><span style="color: #F0FFFF;">;</span> 
    <span style="color: #8B0000 ;">String</span>      str <span style="color: #F0FFFF;">=</span> <span style="color: #00FFFF  ; font-weight: bold;">new</span>
      <span style="color: #8B0000 ;">String</span><span style="color: #FFFF00;">&#40;</span><span style="color: #EEE8AA;">&quot;Javabg&quot;</span><span style="color: #FFFF00;">&#41;</span><span style="color: #F0FFFF;">;</span>
&nbsp;
    g.<span style="color: #4B0082;">setFont</span><span style="color: #FFFF00;">&#40;</span>font<span style="color: #FFFF00;">&#41;</span><span style="color: #F0FFFF;">;</span>
    g.<span style="color: #4B0082;">drawString</span><span style="color: #FFFF00;">&#40;</span>str, <span style="color: #FFFF00;">&#40;</span>size<span style="color: #FFFF00;">&#40;</span><span style="color: #FFFF00;">&#41;</span>.<span style="color: #4B0082;">width</span> <span style="color: #F0FFFF;">-</span> fm.<span style="color: #4B0082;">stringWidth</span><span style="color: #FFFF00;">&#40;</span>str<span style="color: #FFFF00;">&#41;</span><span style="color: #FFFF00;">&#41;</span> <span style="color: #F0FFFF;">/</span> <span style="color: #E0FFFF;">2</span>,
      <span style="color: #FFFF00;">&#40;</span><span style="color: #FFFF00;">&#40;</span>size<span style="color: #FFFF00;">&#40;</span><span style="color: #FFFF00;">&#41;</span>.<span style="color: #4B0082;">height</span> <span style="color: #F0FFFF;">-</span> fm.<span style="color: #4B0082;">getHeight</span><span style="color: #FFFF00;">&#40;</span><span style="color: #FFFF00;">&#41;</span><span style="color: #FFFF00;">&#41;</span> <span style="color: #F0FFFF;">/</span> <span style="color: #E0FFFF;">2</span><span style="color: #FFFF00;">&#41;</span> <span style="color: #F0FFFF;">+</span> fm.<span style="color: #4B0082;">getAscent</span><span style="color: #FFFF00;">&#40;</span><span style="color: #FFFF00;">&#41;</span><span style="color: #FFFF00;">&#41;</span><span style="color: #F0FFFF;">;</span>
  <span style="color: #FFFF00;">&#125;</span>
<span style="color: #FFFF00;">&#125;</span></pre></div></div>

<img src="http://javabg.eu/?ak_action=api_record_view&id=278&type=feed" alt="" />

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://javabg.eu/2010/01/%d1%87%d0%b5%d1%80%d1%82%d0%b0%d0%bd%d0%b5-%d0%bd%d0%b0-%d1%82%d0%b5%d0%ba%d1%81%d1%82/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jDrawing Графика с примитиви</title>
		<link>http://javabg.eu/2010/01/jdrawing-%d0%b3%d1%80%d0%b0%d1%84%d0%b8%d0%ba%d0%b0-%d1%81-%d0%bf%d1%80%d0%b8%d0%bc%d0%b8%d1%82%d0%b8%d0%b2%d0%b8/</link>
		<comments>http://javabg.eu/2010/01/jdrawing-%d0%b3%d1%80%d0%b0%d1%84%d0%b8%d0%ba%d0%b0-%d1%81-%d0%bf%d1%80%d0%b8%d0%bc%d0%b8%d1%82%d0%b8%d0%b2%d0%b8/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 09:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Java Game Development]]></category>
		<category><![CDATA[уроци]]></category>

		<guid isPermaLink="false">http://javabg.eu/?p=276</guid>
		<description><![CDATA[Графика с примитиви се състои от линии, правоъгълници, кръгове, полигони, овал, и дъги. Можете да създадете доста впечатляваща графика с помощта на тези примитиви във връзка един с друг; класът Graphics предвижда методи за съставяне на тези примитиви. Затворени региони са графични елементи с ясни отличения. За пример, кръгове и правоъгълници са затворени региони, като [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p> <img style="border:0px;" src="thumbs/jn.jpg"  /></p>
<p>Графика с примитиви се състои от линии, правоъгълници, кръгове, полигони, овал, и дъги. Можете да създадете доста впечатляваща графика с помощта на тези примитиви във връзка един с друг; класът Graphics предвижда методи за съставяне на тези примитиви. </p>
<p>Затворени региони са графични елементи с ясни отличения. За пример, кръгове и правоъгълници са затворени региони, като има предвид, линиите и точките.</p>
<p><strong>Линии</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size: 18; font-family:monospace;"><span style="color: #8B0000 ; font-weight: bold;">void</span> drawLine<span style="color: #FFFF00;">&#40;</span><span style="color: #8B0000 ; font-weight: bold;">int</span> x1, <span style="color: #8B0000 ; font-weight: bold;">int</span> y1, <span style="color: #8B0000 ; font-weight: bold;">int</span> x2, <span style="color: #8B0000 ; font-weight: bold;">int</span> y2<span style="color: #FFFF00;">&#41;</span></pre></div></div>

<p>Първите два параметъра са, x1 и y1, които са главните точки на линията,  x2 и y2 са за крайните точки на линията .<br />
Следващ:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size: 18; font-family:monospace;"><span style="color: #00FFFF  ; font-weight: bold;">public</span> <span style="color: #8B0000 ; font-weight: bold;">void</span> paint<span style="color: #FFFF00;">&#40;</span><span style="color: #8B0000 ;">Graphics</span> g<span style="color: #FFFF00;">&#41;</span> <span style="color: #FFFF00;">&#123;</span>
  g.<span style="color: #4B0082;">drawLine</span><span style="color: #FFFF00;">&#40;</span><span style="color: #E0FFFF;">5</span>, <span style="color: #E0FFFF;">10</span>, <span style="color: #E0FFFF;">15</span>, <span style="color: #E0FFFF;">55</span><span style="color: #FFFF00;">&#41;</span><span style="color: #F0FFFF;">;</span>
<span style="color: #FFFF00;">&#125;</span></pre></div></div>

<p>Рисуване с drawLine метод.<br />
<strong>Правоъгълници</strong></p>
<p>Правоъгълници също са много лесни за рисуване.drawRect метод позволява да се изготвят правоъгълници, като се посочва в горния ляв ъгъл ширината и височината на правоъгълника.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size: 18; font-family:monospace;"><span style="color: #8B0000 ; font-weight: bold;">void</span> drawRect<span style="color: #FFFF00;">&#40;</span><span style="color: #8B0000 ; font-weight: bold;">int</span> x, <span style="color: #8B0000 ; font-weight: bold;">int</span> y, <span style="color: #8B0000 ; font-weight: bold;">int</span> width, <span style="color: #8B0000 ; font-weight: bold;">int</span> height<span style="color: #FFFF00;">&#41;</span></pre></div></div>

<p>Параметрите x и y определят височината и ширината на правоъгълника от горния ляв ъгъл. За да начертаете правоъгълник просто извикайте функцията drawRect от paint метода:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size: 18; font-family:monospace;"><span style="color: #00FFFF  ; font-weight: bold;">public</span> <span style="color: #8B0000 ; font-weight: bold;">void</span> paint<span style="color: #FFFF00;">&#40;</span><span style="color: #8B0000 ;">Graphics</span> g<span style="color: #FFFF00;">&#41;</span> <span style="color: #FFFF00;">&#123;</span>
  g.<span style="color: #4B0082;">drawRect</span><span style="color: #FFFF00;">&#40;</span><span style="color: #E0FFFF;">5</span>, <span style="color: #E0FFFF;">10</span>, <span style="color: #E0FFFF;">15</span>, <span style="color: #E0FFFF;">55</span><span style="color: #FFFF00;">&#41;</span><span style="color: #F0FFFF;">;</span>
<span style="color: #FFFF00;">&#125;</span></pre></div></div>

<p>Other Primitives</p>
<p>Другите фигури също се чертаят, по подобен начин , като с правоъгълника и квадрата . Единствената разлика е, че при кръговете и овалите се ползва радиус за чертане.</p>
<img src="http://javabg.eu/?ak_action=api_record_view&id=276&type=feed" alt="" />

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://javabg.eu/2010/01/jdrawing-%d0%b3%d1%80%d0%b0%d1%84%d0%b8%d0%ba%d0%b0-%d1%81-%d0%bf%d1%80%d0%b8%d0%bc%d0%b8%d1%82%d0%b8%d0%b2%d0%b8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Движение на топче 2D</title>
		<link>http://javabg.eu/2010/01/%d0%b4%d0%b2%d0%b8%d0%b6%d0%b5%d0%bd%d0%b8%d0%b5-%d0%bd%d0%b0-%d1%82%d0%be%d0%bf%d1%87%d0%b5-2d/</link>
		<comments>http://javabg.eu/2010/01/%d0%b4%d0%b2%d0%b8%d0%b6%d0%b5%d0%bd%d0%b8%d0%b5-%d0%bd%d0%b0-%d1%82%d0%be%d0%bf%d1%87%d0%b5-2d/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 09:34:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[applet]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java Game Development]]></category>
		<category><![CDATA[JSE]]></category>

		<guid isPermaLink="false">http://javabg.eu/?p=217</guid>
		<description><![CDATA[Демо С този урок, ще започнем с програмирането на игри в 2D сферата. Ще програмираме applet, в който топката, ще се движи от ляво на дясно.Не е кой знае колко трудно, но за начало с това ще започнем. В нашия applet трябва да създадем метода за стартиране и метода за свързване с него run() за [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p><strong></p>
<blockquote><p>Демо</p></blockquote>
<p></strong></p>
<blockquote><p><applet code="Ballbewegung1.class" codebase="http://javabg.eu/democ/" width="300" height="300"> </p></blockquote>
<p><img style="border:0px;" src="thumbs/jn.jpg"  /><br />
С този урок, ще започнем с програмирането на игри в 2D сферата.<br />
 Ще програмираме applet, в който топката, ще се движи от ляво на дясно.Не е кой знае колко трудно, но за начало с това ще започнем.<br />
В нашия applet трябва да създадем метода за стартиране и метода за свързване с него run() за да анимираме обект.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size: 18; font-family:monospace;"><span style="color: #00FFFF  ; font-weight: bold;">import</span> <span style="color: #7FFF00 ;">java.applet.*</span><span style="color: #F0FFFF;">;</span> 
<span style="color: #00FFFF  ; font-weight: bold;">import</span> <span style="color: #7FFF00 ;">java.awt.*</span><span style="color: #F0FFFF;">;</span> 
&nbsp;
<span style="color: #00FFFF  ; font-weight: bold;">public</span> <span style="color: #00FFFF  ; font-weight: bold;">class</span> BallApplet <span style="color: #00FFFF  ; font-weight: bold;">extends</span> <span style="color: #8B0000 ;">Applet</span> <span style="color: #00FFFF  ; font-weight: bold;">implements</span> <span style="color: #8B0000 ;">Runnable</span> 
<span style="color: #FFFF00;">&#123;</span> 
<span style="color: #00FFFF  ; font-weight: bold;">public</span> <span style="color: #8B0000 ; font-weight: bold;">void</span> init<span style="color: #FFFF00;">&#40;</span><span style="color: #FFFF00;">&#41;</span> <span style="color: #FFFF00;">&#123;</span> <span style="color: #FFFF00;">&#125;</span> 
&nbsp;
<span style="color: #00FFFF  ; font-weight: bold;">public</span> <span style="color: #8B0000 ; font-weight: bold;">void</span> start<span style="color: #FFFF00;">&#40;</span><span style="color: #FFFF00;">&#41;</span> <span style="color: #FFFF00;">&#123;</span> <span style="color: #FFFF00;">&#125;</span> 
&nbsp;
<span style="color: #00FFFF  ; font-weight: bold;">public</span> <span style="color: #8B0000 ; font-weight: bold;">void</span> stop<span style="color: #FFFF00;">&#40;</span><span style="color: #FFFF00;">&#41;</span> <span style="color: #FFFF00;">&#123;</span> <span style="color: #FFFF00;">&#125;</span> 
&nbsp;
<span style="color: #00FFFF  ; font-weight: bold;">public</span> <span style="color: #8B0000 ; font-weight: bold;">void</span> destroy<span style="color: #FFFF00;">&#40;</span><span style="color: #FFFF00;">&#41;</span> <span style="color: #FFFF00;">&#123;</span> <span style="color: #FFFF00;">&#125;</span> 
&nbsp;
<span style="color: #00FFFF  ; font-weight: bold;">public</span> <span style="color: #8B0000 ; font-weight: bold;">void</span> run <span style="color: #FFFF00;">&#40;</span><span style="color: #FFFF00;">&#41;</span> <span style="color: #FFFF00;">&#123;</span> <span style="color: #FFFF00;">&#125;</span> 
&nbsp;
<span style="color: #00FFFF  ; font-weight: bold;">public</span> <span style="color: #8B0000 ; font-weight: bold;">void</span> paint <span style="color: #FFFF00;">&#40;</span><span style="color: #8B0000 ;">Graphics</span> g<span style="color: #FFFF00;">&#41;</span> <span style="color: #FFFF00;">&#123;</span> <span style="color: #FFFF00;">&#125;</span> 
&nbsp;
<span style="color: #FFFF00;">&#125;</span></pre></div></div>

<p>За да местим обект, трябва да създадем, още един обект:Ще използваме Thread . </p>
<p> класовете Thread са:<br />
Thread.start(): стартира thread<br />
Thread.stop(): спира thread<br />
Thread.sleep(време в милисекунди): </p>
<p>Ето го и кода!</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size: 18; font-family:monospace;"><span style="color: #00FFFF  ; font-weight: bold;">public</span> <span style="color: #8B0000 ; font-weight: bold;">void</span> start <span style="color: #FFFF00;">&#40;</span><span style="color: #FFFF00;">&#41;</span> 
<span style="color: #FFFF00;">&#123;</span> 
<span style="color: #7FFF00 ; font-style: italic;">// дефинира нов thread </span>
<span style="color: #8B0000 ;">Thread</span> th <span style="color: #F0FFFF;">=</span> <span style="color: #00FFFF  ; font-weight: bold;">new</span> <span style="color: #8B0000 ;">Thread</span> <span style="color: #FFFF00;">&#40;</span><span style="color: #00FFFF  ; font-weight: bold;">this</span><span style="color: #FFFF00;">&#41;</span><span style="color: #F0FFFF;">;</span> 
<span style="color: #7FFF00 ; font-style: italic;">// стартира го thread </span>
th.<span style="color: #4B0082;">start</span> <span style="color: #FFFF00;">&#40;</span><span style="color: #FFFF00;">&#41;</span><span style="color: #F0FFFF;">;</span> 
<span style="color: #FFFF00;">&#125;</span></pre></div></div>

<p>Сега thread е стартиран в run() метода на нашия applet.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-size: 18; font-family:monospace;"><span style="color: #00FFFF  ; font-weight: bold;">public</span> <span style="color: #8B0000 ; font-weight: bold;">void</span> run <span style="color: #FFFF00;">&#40;</span><span style="color: #FFFF00;">&#41;</span> 
<span style="color: #FFFF00;">&#123;</span> 
<span style="color: #7FFF00 ; font-style: italic;">// бавно ThreadPriority </span>
<span style="color: #8B0000 ;">Thread</span>.<span style="color: #4B0082;">currentThread</span><span style="color: #FFFF00;">&#40;</span><span style="color: #FFFF00;">&#41;</span>.<span style="color: #4B0082;">setPriority</span><span style="color: #FFFF00;">&#40;</span><span style="color: #8B0000 ;">Thread</span>.<span style="color: #4B0082;">MIN_PRIORITY</span><span style="color: #FFFF00;">&#41;</span><span style="color: #F0FFFF;">;</span> 
&nbsp;
<span style="color: #7FFF00 ; font-style: italic;">// стартира дълъг while (true) това значи &quot;винаги&quot;.</span>
<span style="color: #00FFFF  ; font-weight: bold;">while</span> <span style="color: #FFFF00;">&#40;</span><span style="color: #00FFFF; font-weight: bold;">true</span><span style="color: #FFFF00;">&#41;</span> 
<span style="color: #FFFF00;">&#123;</span> 
<span style="color: #7FFF00 ; font-style: italic;">// променя applet</span>
repaint<span style="color: #FFFF00;">&#40;</span><span style="color: #FFFF00;">&#41;</span><span style="color: #F0FFFF;">;</span> 
&nbsp;
<span style="color: #00FFFF  ; font-weight: bold;">try</span> 
<span style="color: #FFFF00;">&#123;</span> 
<span style="color: #7FFF00 ; font-style: italic;">// Спира thread за 20 милисекунди </span>
<span style="color: #8B0000 ;">Thread</span>.<span style="color: #4B0082;">sleep</span> <span style="color: #FFFF00;">&#40;</span><span style="color: #E0FFFF;">20</span><span style="color: #FFFF00;">&#41;</span><span style="color: #F0FFFF;">;</span> 
<span style="color: #FFFF00;">&#125;</span> 
<span style="color: #00FFFF  ; font-weight: bold;">catch</span> <span style="color: #FFFF00;">&#40;</span><span style="color: #8B0000 ;">InterruptedException</span> ex<span style="color: #FFFF00;">&#41;</span> 
<span style="color: #FFFF00;">&#123;</span> 
<span style="color: #7FFF00 ; font-style: italic;">// Неправи нищо </span>
<span style="color: #FFFF00;">&#125;</span> 
&nbsp;
<span style="color: #7FFF00 ; font-style: italic;">// Задава ThreadPriority с максимална стойност </span>
<span style="color: #8B0000 ;">Thread</span>.<span style="color: #4B0082;">currentThread</span><span style="color: #FFFF00;">&#40;</span><span style="color: #FFFF00;">&#41;</span>.<span style="color: #4B0082;">setPriority</span><span style="color: #FFFF00;">&#40;</span><span style="color: #8B0000 ;">Thread</span>.<span style="color: #4B0082;">MAX_PRIORITY</span><span style="color: #FFFF00;">&#41;</span><span style="color: #F0FFFF;">;</span> 
<span style="color: #FFFF00;">&#125;</span> 
<span style="color: #FFFF00;">&#125;</span> 
&nbsp;
Нека да нарисуваме кръг.
<span style="color: #F0FFFF;">&lt;</span>pre lang<span style="color: #F0FFFF;">=</span><span style="color: #EEE8AA;">&quot;java&quot;</span><span style="color: #F0FFFF;">&gt;</span>
<span style="color: #00FFFF  ; font-weight: bold;">public</span> <span style="color: #8B0000 ; font-weight: bold;">void</span> paint <span style="color: #FFFF00;">&#40;</span><span style="color: #8B0000 ;">Graphics</span> g<span style="color: #FFFF00;">&#41;</span> 
<span style="color: #FFFF00;">&#123;</span> 
<span style="color: #7FFF00 ; font-style: italic;">// Задаваме цвят</span>
g.<span style="color: #4B0082;">setColor</span> <span style="color: #FFFF00;">&#40;</span><span style="color: #8B0000 ;">Color</span>.<span style="color: #4B0082;">red</span><span style="color: #FFFF00;">&#41;</span><span style="color: #F0FFFF;">;</span> 
&nbsp;
<span style="color: #7FFF00 ; font-style: italic;">// Създаваме кръг</span>
g.<span style="color: #4B0082;">fillOval</span> <span style="color: #FFFF00;">&#40;</span>x_pos <span style="color: #F0FFFF;">-</span> radius, y_pos <span style="color: #F0FFFF;">-</span> radius, <span style="color: #E0FFFF;">2</span> <span style="color: #F0FFFF;">*</span> radius, <span style="color: #E0FFFF;">2</span> <span style="color: #F0FFFF;">*</span> radius<span style="color: #FFFF00;">&#41;</span><span style="color: #F0FFFF;">;</span> 
<span style="color: #FFFF00;">&#125;</span> 
&nbsp;
<span style="color: #7FFF00 ; font-style: italic;">//Задаваме стойност на променливите </span>
&nbsp;
<span style="color: #8B0000 ; font-weight: bold;">int</span> x_pos <span style="color: #F0FFFF;">=</span> <span style="color: #E0FFFF;">10</span><span style="color: #F0FFFF;">;</span> <span style="color: #7FFF00 ; font-style: italic;">//Стартираща позиция</span>
<span style="color: #8B0000 ; font-weight: bold;">int</span> y_pos <span style="color: #F0FFFF;">=</span> <span style="color: #E0FFFF;">100</span><span style="color: #F0FFFF;">;</span> <span style="color: #7FFF00 ; font-style: italic;">//Крайна позиция</span>
<span style="color: #8B0000 ; font-weight: bold;">int</span> radius <span style="color: #F0FFFF;">=</span> <span style="color: #E0FFFF;">20</span><span style="color: #F0FFFF;">;</span> <span style="color: #7FFF00 ; font-style: italic;">//Радиус на кръга</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-size: 18; font-family:monospace;"><span style="color: #00FFFF  ; font-weight: bold;">public</span> <span style="color: #8B0000 ; font-weight: bold;">void</span> run <span style="color: #FFFF00;">&#40;</span><span style="color: #FFFF00;">&#41;</span> 
<span style="color: #FFFF00;">&#123;</span> 
... 
<span style="color: #00FFFF  ; font-weight: bold;">while</span> <span style="color: #FFFF00;">&#40;</span><span style="color: #00FFFF; font-weight: bold;">true</span><span style="color: #FFFF00;">&#41;</span> 
<span style="color: #FFFF00;">&#123;</span> 
<span style="color: #7FFF00 ; font-style: italic;">// Променя x позицията на кръга</span>
x_pos <span style="color: #F0FFFF;">++;</span> 
... 
<span style="color: #FFFF00;">&#125;</span> 
<span style="color: #FFFF00;">&#125;</span></pre></div></div>

<img src="http://javabg.eu/?ak_action=api_record_view&id=217&type=feed" alt="" />

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://javabg.eu/2010/01/%d0%b4%d0%b2%d0%b8%d0%b6%d0%b5%d0%bd%d0%b8%d0%b5-%d0%bd%d0%b0-%d1%82%d0%be%d0%bf%d1%87%d0%b5-2d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

