Hello everyone ,
It's been a while, anyway I decided I go another round with the sprite engine and asphyre , and finally I did my breakthrough , smooth scrolling is working now, I was scrolling the world in a way in which it was not meant to be scrolled.
Once I'm done with my latest findings, I will collect my documents and do a more detailed step-by-step guide thing.
Anyway the problem I am facing now is this :
OnFormCreate after I initialize the Apshyre Device , I create the Player Ship, then I create a test enemy , that is only moving left and right ... like this
Code:
Enemy := TEnemy.Create(SpriteEngine);
with TEnemy(Enemy) do
begin
ImageName := 'Enemy.image';
Z := 40;
X := 100;
y := 4350;
horz := 1;
CollideMethod := cmRadius;
CollideRadius := 5;
DoCollision := true;
end;
** the Enemy size is 32x64 , I guess the collide radius means that it checks Enemy.X,Enemy.Y +5 radius (circle) for collision...
Now using PlayerSprite.Move I move the ship , I can shoot (create Bullet sprites) like this :
Code:
procedure TPlayerSprite.Move(const MoveCount: Single);
var Bullet : TBullet;
begin
// here we move the ship and the world with world.y
inherited;
if Engine.WorldY > 0 then
Y := Y - 0.5; // we are moving constantly ahead till we reach the end
if Form1.Keyboard.Key[203] then
begin
if X > 0 then
X := X - 3
else
X := 0; // we put the ship to the edge of the screen
end;
if Form1.Keyboard.Key[205] then
begin
if X < 608 then
X := X + 3
else
X := 608; // we put the ship to the edge of the screen
end;
if fireRate > 1 then dec(fireRate);
if ((Form1.Keyboard.Key[29]) or (Form1.Keyboard.Key[57])) and (firerate=1) then
begin
Bullet := TBullet.Create(Form1.SpriteEngine);
Bullet.CollideMethod := cmRadius;
Bullet.CollideRadius := 5;
Bullet.DoCollision:=true;
Bullet.MoveSpeed := 7;
Bullet.DoCenter := False;
Bullet.X := PlayerSprite.X;
Bullet.Y := PlayerSprite.Y + 10;
Bullet.Z := PlayerSprite.Z;
Bullet.ImageName := 'Bullet.image';
firerate:=20;
end;
Engine.WorldY := Y - (480-64);
end;
And then I move the Bullet and the Enemy sprite and check for collision like this :
Code:
procedure TEnemy.Move( const MoveCount: Single);
begin
inherited;
y:=Engine.WorldY+64;
x:=x+horz;
if x > 640 then horz:=horz*-1;
if x < 0 then horz:=horz*-1;
end;
procedure TBullet.Move(const MoveCount: Single);
begin
inherited;
Y := Y - FMoveSpeed;
if Y < WorldY then
begin
Dead;
Visible := False;
end;
Collision;
end;
procedure TBullet.OnCollision(const Sprite: TSprite);
begin
if (Sprite is TEnemy) then
begin
Dead;
end;
end;
The problem is the newly created Bullet sprites are instantly colliding with the TEnemy sprite , and thus as long as the TBullet.OnCollision is
not commented out, Bullet's aren't visible...
They are not colliding properly , what am I doing wrong here ? Any ideas? I was banging my head against the wall all day long, trying to check samples
but unfortunately they use another newer Sprite Engine...
Please Help.
Greetings
Robert
Bookmarks