on 10-05-2012 04:46 AM
I'm so close I can feel it.
I just need to get this square bouncing on the screen without having to make another class:
using System;
using System.Collections.Generic;
using Sce.Pss.Core;
using Sce.Pss.Core.Environment;
using Sce.Pss.Core.Graphics;
using Sce.Pss.Core.Imaging;
using Sce.Pss.Core.Input;
using Sce.Pss.HighLevel.GameEngine2D;
using Sce.Pss.HighLevel.GameEngine2D.Base;
using System.Threading;
using System.Diagnostics;
namespace ss
{
public class AppMain
{
static GraphicsContext graphics;
static Texture2D rect;
float positionX;
float positionY;
static void Main (string[] args)
{
Director.Initialize();
Random rand = new System.Random();
int dirX = rand.Next(2) > 0 ? 1 : -1;;
int dirY = rand.Next(2) > 0 ? 1 : 1;
float addPosition;
var width = Director.Instance.GL.Context.GetViewport().Width;
var height = Director.Instance.GL.Context.GetViewport().Height;
var scene=new Scene();
scene.Camera.SetViewFromViewport();
var ti=new TextureInfo(
new Texture2D("/Application/rect.png", false));
var sprite=new SpriteUV() {TextureInfo=ti};
rect = new Texture2D("Application/rect.png", false);
sprite.Quad.S=ti.TextureSizef;
sprite.CenterSprite();
sprite.Position=scene.Camera.CalcBounds().Center;
var positionX=rand.Next (0, width);
var positionY=rand.Next (0, height);
dirX=rand.Next(2) > 0 ? 1 : -1;
dirY=rand.Next (2) > 0 ? 1 : 1;
addPosition = 0 + (float)rand.NextDouble() * 5.0f;
scene.AddChild(sprite);
Director.Instance.RunWithScene(scene, true);
bool gameOver = false;
while(!gameOver)
{
Sce.Pss.HighLevel.GameEngine2D.Director.Instance.U
if(Input2.GamePad0.Circle.Press == true)
gameOver = true;
Sce.Pss.HighLevel.GameEngine2D.Director.Instance.R
Sce.Pss.HighLevel.GameEngine2D.Director.Instance.G
Sce.Pss.HighLevel.GameEngine2D.Director.Instance.P
}
Director.Terminate();
}
}}
14-05-2012 11:53 AM - edited 14-05-2012 11:55 AM
Hi favi85,
To control the ball bouncing around the screen, you will need to implement some code which will check and move the ball in your update loop, which will be run each frame. On each frame, you want to put the ball along the X and Y axis a litle further, and when the ball reaches the edge of the screen then you want to reverse the horizontal or vertical direction.
I've dropped the changes into your code and highlighted them (bold & italic). I've not fully tested it with your code, but the logic should be all there ![]()
using System;
using System.Collections.Generic;
using Sce.Pss.Core;
using Sce.Pss.Core.Environment;
using Sce.Pss.Core.Graphics;
using Sce.Pss.Core.Imaging;
using Sce.Pss.Core.Input;
using Sce.Pss.HighLevel.GameEngine2D;
using Sce.Pss.HighLevel.GameEngine2D.Base;
using System.Threading;
using System.Diagnostics;
namespace ss
{
public class AppMain
{
static GraphicsContext graphics;
static Texture2D rect;
float positionX;
float positionY;
// Adjust these to be the speed that you wish
static float directionX = 2f;
static float directionY = 2f;
static void Main (string[] args)
{
Director.Initialize();
Random rand = new System.Random();
int dirX = rand.Next(2) > 0 ? 1 : -1;;
int dirY = rand.Next(2) > 0 ? 1 : 1;
float addPosition;
var width = Director.Instance.GL.Context.GetViewport().Width;
var height = Director.Instance.GL.Context.GetViewport().Height;
var scene=new Scene();
scene.Camera.SetViewFromViewport();
var ti=new TextureInfo(
new Texture2D("/Application/rect.png", false));
var sprite=new SpriteUV() {TextureInfo=ti};
rect = new Texture2D("Application/rect.png", false);
sprite.Quad.S=ti.TextureSizef;
sprite.CenterSprite();
sprite.Position=scene.Camera.CalcBounds().Center;
var positionX=rand.Next (0, width);
var positionY=rand.Next (0, height);
dirX=rand.Next(2) > 0 ? 1 : -1;
dirY=rand.Next (2) > 0 ? 1 : 1;
addPosition = 0 + (float)rand.NextDouble() * 5.0f;
scene.AddChild(sprite);
Director.Instance.RunWithScene(scene, true);
bool gameOver = false;
while(!gameOver)
{
Sce.Pss.HighLevel.GameEngine2D.Director.Instance.U pdate();
if(Input2.GamePad0.Circle.Press == true)
gameOver = true;
tile.Position = new Vector2(tile.Position.X + directionX, tile.Position.Y + directionY);
// You may have to adjust the tile.Scale.* calculations if you stop calling CenterSprite()
// Going off the left of the screen.
if((sprite.Position.X - (sprite.Scale.X / 2)) < 0)
directionX *= -1;
// Going off the right of the screen
if((sprite.Position.X + (sprite.Scale.X / 2)) > Director.Instance.GL.Context.Screen.Width)
directionX *= -1;
// Going off the top of the screen
if((sprite.Position.Y + (sprite.Scale.Y / 2)) > Director.Instance.GL.Context.Screen.Height)
directionY *= -1;
// Going off the bottom of the screen
if((sprite.Position.Y - (sprite.Scale.Y / 2)) < 0)
directionY *= -1;
if(Input2.GamePad0.Circle.Press == true)
gameOver = true;
Sce.Pss.HighLevel.GameEngine2D.Director.Instance.R ender();
Sce.Pss.HighLevel.GameEngine2D.Director.Instance.G L.Context.SwapBuffers();
Sce.Pss.HighLevel.GameEngine2D.Director.Instance.P ostSwap();
}
Director.Terminate();
}
}}
Hope this helps
on 14-05-2012 05:05 PM
very cool!
PSM Developer Registration (for free) on PSM DevPortal is required to post on the forum.
Please sign out then sign in again to the forum and PSM DevPortal after you have completed the registration.
フォーラムへ投稿をするにはPSM DevPortalへの登録(無料)が必要です。
登録後はフォーラムと
PSM DevPortalを一度ログアウトし、再度ログインしてください。


Website ©2013 Sony Computer Entertainment Europe
All content, game titles, trade names and/or trade dress, trademarks, artwork and associated imagery are trademarks and/or copyright material of their respective owners. All rights reserved. [more info]
%%http://community.eu.playstation.com/t5/Announcements/Beta-Trial-Information/td-p/11386362
best_shooter.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_driver.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_performer.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_footballer.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_fighter.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_creator.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_action_player.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
dev2.png%%http://community.eu.playstation.com/t5/Website-and-Forum-Help-Feedback/Producer-and-Developer-Ranks/td-p/18407352
trophy.gif%%http://community.eu.playstation.com/t5/Website-and-Forum-Help-Feedback/The-Community-Awards-FAQ/td-p/18407096
PSlogoSM.png%%http://community.eu.playstation.com/t5/Website-and-Forum-Help-Feedback/Online-Support-Coordinator-rank/td-p/18414870