Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Need Help for SetSpritePositionByOffset

Author
Message
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 12th Jul 2016 13:39
Hi.

in my code when I wrote SetSpritePositionByOffset() above of the below code, my character can't move.



but when I wrote SetSpritePositionByOffset() down of the below code, my character can move.



anyone know why do this happen?

Thanks.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 12th Jul 2016 13:45
I'm guessing this is in a function and Byvelocity# or BySpeed# or both are local variables, reset to 0 each time.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 12th Jul 2016 13:50 Edited at: 12th Jul 2016 14:10
Quote: "I'm guessing this is in a function and Byvelocity# or BySpeed# or both are local variables, reset to 0 each time."


Thanks for reply.

Byvelocity# and BySpeed# are global variables. and at the first they values are :

global Byspeed# = 0.0
global Byvelocity# = 83.5

I define these variables outside of do -- loop. but for test I set values to 0 in do--loop for each time.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 12th Jul 2016 18:43
any idea?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 12th Jul 2016 18:50
i am confused why u don't add this to the x,y value in your struct,
you are using Boss.x but not Boss.y, looks odd.
SetSpritePositionByOffset(Boss.spr,Boss.x,Byvelocity#) //Move Boss
AGK (Steam) V2.0.19 : Windows 10 Pro 64 Bit : AMD (16.3.2) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 12th Jul 2016 18:59 Edited at: 12th Jul 2016 19:01
already I find this code for move sprite without physics.

this complete code is here:



do you have better idea?

I define all variables as global but seem working as local.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 12th Jul 2016 19:58 Edited at: 12th Jul 2016 20:36
mycharacter position is correct before comment below code, but it can't move.



like this picture :



but when I comment above code character poistion is not correct, but it can move.

like this picture :



above code work very well for Player and Enemy but won't work for Buss.but I don't know what happened.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 12th Jul 2016 21:00
try at top #option_explicit
cheack values with print(Byvelocity#) or put them in debugger.
you can also use print("i am here") and print("now here") in your if then condition.

AGK (Steam) V2.0.19 : Windows 10 Pro 64 Bit : AMD (16.3.2) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 12th Jul 2016 21:08
Quote: "try at top #option_explicit"


what is this command?

Quote: "cheack values with print(Byvelocity#) or put them in debugger.
you can also use print("i am here") and print("now here") in your if then condition."


already I print all variable and check them.Byvelocity# work correctly but Boss.x won't change when I try to Print it. I tried everything I could think of.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 12th Jul 2016 21:21 Edited at: 12th Jul 2016 21:27
is your Boss.x as float in type?
now saw where you change it.
#option_explicit prevent unwanted auto var declaration at any place

your code show only
Boss.x = GetSpriteXByOffset(
SetSpritePositionByOffset(,Boss.x,)
that is for me 1=1
AGK (Steam) V2.0.19 : Windows 10 Pro 64 Bit : AMD (16.3.2) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 12th Jul 2016 21:30 Edited at: 12th Jul 2016 21:46
Quote: "is your Boss.x as float in type?"


yes it is float in type.

I think Problem is relate to below code and you right that 1=1 :



Thanks Markus.

if there is any Problem I ask here.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 12th Jul 2016 22:03 Edited at: 12th Jul 2016 22:08
use above post code, work correctly for Player and Enemy but when I remove this line GetSpriteXByOffset(Boss.spr), Boss character can be move to direction but make change Boss.x position to 0. while i set Boss.x Position to 80 in CreateBoss() Command.

CreateBoss() :



Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 12th Jul 2016 22:05 Edited at: 12th Jul 2016 22:26
I fix it with with wrote below line code above to Fit Boss Y Position.



I'd be happy if there is not a new problem.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 12th Jul 2016 22:47 Edited at: 12th Jul 2016 22:50
its maybe better if u remove this x,y in boss type because u have this position in the sprite.
or make and use a
function setbossxy(ref boss as tboss)
SetSpritePositionByOffset(boss.spr,boss.x,boss.y)

function getbossxy(ref boss as tboss)
boss.x=...
boss.y=...

AGK (Steam) V2.0.20 : Windows 10 Pro 64 Bit : AMD (16.3.2) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 13th Jul 2016 06:23
Thanks Markus for your help.

if there is any problem I ask here.

Login to post a reply

Server time is: 2024-11-25 05:23:32
Your offset time is: 2024-11-25 05:23:32